-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turf polygonize #767
Turf polygonize #767
Conversation
@NickCis 👍 This is a great new module! I'll send over a review |
👎 All source code should be written in ES5 (with the exceptions of tests could be written in ES6). All TurfJS modules should be very minimal with only a single You should consider publishing
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Convert to ES5
- Publish Polygonize as separate module
- Only include single test.js & index.js files as source code
packages/turf-polygonize/index.js
Outdated
* - Dangles: edges which have one or both ends which are not incident on another edge endpoint. | ||
* - Cut Edges (bridges): edges that are connected at both ends but which do not form part | ||
* of a polygon. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @name polygonize
I've used I'm working on the MultiLineString support. Sorry for the delay. |
@NickCis I've got MultiLineString support by adding module.exports = function (lines) {
return polygonize(lineSegment(lines));
}; |
I'm working some issues in the |
Awesome stuff! So far everything looks good to me. |
Finished update of |
packages/turf-polygonize/index.js
Outdated
module.exports = function (geojson) { | ||
return polygonize(lineSegment(geojson)); | ||
}; | ||
module.exports = polygonize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to keep the basic function syntax in case anyone wants to expand the TurfJS method they can easily do so.
module.exports = function (geojson) {
return polygonize(geojson);
}
Noticed you're making Polygon fail, any reason why this should fail? I can already see this error being very annoying, example if you have a collection of LineStrings and you polygonize them you then get a FeatureCollection of Polygons, if you keep adding more LineStrings to that FeatureCollection and re-run polygonize then it would fail since the FeatureCollection will have mixed contents. It seems like throwing an Error against Polygons would make this module less practical. |
@DenisCarriere I thought it would be more coherent to throw an error than just ignore another input that isn't a LineString ([Collection]Feature/Geometry<[Multi]LineString>). The exception is a good way to tell the user "Hey, are you sure that you want to send me all these things that i do not understand?". But, as you are a maintainer of the library, i think that you have a better understanding of the target audience. If you explain me what will the expected behavior of the user, i'll happily make the necessary changes. |
@NickCis As for Polygon Features, you can simply just return itself and not need to polygonize Polygons. if (type === 'Polygon') return feature The only thing that really need to be strict is the output, as long as the output is always the same type. As for Inputs, the more geometry types the better, you could even attempt to properly support |
Come to think of it, polygons with holes might get problematic... 😕 Might be best to leave out Polygons from the supported input Geometry types. @NickCis Keep throwing that Error 👍 |
The library correctly supports As regards And example is the following:
The problem with this approach is that the algorithm still assumes that lines are correctly nodded (i.e.: they only met at their endpoints). So, if the polygon doesn't have a vertex where the line starts, it won't work correctly. Perhaps, it could be useful to add a non default option to find all intersections and divide lines and polygons. I think that it will have a huge impact on performance. Does turf have a module that given |
@DenisCarriere I didn't read you answer before posting, sorry! |
@NickCis This looks awesome, maybe that can be an entirely other module, I had attempted this before but it was getting too complex for the basic implementation I had. I never finished it but this would be ideal for More info here on this issue #580 Here's what I started which was never finished. I like your graph approach. |
Ok!, I'll look the issue and the branch! We'll follow the topic there!. Thanks! |
I'm not getting expected results from polygonize. Where is the appropriate place to ask questions about it? I'm a raw newbie to Turf and barely familiar with Node. |
New Module
@turf/polygonize
Polygonizes a set of Geometrys which contain linework that represents the edges of a planar graph. It's basically an implementation of GEOS's Polygonizer.
I ended up porting this to javascript because I wanted the same functionality as Shapely's polygonize function. This python framework uses GEOS'S C api as backend.
JSDoc
Example
This example is the test found in
test/in/complex.geojson
An example of input's LineString:
Turned into polygons: