ESRI LEaflet - Adding ESRI GeoJSON / MultiPart Polygons to a REST service

395 views Asked by At

I'm currently allowing users to draw into an ESRI-Leaflet map using a drawing layer, adding some additional properties to that layer, and then submitting the results to a feature service.

This is great for single polygons. The methodology, however, doesn't work for multipart (multipolygon) polygons, or mixed feature types in a FeatureCollection. I specifically wish to submit multipart polygons rather than iterating through available features. There are some follow on GIS functions that rely on them being multipart.

Below is a sampleset of how I'm currently dealing with things. Then, a concept of what I'm thinking regarding multipart.

My question is -
When using geojsonToArcGIS can I use the result with addFeature to have a multipart polygon added to the feature service?

Not only do I not know if this is a valid approach, I'm not sure if there might be a better way of approaching this. There's not much documentation or examples to work with online around adding multipart feature collections using ESRI Leaflet.

Currently using:


 var feature = {
            type: 'Feature',
            geometry: Geometry,
            properties: {
                LGA: String(lga),
                Locality: String(locality),
                Region: String(region),
            };

service.addFeature(feature, function (error, response) {
            if (error) {
                console.log('error creating feature' + error.message);
            } else {
                console.log('Successfully created feature with id ' + response.objectId);
            }
        });

Rather than using the above, I'm wondering if it is possible to do something more along the lines of:

//We start with a drawing layer, ingested as drawngeo. Lets assume it has 3 polygons (or lines) at this point. 
if (eventtype == "create") {
            var drawngeo = drawnItems.toGeoJSON(); //This makes the JSON accessible
            drawngeo.features[0].properties.TestKey = "Test"; //Add a custom property, for example.
            var drawnesrijson = L.esri.Util.geojsonToArcGIS(drawngeo,"OBJECTID"); //Make it ESRI-JSON
}

service.addFeature(drawnesrijson, function (error, response) { //We have used the ESRI GeoJSON instead
            if (error) {
                console.log('error creating feature' + error.message);
            } else {
                console.log('Successfully created feature with id ' + response.objectId);
            }
        });

In case this helps with people finding this in future, here are a few extra keywords: ArcGIS Online, AGOL, ESRI, ArcGIS Portal.

1

There are 1 answers

2
Andrew T On

Multipart polygons are supported by the ArcGIS Rest API using EsriJson and also as GeoJson. The library you are using is looks to be the same as this one from Esri and should be able to convert to multipart but if it is not then you're going to probably need to construct the object yourself as you're doing in the first example.

Here is an example EsriJson object constructed with geometry as a multi-part polygon:

{
  "attributes" : {
    "DESCRIPTION" : "Test case multipolygon"
  }, 
  "geometry" : 
  {
    "rings" : 
    [
      [
        [155000, 463000], 
        [156000, 463000], 
        [156000, 464000], 
        [155000, 464000], 
        [155000, 463000]
      ], 
      [
        [157000, 463000], 
        [158000, 463000], 
        [158000, 464000], 
        [157000, 464000], 
        [157000, 463000]
      ]
    ]
  }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

It may be helpful to perform a console.log() on the output of drawnesrijson() and check that the Json array matches the format above. If it does not then you will need to check that your input is valid (no donuts or overlapping geometry) or construct the geometry to match the EsriJson format for multipart and then append it to your Json object as you do in example 1 above.