Select to view content in your preferred language

Apply many edits to a feature layer applyedits

2982
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
17 Replies
by Anonymous User
Not applicable

No. I am leaving OBJECTID aside because It is not necessary. Is that a problem?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

No that is not an issue if that is the only value you are not providing.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   Wait a second in your original code post projectparcels was an array of graphics and latter in your back and forth you have

projectparcels = new Graphic(feature, symbol);

Which means it is just one graphic. So I am not sure where your code is currently.

0 Kudos
by Anonymous User
Not applicable

My current code:

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 = feature;
                        feature.setSymbol(symbol);
                        map.getLayer("GraphicsParcel").add(feature);
                    });
0 Kudos
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 () {
by Anonymous User
Not applicable

That was it! Thanks Robert

0 Kudos
by Anonymous User
Not applicable

Also, an array of features is returned to the map as shown below:

0 Kudos
by Anonymous User
Not applicable

the feature I add:

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"]
                        });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

the feature class fields:

query.outFields = ["OBJECTID", 
                  "OWNER_NAME", 
                  "OWNER_ADDR", 
                  "OWNER_CITY",
                  "OWNER_STAT", 
                  "OWNER_ZIP",
                   "PRCL_ID",
                  "SITUSNUMBR",
                 "SITUSSTRNM", 
                  "SITUSSTRTY"];
0 Kudos