Support for string manipulation and pattern matching in Arcade

424
4
Jump to solution
02-11-2026 10:38 AM
RJSunderman
Esri Regular Contributor

Hello,

Given a string representation of a Esri polyline feature:

{"paths":[[[-86.762566,36.180317],[-86.760232,36.184474],[-86.75721,36.186857],[-86.75467,36.188519],[-86.752679,36.194005]]],"spatialReference":{"wkid":4326}}


Is there an Arcade expression which supports pattern matching similar to Regular Expression pattern matching?  I want to parse the JSON string and extract the longitude value (-86.762566) and the latitude value (36.180317) as separate Double values from the first coordinate pair of the polyline. Similarly, I need to parse the string to locate the last coordinate pair and extract the longitude and latitude values for the point at the other end of the polyline. The coordinate values in the JSON string will not always have the same number of significant decimals. Also, the polyline will not always have the same number of vertices.

Finally, while the coordinate values in the example above are all in North America, that cannot be assumed. The pattern match cannot, for example, assume the longitude will always be negative and the latitude will always be positive.

1 Solution

Accepted Solutions
AlfredBaldenweck
MVP Frequent Contributor

Related: Arcade: Regular Expression Support - Esri Community

 

I would probably use FromJSON and then traverse over the resulting dictionary.

View solution in original post

4 Replies
AlfredBaldenweck
MVP Frequent Contributor

Related: Arcade: Regular Expression Support - Esri Community

 

I would probably use FromJSON and then traverse over the resulting dictionary.

RJSunderman
Esri Regular Contributor

Thank you @AlfredBaldenweck for your quick reply.  Expressions like those below give me the access I need to the elements in the JSON.

var d = fromJSON('{"paths":[[[-86.762566,36.180317],[-86.760232,36.184474],[-86.75721,36.186857],[-86.75467,36.188519],[-86.752679,36.194005]]],"spatialReference":{"wkid":4326}}')
var pFirst = First(d.paths[0])
var pLast = First(Reverse(d.paths[0]))

 

RPGIS
by MVP Regular Contributor
MVP Regular Contributor

You can also use the following:

vr G = Geometry($feature) ; var Paths = G.paths:
for( var p in Paths ){ var lastpnt = p[-1] ; console(lastpnt ) }
0 Kudos
RJSunderman
Esri Regular Contributor

Thank you @RPGIS ... unless I'm doing something wrong, though, the Geometry and Polyline functions do not accept my JSON string. It seems like the specified "spatialReference":{"wkid":4326} is not supported. Cross reference Arcade Geometry Function not working 

If I remove the spatial reference from the JSON string Arcade will construct a Geometry which assumes WKID 3857. That does not interfere with pulling coordinate values out as Double. But it does feel odd specifying a Geometry without a spatial reference and allowing Arcade to assume an incorrect default.

var G = Geometry({"paths":[[[-86.762566,36.180317],[-86.760232,36.184474],[-86.75721,36.186857],[-86.75467,36.188519],[-86.752679,36.194005]]],"spatialReference":{"wkid":102100}})
var Paths = G.paths

for (var i=0; i < Count(Paths[0]); i++)
  { Console( "Longitude: " + Paths[0][i].y + ' / ' + "Latitude: " + Paths[0][i].x); }

  

0 Kudos