2

Arcade/ArcGIS Pro 2.9:

I have an array of polyline vertices:

[[[670634.3148,4862051.3579,null],[670719.3321,4862051.0072,null],[670721.44381227,4862055.2956567,null],
[670724.26721751,4862059.1529319,null],[670727.71675869,4862062.4621395,null],[670731.6879051,4862065.1230012,null],
[670736.06031997,4862067.0548856,null],[670740.70150695,4862068.1992512,null],[670745.47082515,4862068.5214206,null],
[670750.22375097,4862068.011631,null],[670754.81625751,4862066.6853305,null],[670759.10917905,4862064.5827098,null],
[670762.97242811,4862061.7674841,null],[670766.2889375,4862058.3249626,null],[670768.95820776,4862054.3594632,null],
[670770.89935255,4862049.9911516,null],[670772.0535498,4862045.3523998,null],[670772.38582412,4862040.583775,null],
[670771.88610666,4862035.8297796,null],[670770.56954026,4862031.2344731,null],[670768.47602054,4862026.9371059,null],
[670765.66898698,4862023.0679004,null],[670762.2335005,4862019.7441041,null],[670758.27366592,4862017.0664373,null],
[670753.90947724,4862015.1160409,null],[670749.27318152,4862013.9520171,null],[670744.50527143,4862013.6096393,null],
[670739.75022791,4862014.0992824,null],[670735.15214202,4862015.4061089,null],[670730.85034857,4862017.4905182,null],
[670726.97520385,4862020.289347,null],[670723.64413555,4862023.717783,null],[670720.95808431,4862027.6719349,null],
[670718.99844495,4862032.0319811,null],[670717.8246,4862036.6658,null]]]

I want to convert the array to a polyline so that I can use Arcade geometry functions on it.

I've searched the docs, but I can't seem to find an Arcade function that converts an array to a polyline. I see there is a FromJSON() function, but I don't think my array is JSON. And I don't see a FromArray() function in the docs.


How can I convert the array to a polyline using Arcade?

4
  • Where is this array coming from? What mechanism is generating it? If it is being generated in a python environment you could use arcpy to create a polyline geometry.
    – Hornbydd
    Feb 28, 2022 at 17:18
  • 1
    What the paths property of the Polyline object is giving you is the same paths that is set in JSON to pass to the Polyline constructor. Take what you have and embed it into JSON structure and add a "spatialReference" property, and then pass it to Polyline constructor.
    – bixb0012
    Feb 28, 2022 at 20:54
  • 1
    @bixb0012 Thanks! For my notes, I think this is what you're referring to: i.stack.imgur.com/8KTZU.png Source: Arcade Polyline Function
    – User1974
    Feb 28, 2022 at 21:13
  • @User1974, I can a bit later today.
    – bixb0012
    Mar 1, 2022 at 17:19

1 Answer 1

2

From Polyline | Geometry Functions | ArcGIS Arcade:

Polyline(definition) -> Polyline

Constructs a Polyline object from a JSON string or an object literal. The JSON schema must follow the ArcGIS REST API format for Polyline geometries.

and looking at Geometry objects -- Common Data Types | ArcGIS Developers

Polyline

A polyline (specified as esriGeometryPolyline) contains an array of paths or curvePaths and a spatialReference. ... Each path is represented as an array of points, and each point in the path is represented as an array of numbers.

Given an array of coordinates that is compatible/compliant with JSON formatting, one can directly embed the array into a larger JSON definition for the polyline object.

// array of coordinates that is compliant with JSON formatting
var paths = [
    [[-97.06138,32.837],[-97.06133,32.836],[-97.06124,32.834],[-97.06127,32.832]],
    [[-97.06326,32.759],[-97.06298,32.755]]
];

// embed existing array into large JSON definition for polyline
var polylineJSON = {
  "paths": paths,
  "spatialReference": { "wkid": 3857 }
};
Polyline(polylineJSON);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.