-
Notifications
You must be signed in to change notification settings - Fork 943
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 not creating polygons from grid of multilinestring lines #819
Comments
@NickCis Can you have a look at this? You are the one most "qualified" to answer/fix this. |
Current implementation of
As far as i understand, in this test case the I must highlight that (according to the docs) this is the library's expected behavior. At the moment, the user has to look for all the intersections and make the |
Oh sorry. I read "I ended up porting this to javascript because I wanted the same functionality as Shapely's polygonize function" in the PR intro and assumed there was feature parity with Shapely (because that's what I wanted to believe ;-). |
As far as i know Shapely is calling the GEOS's polygonizer class. This is a javascript port of that c++ class. I think that with Shapely you'll get the same problem. If that's not the case, please tell me so (if possible, inform the Shapely version used and a working example). i could try to port that functionality. |
We can always attempt to port over Shapely's We've done this so far with some of the This test process is a bit unconventional, but if you want to check |
According to https://gis.stackexchange.com/a/95374/108 Qgis' polygonize uses shapely, and that's how I produced the "expected output" above. |
@maphew I really don't know what QGis is exactly doing, but if i run Shapely's polygonize i get the same blank result. Using the following script (i'm using shapely 1.5.17): #! /usr/bin/env python
import sys
import json
from shapely.ops import polygonize
from shapely.geometry import asShape
from shapely.geometry import mapping
def main(in_path, out_path):
with open(in_path, encoding='utf-8') as f:
geo_json = json.load(f)
output = {
'type': 'FeatureCollection',
'features': []
}
for poly in polygonize(asShape(geo_json)):
output['features'].append({
'type': 'Feature',
'properties': {},
'geometry': mapping(poly)
})
with open(out_path, 'w') as f:
json.dump(output, f)
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2]) It's first argument is the input geojson, and the second one the output feature collection: $ ./polygonizer.py input.geojson outpu.geojson When running with your example, i get a blank result, as with turf's Polygonizer. If it is run with an example that has the lines correctly nodded, eg: {
"coordinates": [
[
[0, 0],
[1, 1]
],
[
[0, 0],
[0, 1]
],
[
[0, 1],
[1, 1]
],
[
[1, 1],
[1, 0]
],
[
[1, 0],
[0, 0]
]
],
"type": "MultiLineString",
"properties": {}
}
The polygons are formed. If you read the performace section of Shapely's ops documentation, it says that it is using geos c library. Turf's polygonize is a port of the Polygonizer class of that library, so you get similar results. |
I've been reading the QGis source code in order to understand what QGis is doing. Apparently, when you are running "QGis >> Vector geometry Tools >> Polygonize", it runs this QGis Polygonize algorithm. If you look at the The
The
So, in terms of a library, turf's I really don't know (please help me @DenisCarriere ) if there is a function in turf that does something similar to |
Thank you for the attention and research Nicolas!
|
⭐️ 👍 @NickCis Great research. Unfortunately we Turf does not have any methods that performs I have no issues if you call this new module exactly the same name as QGIS The only library that would do a similar effort would be |
Ok!, I'll be starting to work on that new module. I'll update with further news. |
turf.polygonize isn't creating polygons from this input:
Code snippet:
Full test case - https://jsfiddle.net/87cq6edb/
The text was updated successfully, but these errors were encountered: