Using sketch widget to draw polygon. It returns polygon rings from selection. I need to convert the ring data to geoJSON and having issues.

806
1
08-24-2021 02:30 PM
naglane
New Contributor

Hello, as the title says I am having trouble converting ring data to geoJSON. 

I had a look at the Geometry class from the ArcGIS javascript library, but I don't understand how to use it to convert the ring data to geoJSON. 

The array of rings that I am working with looks like this:

rings = [
          [
           -13441425.32511117,
           4491520.711015136
        ],
        [
          -13440894.1920939,
          4491511.685098792
        ],
       [
          -13440922.71925878,
          4490494.010447212
        ],
      [
          -13441438.25014971,
          4490494.010447212
        ],
       [
          -13441425.32511117,
          4491520.711015136
      ]
  ]

Any help would be greatly appreciated! 

 

Tags (4)
0 Kudos
1 Reply
MehdiPira1
Esri Contributor

Hi @naglane ,

The following code snippet converts rings to polygonJson (geojson):

const rings = [
 [
       [
          -13441425.32511117,
          4491520.711015136
        ],
        [
          -13440894.1920939,
          4491511.685098792
        ],
       [
          -13440922.71925878,
          4490494.010447212
        ],
      [
          -13441438.25014971,
          4490494.010447212
        ],
       [
          -13441425.32511117,
          4491520.711015136
      ]
  ]
];

const polygon = new Polygon({
  rings: rings,
  spatialReference: { wkid: 4326 }
});

 I hope that's helpful.

0 Kudos