1

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.

Seth Lutske
  • 9,154
  • 5
  • 29
  • 78
anakaine
  • 1,188
  • 2
  • 14
  • 30
  • Would you mind sharing a bit about what you're using to draw polygons / other geo data? The line `var drawngeo = drawnItems.toGeoJSON()` hints that a drawn item creates an entire, complete GeoJSON object, then submits it as a new feature. Is that correct? – Seth Lutske Feb 10 '21 at 16:57

1 Answers1

1

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.

Andrew T
  • 31
  • 4
  • Thanks, there's a few little useful reinforcements of other reading in your answer. To some degree the ESRI-Leaflet library takes care of many of the constructions - though my first example does show how I'm doing it manually. I think the next step will be to try taking the layer object geojson, adding elements that I need by array ID, then avoid my custom construction of the object and try handing off the entire geojson to the rest service. It is that last part that I suspect will not work, and probably how I wound up with a custom construction in the first place. – anakaine Feb 11 '21 at 23:06
  • I understand more now what your trying to do. Geojson supports multipart, so one would presume that a conversion library would translate it. But that is not without hassle in parsing the input. This is why I typically prefer the option to process server side using C#/.NET. Without delving into WebApi or ArcGIS SOI's, you may look into writing a Geoprocessing service if you need to pass a custom object without a lot of hassle. Then you can tinker and parse your objects neatly there and keep the client side clean. – Andrew T Feb 12 '21 at 06:26