turf intersect: Each LinearRing of a Polygon must have 4 or more Positions
See original GitHub issuePlease provide the following when reporting an issue:
- GeoJSON data as a gist file or geojson.io (filename extension must be
.geojson
). - Snippet of source code or for complex examples use jsfiddle.
Hello,
I have an error with turf/intersect. Is that something I am doing wrong or a bug?
Thank you
const intersect = require("@turf/intersect").default;
const geoJson1 = {
type: "Feature",
properties: {
code: "65242"
},
geometry: {
type: "Polygon",
coordinates: [
[
[0.141179, 43.36818], [0.148728, 43.367642], [0.153978, 43.367941], [0.15406, 43.368879], [0.163409, 43.371427], [0.162531, 43.370615], [0.165807, 43.367931], [0.166334, 43.362561], [0.168195, 43.361501], [0.168578, 43.357791], [0.170263, 43.356262], [0.173148, 43.3492], [0.165161, 43.34775], [0.157626, 43.342611], [0.152694, 43.342085], [0.149333, 43.342992], [0.145901, 43.341962], [0.140744, 43.342316], [0.140504, 43.344645], [0.134485, 43.344652], [0.13974, 43.358065], [0.142917, 43.357494], [0.14257, 43.359911], [0.140389, 43.363775], [0.141179, 43.36818]
]
]
}
};
const geoJson2 = {
type: "Feature",
properties: {},
geometry: {
type: "MultiPolygon",
coordinates: [
[
[
[-0.003511817426206, 43.4699897941247], [-0.003510675548367, 43.379992017286], [0.086492457141402, 43.3799922060496], [0.086492395200926, 43.2899938575523], [0.266499564242721, 43.2899958347523], [0.266498422976084, 43.3799936438263], [0.176495463022904, 43.3799924051132], [0.176494466412028, 43.4699904648683], [-0.003511817426206, 43.4699897941247]
],
[
[0.221496676867966, 43.3259988784034], [0.221497305021322, 43.3439979092252], [0.248497229697336, 43.3439977847358], [0.248498037469127, 43.3259979174387], [0.221496676867966, 43.3259988784034]
],
[
[0.149494714775711, 43.3169980868321], [0.149495737551508, 43.3259972246487], [0.140494074719633, 43.3259972052475], [0.140494667441234, 43.3439967446387], [0.131494370741759, 43.3439970882588], [0.131493979866131, 43.3529964603265], [0.122493641497581, 43.3529971097641], [0.122494266127063, 43.370996144705], [0.158495319359878, 43.3709970371161], [0.158494333168507, 43.3619965574681], [0.194496359336044, 43.361996882516], [0.194496951739768, 43.3169982443264], [0.149494714775711, 43.3169980868321]
]
]
]
}
};
intersect(geoJson1, geoJson2);
Throws an error:
Error: Each LinearRing of a Polygon must have 4 or more Positions.
at Object.polygon (/test-turf/node_modules/@turf/helpers/index.js:213:19)
at intersect (/test-turf/node_modules/@turf/intersect/index.js:62:34)
at intersect (/test-turf/node_modules/@turf/intersect/index.js:74:35)
at intersect (/test-turf/node_modules/@turf/intersect/index.js:102:16)
at Object.<anonymous> (/test-turf/index.js:88:1)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
at Function.Module._load (internal/modules/cjs/loader.js:558:3)
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
D3.js with Turf.js error: "Uncaught (in promise) Error: Each ...
Uncaught (in promise) Error: Each LinearRing of a Polygon must have 4 or more Positions. I've tried D3's d3.geoContain() but it threw false ......
Read more >Each LinearRing of a Polygon must have 4 or more Positions
turf intersect : Each LinearRing of a Polygon must have 4 or more Positions.
Read more >Union GeoJSON polygons - openlayers - GIS Stack Exchange
If I try with just: turf.polygon(geojsonObject) I get the error: Each LinearRing of a Polygon must have 4 or more Positions. Edit 1:...
Read more >Advanced geospatial analysis - Turf.js
Takes any number of features and returns a rectangular Polygon that encompasses all vertices.
Read more >Each Linearring Of A Polygon Must Have 4 Or More Positions.
The Polygon should have properties a b and c that define the values at its three corners.Alternatively the zvalues of each triangle point...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The error that is thrown when you don’t have any internal rings is “Each LinearRing of a Polygon must have 4 or more Positions”. There should be another check to throw an error if there are no rings that says something like: “Each polygon must have at least one internal ring of 4 or more positions.”
@frastlin a full validation of GeoJSON object is expected to be done by the user before using any Turf modules. The
@turf/boolean-valid
module (which might not be perfect) was added to do that.In other words, Turf modules generally expect valid inputs. Checking if the Polygon’s coordinates array contains an array of (valid) LinearRings or (valid) coordinates is not trivial, so it is best keeping that outside the scope of the
intersect
module, in this case.