GEOSwift: Invalid Intersection result after upgrading to GeoSwift 7.0.0+

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

  do {
             for lineString in multiLineString.lineStrings {
                if try lineString.intersects(polygon) {
                    let intersectingGeometry = try lineString.intersection(with: polygon)
                    // Handle Intersection here
                }
            } 
   } catch {
            DDLogError("Unable to get the intersection of line string with the geometry. \(error.localizedDescription)")
            return nil
        }

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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 30 (12 by maintainers)

Most upvoted comments

This has been fixed in GEOS. See GEOS 1093.

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!

That worked! However, I had to set it to 8.0.0, setting it to 8.0.1 resulted in the following error

[!] CocoaPods could not find compatible versions for pod "GEOSwift":
  In Podfile:
    GEOSwift (= 8.0.1)

None of your spec sources contain a spec satisfying the dependency: `GEOSwift (= 8.0.1)`.

You have either:
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

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)

No timeline for next GEOS release at the moment.

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.

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.

This is now available in version 8.0

@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 normalize and it adds a method normalized() -> Geometry that can be used on any type conforming to GeometryConvertible.

@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.

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.

Thanks for reporting this. I’ll take a look in the next few days.