Edit Vertices/Draw: If polygon lines cross, deleted shape, no error

2891
4
Jump to solution
02-09-2016 04:48 PM
by Anonymous User
Not applicable

Hello -

Someone recently had the issue that when editing a FeatureLayer in my web app it wouldn't save. We found that when drawing a polygon if the lines cross (for instance, drawing a narrow polygon and the sides accidentally cross/touch), the shape deleted itself. The same goes for editing vertices -- if the user accidentally pulled a vertex such that the polygon sides crossed, the shape deleted itself.

I followed this sample relatively closely but in the sample, there is no issue! I somehow broke it.

In ArcMap, looking at the source dataset, the features drawn with crossed lines were listed in the attribute table with the Shape.STArea() and Shape.STLength() attributes as '0'.

My issue is this: in my own code no error was thrown. The applyEdits function runs successfully and creates the objectid. I don't use the TemplatePicker dijit. However I do use the Draw toolbar and take that graphic to applyEdits - I can see the graphic in the console.log just fine.

Any thoughts on where to start debugging my work?

function finishDraw(event, layer) {
            console.log('finishDraw', event);      
            var newAttributes = templateFields(layer);
            console.log(newAttributes);   
            var newGraphic = new Graphic(event.geometry, null, newAttributes);
            var finishDeferred = layer.applyEdits([newGraphic], null, null);
            return finishDeferred.promise;
        }

function templateFields (layer) {
            var fieldObj = {};
            arrayUtils.forEach(layer.fields, function(atts) {
                if (atts.name.search('OBJECTID') == -1) {
                    if (atts.name.search('Shape') == -1) {
                        fieldObj[atts.name] = null;
                    };
                };
            });
            return fieldObj;
        },
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Sarah,

You should check if the polygon is self-intersecting using the "isselfintersecting" method of polygon.

Polygon | API Reference | ArcGIS API for JavaScript | isselfintersecting

and if it is then use the GeometryService Simplify:

GeometryService | API Reference | ArcGIS API for JavaScript | Simplify

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Sarah,

You should check if the polygon is self-intersecting using the "isselfintersecting" method of polygon.

Polygon | API Reference | ArcGIS API for JavaScript | isselfintersecting

and if it is then use the GeometryService Simplify:

GeometryService | API Reference | ArcGIS API for JavaScript | Simplify

by Anonymous User
Not applicable

Thanks so much - I'll add that code in today

0 Kudos
KushendraShah2
New Contributor II

Robert, do you have any samples/template that utilizes this 'selfintersecting' method? I am trying to implement while editing the feature layer. Thanks. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Kushendra,

   No. But it is a simple method you would call after drawing a polygon to know if you need to simplify the geometry:

var isIntersecting = polygon.isSelfIntersecting(polygon);