1

Im using the GEOSwift Library: https://github.com/GEOSwift/GEOSwift

My best guess is that if you look at the string image linked, it looks as if its not a proper circle, so maybe it is a bug in the library? But i am not at all sure about this!

Im having an issue only when i enter one specific linestring. My app takes an array of route coordinates, converts them into WKT String (representing a line). It then Creates a buffer around this line, then converts this into a mapShape.

It runs fine, until i search one specific route.

It fails here:

    func bufferPolyline(routeCoords: [CLLocationCoordinate2D], completion: @escaping (_ bufferCoordsArray: [LatLng]) -> ()) {
        var wktString = ""
        var i = 0
        while i < routeCoords.count {
            let lat = routeCoords[i].latitude
            let lng = routeCoords[i].longitude
            if i == routeCoords.count-1 {
                let wktLast = " \(lng) \(lat)"
                wktString += "\(wktLast)"
                i += 1
            }
            if i >= 1 && i <= routeCoords.count-2 {
                let wktMid = " \(lng) \(lat),"
                wktString += "\(wktMid)"
                i += 1
            }
            if i == 0 {
                let wktFirst = "\(lng) \(lat),"
                wktString += "\(wktFirst)"
                i += 1
            }
        }
        let linestring = Geometry.create("LINESTRING(\(wktString))")! 
        let string = linestring.buffer(width: 0.05)!
        guard let shapeLine = string.mapShape() as? MKPolygon else {
            preconditionFailure() // FAILURE HAPPENS HERE.
        }
}

Here are links to images to see how it looks: LineString - https://i.stack.imgur.com/MMnve.jpg String - https://i.stack.imgur.com/WGeEn.jpg

the linestring, and string values are still coming through even when shapeLine doesnt initialise so im struggling to see where im going wrong. They also seem to be formatted the same way.

I tried to google for a WKT String validator, but didnt find one, but i assume it should be ok, as i return multiple other searches with no issues. (i.e. the shapeLine returns a value)

My question is: does this look like a problem in my code, or a possible bug of the library? (i have little faith in my code!)

Alex A
  • 189
  • 12

0 Answers0