Apply many edits to a feature layer applyedits

2726
17
Jump to solution
12-16-2016 02:07 PM
by Anonymous User
Not applicable

Hi all,

I am trying to batch insert features (parcels) into a feature layer using feature.applyedits. I am not successful yet. Any tips?

Here is what I got: 

 on(dom.byId("createproject"), "click", function () {
                    $("#showattribute").css("display", "inline-block");
                    $("#gifspin").css("display", "inline-block");
                    projectarea.setAttributes({ "START_DATE": Date.parse($("#projectstartdate").val()), "FINISH_DATE": Date.parse($("#projectfinishdate").val()), "Name": $("#projectname").val(), "PROJECT_ID": $("#tesr").val(), "TREE_COUNT": $("#messages").text(), "ACRES": $("#area").text() });

                    
                    //Index array

                    arrayUtil.forEach(projectparcels, function (feature) {
                        feature.setAttributes({
                            "ID": $("#tesr").val(), "OWNER_NAME ": feature.attributes["OWNER_NAME"], "OWNER_ADDR": feature.attributes["OWNER_ADDR"],
                            "OWNER_CITY": feature.attributes["OWNER_CITY"],
                            "OWNER_STAT": feature.attributes["OWNER_STAT"], "OWNER_ZIP": feature.attributes["OWNER_ZIP"],
                            "PRCL_ID": feature.attributes["PRCL_ID"], "SITUSNUMBR": feature.attributes["SITUSNUMBR"], "SITUSSTRNM": feature.attributes["SITUSSTRNM"],
                            "SITUSSTRTY": feature.attributes["SITUSSTRTY"]
                        });
                        featurelayerParcels.applyEdits([feature], null, null, function () {
                            console.log("Parcel updated!");

                        },
                            function (error) {
                                console.log("Features not updated! ", error);
                            });
                    });

...});

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Alex,

   So because you have:

projectparcels = feature;

That means the projectparcels is an individual graphic.

Another issue is that a graphic can only exist once, meaning you can not add it to a graphicslayer and add the same graphic to your FeatureLayer. You will have to clone the graphic for one of the layers you are adding it to.

You something like this:

var newGraArr = []
...
//update the attributes
...
newGraArr.push(new Graphic(feature.toJson()));
...
featurelayerParcels.applyEdits(newGraArr, null, null, function () {

View solution in original post

17 Replies
RobertScheitlin__GISP
MVP Emeritus

Alex,

   Projectparcels is a array of graphics so set your attributes like you are but don't do the applyEdits until after you are out of the forEach loop

featurelayerParcels.applyEdits(projectparcels, null, null, function () {
    console.log("Parcel updated!");
}
0 Kudos
by Anonymous User
Not applicable

I tried and i get this error

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   What is line 582 of your code?

0 Kudos
by Anonymous User
Not applicable
                function queryCallback(featureSet) {

                    var symbol = new SimpleFillSymbol(
                        SimpleFillSymbol.STYLE_SOLID,
                        new SimpleLineSymbol(
                            SimpleLineSymbol.STYLE_SOLID,
                            new Color([0, 0, 0, 0.65]), 2
                        ),
                        new Color([255, 255, 0, 0.35])
                    );

                    featureArray = featureSet.features;
                    arrayUtil.forEach(featureArray, function (feature) {
                     
                        projectparcels = new Graphic(feature, symbol);
                        map.getLayer("GraphicsParcel").add(projectparcels);
                    });

It seems like my issue is that grphic array is null and returning no features. I think it is missing its geometry.

To answer your question, line 582 is this: 

featurelayerParcels.applyEdits([projectparcels], null, null, function () {
                        console.log("Parcel updated!");

                    },function (error) {
                            console.log("Features not updated! ", error);
                        });
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   The issue I see now is that projectparcels is already an array of graphics (i.e. a FeatureSet) so the fact that you are adding that to another array instead of using the code I posted earlier is an issue.

Your doing:

featurelayerParcels.applyEdits([projectparcels], null, null, function () {

I said this:

featurelayerParcels.applyEdits(projectparcels, null, null, function () {
0 Kudos
by Anonymous User
Not applicable

Ha good point. I tried. no success. No errors anymore though.The layer does show any updated parcels.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

  Are you updating or adding new parcels? If you are updating then the array of graphics goes in the second parameter instead.

featurelayerParcels.applyEdits(null, projectparcels, null, function () {
0 Kudos
by Anonymous User
Not applicable

I am trying to add new parcels to a feature layer from a user selection. It

works for but not for the whole list of selected parcels.

On Fri, Dec 16, 2016 at 3:50 PM, Robert Scheitlin, GISP <geonet@esri.com>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Are you adding all the field in the feature class to the attributes?

0 Kudos