<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Decode compressed geometry in iOS and Android client sdks in ArcGIS Runtime SDK for iOS Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1207671#M7442</link>
    <description>&lt;P&gt;Thanks a lot for sharing. I also implemented the decompression in kotlin and it works for now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you planning to add support for this in the official sdk?&lt;/P&gt;</description>
    <pubDate>Tue, 30 Aug 2022 13:54:36 GMT</pubDate>
    <dc:creator>JulianBissekkou</dc:creator>
    <dc:date>2022-08-30T13:54:36Z</dc:date>
    <item>
      <title>Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1201792#M7423</link>
      <description>&lt;P&gt;I get compressed geometry from an arcgis server when requesting a route. I would like to draw the route on the clients map.&lt;/P&gt;&lt;P&gt;Is there an API on how to uncompress the geometry and create a Path (or any other data structure) from it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 08:25:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1201792#M7423</guid>
      <dc:creator>JulianBissekkou</dc:creator>
      <dc:date>2022-08-11T08:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1202199#M7426</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;Are you making REST requests yourself against the routing service?&amp;nbsp;If you're using the Runtime SDK, simply use the AGSRouteTask. It will handle unpacking the response into Runtime geometry objects. See these links:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/ios/route-and-directions/#route-task" target="_blank"&gt;https://developers.arcgis.com/ios/route-and-directions/#route-task&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/ios/swift/sample-code/find-route/" target="_blank"&gt;https://developers.arcgis.com/ios/swift/sample-code/find-route/&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 21:31:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1202199#M7426</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2022-08-11T21:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1202275#M7427</link>
      <description>&lt;P&gt;No, in my case a server calls the routing service and returns the client a json with some additional information.&lt;/P&gt;&lt;P&gt;This is why I have to deal with the compressed geometry instead of using the&amp;nbsp;&lt;SPAN&gt;AGSRouteTask.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 04:54:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1202275#M7427</guid>
      <dc:creator>JulianBissekkou</dc:creator>
      <dc:date>2022-08-12T04:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1202388#M7428</link>
      <description>&lt;P&gt;I see. Interesting. I'll do some digging and will let you know what I find out.&lt;/P&gt;&lt;P&gt;In the meantime, does your server specify returnRoutes=true? My understanding (though I'm slightly guessing at this point) is than maneuver geometries come back compressed, but the overall route geometry should be a full Esri JSON geometry that you could pass to AGSPolyline.fromJSON.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 14:48:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1202388#M7428</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2022-08-12T14:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1204167#M7433</link>
      <description>&lt;P&gt;So, I have some information, but it means you'll have to write some code yourself &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Take a look at &lt;A href="https://github.com/patrickarlt/terraformer-arcgis-parser/blob/6ed966931c3bc05dace8700baeef339bc9d4a90b/terraformer-arcgis-parser.js#L21-L50" target="_self"&gt;this code&lt;/A&gt; form Terraformer, which shows how to decompress this geometry using JavaScript. You'd have to translate that to Swift of course but it should show how to do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  function decompressGeometry(str) {
    var xDiffPrev = 0;
    var yDiffPrev = 0;
    var points = [];
    var x, y;
    var strings;
    var coefficient;


    // Split the string into an array on the + and - characters
    strings = str.match(/((\+|\-)[^\+\-]+)/g);


    // The first value is the coefficient in base 32
    coefficient = parseInt(strings[0], 32);


    for (var j = 1; j &amp;lt; strings.length; j += 2) {
      // j is the offset for the x value
      // Convert the value from base 32 and add the previous x value
      x = (parseInt(strings[j], 32) + xDiffPrev);
      xDiffPrev = x;


      // j+1 is the offset for the y value
      // Convert the value from base 32 and add the previous y value
      y = (parseInt(strings[j + 1], 32) + yDiffPrev);
      yDiffPrev = y;


      points.push([x / coefficient, y / coefficient]);
    }


    return points;
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/terraformer-arcgis-parser/pull/15/files" target="_self"&gt;This pull request&lt;/A&gt; also includes a test that could help.&lt;/P&gt;&lt;P&gt;If you come up with a Swift version of this, please share! I won't have time to try until next week, but it should be achievable.&lt;/P&gt;&lt;P&gt;For reference, here is some &lt;A href="https://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/networkanalyst/INACompactStreetDirectionProxy.html#getCompressedGeometry()" target="_self"&gt;really old documentation&lt;/A&gt; that explains the process.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 13:46:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1204167#M7433</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2022-08-18T13:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1205521#M7436</link>
      <description>&lt;P&gt;FYI, I built &lt;A href="https://gist.github.com/nixta/d8b61aac11c001075c8e7acc84704415" target="_self"&gt;this&lt;/A&gt; from the Terraformer code. Hope that works for you!&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;extension AGSGeometry {
    static func decodeCompressedGeometry(_ compressedString: String, spatialReference sr: AGSSpatialReference) -&amp;gt; AGSPolyline? {
        // Break the string up into signed parts.
        // The first part is a coefficient.
        // Subsequent pairs of parts make up the remaining coordinates.
        
        let pattern = #"((\+|\-)[^\+\-]+)"#
        guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else {
            return nil
        }
        
        let range = NSRange(compressedString.startIndex ..&amp;lt; compressedString.endIndex,
                            in: compressedString)
        
        let components = regex.matches(in: compressedString, range: range).compactMap {
            Range($0.range(at: 0), in: compressedString)
        }.compactMap { range -&amp;gt; Double? in
            let val = Int(compressedString[range], radix: 32) ?? 0
            return Double(val)
        }

        guard let coefficient = components.first,
              (components.count - 1) % 2 == 0 else {
            preconditionFailure("Invalid compressed geometry. Needs coefficient plus even number of subsequent parts!")
        }
        var coordinatePairs = [(Double,Double)]()
        
        for i in stride(from: 1, through: components.count - 1, by: 2) {
            let pair = (components[i],components[i+1])
            coordinatePairs.append(pair)
        }

        var xDiffPrev = 0.0
        var yDiffPrev = 0.0
        var x = 0.0
        var y = 0.0
        
        let builder = coordinatePairs.reduce(AGSPolylineBuilder(spatialReference: sr)) { builder, pair in
            
            x = pair.0 + xDiffPrev
            xDiffPrev = x
            
            y = pair.1 + yDiffPrev
            yDiffPrev = y
            
            let newPoint = AGSPoint(x: x / coefficient, y: y / coefficient, spatialReference: sr)
            
            builder.add(newPoint)
            return builder
        }
        
        return builder.toGeometry()
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 19:00:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1205521#M7436</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2022-08-23T19:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1207671#M7442</link>
      <description>&lt;P&gt;Thanks a lot for sharing. I also implemented the decompression in kotlin and it works for now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you planning to add support for this in the official sdk?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 13:54:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1207671#M7442</guid>
      <dc:creator>JulianBissekkou</dc:creator>
      <dc:date>2022-08-30T13:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1207802#M7445</link>
      <description>&lt;P&gt;It's not planned, no.&lt;/P&gt;&lt;P&gt;Most people will use Runtime directly against the service.&lt;/P&gt;&lt;P&gt;In your case do you need to parse out just the compressed geometry, or would it be helpful to be able to parse the entire route result into an AGSRouteResult?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 17:00:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1207802#M7445</guid>
      <dc:creator>Nicholas-Furness</dc:creator>
      <dc:date>2022-08-30T17:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Decode compressed geometry in iOS and Android client sdks</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1209855#M7448</link>
      <description>&lt;P&gt;The server annotates different parts of my route with additional information. Every part of the route has compressed geometry that is then used to draw the route.&lt;/P&gt;&lt;P&gt;I think we won't be able to parse the result into an AGSRouteResult because of the custom strucutre.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 14:02:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/decode-compressed-geometry-in-ios-and-android/m-p/1209855#M7448</guid>
      <dc:creator>JulianBissekkou</dc:creator>
      <dc:date>2022-09-06T14:02:16Z</dc:date>
    </item>
  </channel>
</rss>

