You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the function call i'm assuming polygonFromGeoJSON will retrieve a single polygon from a geojson object that only contains a single polygon?
Also the inverted tag has no explanation so I am unsure if this is auto generated when reading from geojson? Maybe an example for this would help.
My use case is to combine 10 to 500 polygons retrieved from 4-15 geojson files. Do I need to extract them individually to union them? polygonFromGeoJSON seems to be what I'm looking for but I'm not sure if the result will be what I am expecting it to do, which is extract all polygon(s) and return an array of PolyboolJS polygons to use in union/intersect/etc.
If you click on the Invert Red or Invert Blue buttons, you can see what toggling the invert flag does. What's considered outside the polygon is now considered inside, and vice-versa.
I don't know if you need to extract the GeoJSON individually, I don't know what your data looks like. The polygonFromGeoJSON function takes an object that looks like { type: "MultiPolygon", coordinates: [[...]] }.
Will polygonFromGeoJSON only extract the first polygon?
About the inverted tag; Will the resulting poly from polygonFromGeoJSON contain a default eg {inverted : false} ? Assuming most polys are not inverted.
Just to add some random feedbacks and caveats of my knowledge and experience about GeoJSON, maybe could help, and lead to improvements in the future.
The types field should respect case (and is camel cased)
A Feature is something in the shape {type: 'Feature', properties: {}, geometry: <Geometry>}
type, properties (don't forget it) and geometry are mandatory
A Geometry is something in the shape {type: <GeometryType>, coordinates: []}OR{type: 'GeometryCollection', geometries: [Geometry]}
There is a trick here, and this library should be concerned about this : GeometryCollectionis a valid geometry, and thus changes the shape of the root Geometry object...
I don't know if a GeometryCollection can be a geometry child of another GeometryCollection, but that's worth checking it
About coordinates, they are separated in "rings" logic
A Polygon coordinates member is in the shape
[ // <= Array of 'rings'
[ // Single outer 'ring'. It MUST be counter-clockwise
[lng, lat], [lng, lat], [...] // Coordinates serie MUST have last === first
],
[ // Inner 'ring' (hole). It MUST be clockwise
[lng, lat], [lng, lat], [...] // Coordinates serie MUST have last === first
],
[ // Another inner 'ring' (hole). It MUST be clockwise
[lng, lat], [lng, lat], [...] // Coordinates serie MUST have last === first
]
]
(I don't know if a "hole" (inner ring) can contain an "island". But that's worth checking...)
A MultiPolygon coordinates member is an array of Polygon coordinates member
A Position (coordinates couple) contains at least lng and lat in this order, but is not limited to this length, and could include, eg., elevation as a 3rd member ([lng, lat, elevation])
Any GeoJSON member can include a srs (or crs, can't remember) member, which represent the projection of the data. The implicit projection when not provided is WGS84 (=== EPSG:4326)
Just switched from Turf to PolyBoolJs, and i must say i love it! We had many problems with Turf when working with it. Sometimes the resulting geometry is invalid, sometimes it create unreasonable geometries.
With PolyBoolJs we didn't encounter such problems!
What would be nice is if we could pass a Feature to PolyBoolJs and not only a geometry. Also if you stick to geometry a more meaningful error would be nice. I first thought the GeoJSON addon did not work.
An Error like: PolyBool: You didn't pass a GeoJSON geometry to PolyBool
Or PolyBool does not support Type: {type}. Try passing a geometry of type 'Polygon' or 'MultiPoligon'
would be nice
Activity
#4 #7 experimental GeoJSON
velipso commentedon Jan 29, 2018
#11 says GeoJSON is working as expected.
Portur commentedon Mar 19, 2018
The documentation is a bit unclear for GeoJson.
From the function call i'm assuming polygonFromGeoJSON will retrieve a single polygon from a geojson object that only contains a single polygon?
Also the inverted tag has no explanation so I am unsure if this is auto generated when reading from geojson? Maybe an example for this would help.
My use case is to combine 10 to 500 polygons retrieved from 4-15 geojson files. Do I need to extract them individually to union them? polygonFromGeoJSON seems to be what I'm looking for but I'm not sure if the result will be what I am expecting it to do, which is extract all polygon(s) and return an array of PolyboolJS polygons to use in union/intersect/etc.
velipso commentedon Mar 19, 2018
The
polygonFromGeoJSONfunction should work onPolygonandMultiPolygonGeoJSON types. It should convert a GeoJSON object to a polybooljs polygon.The easiest way to explain the inverted flag is to see it in the demo:
https://rawgit.com/voidqk/polybooljs/master/dist/demo.html
If you click on the Invert Red or Invert Blue buttons, you can see what toggling the invert flag does. What's considered outside the polygon is now considered inside, and vice-versa.
I don't know if you need to extract the GeoJSON individually, I don't know what your data looks like. The
polygonFromGeoJSONfunction takes an object that looks like{ type: "MultiPolygon", coordinates: [[...]] }.Portur commentedon Mar 19, 2018
Extract all polygons from a geojson file. eg.
This geojson contains
npolygons:{ "type": "Feature", "properties": {"party": "Republican"}, "geometry": { "type": "Polygon", "coordinates": [[ [-104.05, 48.99], [-97.22, 48.98], [-96.58, 45.94], [-104.03, 45.94], [-104.05, 48.99] ]] } }, { "type": "Feature", "properties": {"party": "Democrat"}, "geometry": { "type": "Polygon", "coordinates": [[ [-109.05, 41.00], [-102.06, 40.99], [-102.03, 36.99], [-109.04, 36.99], [-109.05, 41.00] ]] } },{...}Another example geojson collection
Will
polygonFromGeoJSONonly extract the first polygon?About the inverted tag; Will the resulting poly from
polygonFromGeoJSONcontain adefaulteg{inverted : false}? Assuming most polys are not inverted.Portur commentedon Mar 19, 2018
A handy page to play with geojson
http://geojson.io
Added example geojson : pastebin
velipso commentedon Mar 19, 2018
Right, so the object that has
"type": "Polygon"is what needs to be passed topolygonFromGeoJSON, i.e.,data[n].geometry.Yes,
polygonFromGeoJSONwill fill out the inverted flag.cyrilchapon commentedon Jul 10, 2018
Hey.
Just to add some random feedbacks and caveats of my knowledge and experience about GeoJSON, maybe could help, and lead to improvements in the future.
typesfield should respect case (and is camel cased){type: 'Feature', properties: {}, geometry: <Geometry>}type,properties(don't forget it) andgeometryare mandatory{type: <GeometryType>, coordinates: []}OR{type: 'GeometryCollection', geometries: [Geometry]}GeometryCollectionis a valid geometry, and thus changes the shape of the root Geometry object...coordinatesmember is in the shapecoordinatesmember is an array of Polygon coordinates member[lng, lat, elevation])srs(orcrs, can't remember) member, which represent the projection of the data. The implicit projection when not provided is WGS84 (=== EPSG:4326)Some useful stuff :
Sagarpreet commentedon Aug 27, 2019
So does this library returns holes when taking union ?
velipso commentedon Aug 27, 2019
it could if that's the correct answer, you can play with the demo and see for yourself by dragging points around:
domiSchenk commentedon Aug 28, 2020
Just switched from Turf to PolyBoolJs, and i must say i love it! We had many problems with Turf when working with it. Sometimes the resulting geometry is invalid, sometimes it create unreasonable geometries.
With PolyBoolJs we didn't encounter such problems!
What would be nice is if we could pass a Feature to PolyBoolJs and not only a geometry. Also if you stick to geometry a more meaningful error would be nice. I first thought the GeoJSON addon did not work.
An Error like:
PolyBool: You didn't pass a GeoJSON geometry to PolyBoolOr
PolyBool does not support Type: {type}. Try passing a geometry of type 'Polygon' or 'MultiPoligon'would be nice
Keep up the good work!