-
Notifications
You must be signed in to change notification settings - Fork 172
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
Invalid Intersection result after upgrading to GeoSwift 7.0.0+ #212
Comments
|
Thanks for reporting this. I'll take a look in the next few days. |
|
The only differences I'm seeing in the output are with the results of the line strings at indexes 22, 24, and 26. GEOSwift v6 is on the left, v7 on the right. It seems like the difference is in the order in which the line strings are included in the multilinestrings. This must be a difference between GEOS 3.7.1 (packaged for SPM as GEOSwift/geos 4.1.0) and GEOS 3.9.0 (packaged for SPM as GEOSwift/geos 5.1.0) As far as I'm aware these two results would be considered topologically equivalent. You can check for topological equivalence between 2 geometries using the method Let me know if this helps. |
|
Thanks a lot for the quick reply! Yeah, I guess they would be topologically equivalent. However, the order of the intersection points is quite critical to us. I also believe that the order of the intersection points in the previous version of GEOS was in sync with that of other GeoSpatial libraries like Shapely, ArcGIS, etc. Can you suggest a workaround for this? Like maybe a way to sort the coordinates or something to retain the previous order. Thanks. |
|
I think we'll need to bubble this up to the GEOS folks to get their perspective. I'll ask for guidance on their mailing list. |
|
@india2sarthak in the mean time, one option you have is to downgrade geos to 5.0.0. This will likely resolve this issue for you. |
Shapely uses GEOS as well, so that is probably why it is consistent (and why it will also change with GEOS 3.9). There is no relationship to ArcGIS - any similarity is purely coincidental. In general there is no "defined" ordering to the output from Overlay. In fact Overlay avoids imposing any ordering, in order to minimize processing time.
GEOS provides a normalize operation which does a lexicographical sort of geometries in a collection. That is the usual way to enforce a consistent ordering for geometries. |
|
I just checked. Looks like we haven't exposed it yet, but we can add it. |
|
@india2sarthak I've pushed a branch with this change. Please test it out and let us know whether it meets your needs. The branch is named |
|
Thanks so much! Will test it out and get back to you. |
|
This is now available in version 8.0 |
|
Hey. Thanks a lot for pushing the experimental branch (normalize) and a new release. I tried using the |
|
I've pushed a new branch issue212 which contains a variant of the latest GEOSwift modified to run against an older geos version. I don't think it makes sense for this to be an officially supported part of GEOSwift since we want to keep up with the evolution of geos, but what you could do is maintain a fork that tracks upstream and maintains compatibility with the older geos version. In addition, could you share a bit more about your use case? I'm curious whether we could help you come up with another approach if we knew a bit more about what you're building. |
|
So we use GeoSwift in a drone-based mapping application wherein we obtain the drone path for mapping a geometry. 1.) For this, we first find the bounding box of the geometry using the 2.) We then draw lines inside the bounding box at equal intervals using the 3.) Finally, we find the intersection of these lines with the original geometry using the Hence, the order of the intersecting points is critical to us as a change in the order of the intersecting points changes the path of the drone completely. |
|
Also, I noticed that this issue is only present for concave geometries. We don't face this issue with convex geometries as such. The order changes if the line intersects the geometry at more than 2 points (convex geometries). |
|
Ok, I understand the problem now, and I can reproduce it in GEOS and JTS. And I agree that it is desirable that the order of results from polygon-linestring intersections be faithful to the ordering of the original lines. I'm looking in to whether this is possible to do as an improvement to the OverlayNG code. I do note that the direction of each result line is consistent with the input line. So this provides a workaround - sort the output lines by the distance of their start point along the input line. |
|
@india2sarthak Are you computing the intersection one line at a time? Or for the whole ensemble (in which case how do you determine the ordering within the output?) It would be nice to preserve the total ordering of the input line ensemble in the result (which is not done now in OverlayNG, but seems to be the case in the previous overlay). This should be feasible to do for OverlayNG. That would allow matching result lines to the input lines in an efficient way, by scanning both lists and computing the nearest input line to each result line start point. Is this what you are doing now? |
|
It looks like there is a fairly simple fix to this ordering problem. I will add that to JTS, and we'll work through the pipeline to land in GEOS too. |
|
Sounds great! Thanks @dr-jts. @india2sarthak I'm not sure when we should expect this to land in a GEOS release, but when it does, we can update our CocoaPods & SPM packages accordingly so you'll have access to it and won't need to maintain a fork. We can leave this issue open until then. |
|
@dr-jts Any updates on the fix landing in the GEOS? |
|
This has been fixed in GEOS. See GEOS 1093. |
|
That's great! Thanks so much for the update. Any update on when the next version of GEOS would be released? |
|
No timeline for next GEOS release at the moment. |
|
GEOS 3.9.1 has been released with this fix. I've tagged a new version of GEOSwift/geos that includes the update. @india2sarthak could you please update your geos dependency and verify the fix? (There's not a new GEOSwift version since the current version is already compatible with the new geos.) |
|
Wow, that's great! I will get back to you on this |
|
I tried upgrading geos on my end. However, I am getting this error I am currently targeting iOS 13.0 in my app, even tried increasing it to 14.2, it still resulted in the same error on running Here is a copy of my Podfile Any idea where I am going wrong? Thanks! |
|
You'll want GEOSwift 8.0.1 |
|
That worked! However, I had to set it to 8.0.0, setting it to 8.0.1 resulted in the following error Additionally, I was able to test the fix and I can confirm that the issue has indeed been resolved in the latest version of GEOS (3.9.1) |
|
Thanks! I realize now that 8.0.1 was never published to CocoaPods because the only change was to the Swift Package Manager configuration. Glad it's working! |





I'm using GeoSwift for performing geospatial operations in a mobile app. Prior to v7.0.0, the intersection operation used to work as expected, however, after upgrading to v7.0.0 from 6.2.0, the same method returned a different result. Please find the attached geoJson files in the zip file for reproducing the error.
Parent: polygon.json (polygon)
LineString: multiLinestring.json (multiLineString)
And here is the code I am using for the same
Essentially I am getting a different result when I run the intersection operation on GeoSwift v6.2.0 (Expected) and GeoSwift v7.1.0 (Possibly Incorrect)
Is there something else I need to do to find an intersection in the newer versions of GeoSwift?
Thanks a lot for helping :)
Here is the environment I am using
Xcode : 12.2
GeoSwift: 7.1.0
GEOS: 5.1.0
Apologies for not being able to find a simpler example to illustrate the problem 😅
// Zip containing the geojson files
TestData.zip
The text was updated successfully, but these errors were encountered: