copy features from one layer to another?

4199
9
08-27-2012 03:00 PM
evanpicard
New Contributor II
I have polygons in one layer, I'd like a user to be able to select them, and copy them into a new layer, and hopefully dissolve, making aggregate polygons.

I'm using the draw toolbar to create the selection polygon...

        tb = new esri.toolbars.Draw(map);
        tb.activate(esri.toolbars.Draw.POLYGON);
        dojo.connect(tb, "onDrawEnd", addGraphic);



I can query the polygon layer...

      function addGraphic(geometry){
        tb.deactivate();
        var polySymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,255]), 2), new dojo.Color([255,255,0,0.25]));
        var polyGraphic = new esri.Graphic(geometry, polySymbol);
        map.graphics.add(polyGraphic);
        var queryPolyTask = new esri.tasks.QueryTask(serverVar + "/ArcGIS/rest/services/IndivTerritoriesOnly/CurrentAll/MapServer/1");
        var polyQuery = new esri.tasks.Query();
        polyQuery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
        polyQuery.outSpatialReference = {"wkid": 102100};
        polyQuery.returnGeometry = true;
        polyQuery.geometry = geometry;
        polyQuery.outFields = ["ziptext"];
        queryPolyTask.execute(polyQuery); 
        dojo.connect(queryPolyTask, "onComplete", function(results){
          doZipManager(results);
        });
        };


and I've created a graphic layer to display it.

      function doZipManager(results){
        var items = dojo.map(results,function(result){
          var graphic = result.feature;
          zoomSelExtent = graphic.geometry.getExtent(); 
          graphic.setSymbol(symbol);
          map.graphics.add(graphic);
          return result.feature.attributes;
        });
        var selectedZipGraphic = new esri.layers.GraphicsLayer();
        var selectedZipSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,122,122]), 2), new dojo.Color([180,200,0,0.25]));
        var zipResultFeatures = results.features;
        selectedZipGraphic.setRenderer(selectedZipSymbol);
        dojo.forEach(zipResultFeatures, function (feature) {
            var graphic = feature;
            graphic.setSymbol(selectedZipSymbol);
            selectedZipGraphic.add(graphic);
            items.push(feature.attributes);
        });
        map.addLayer(selectedZipGraphic);

      };



But is it possible to save this selection for long term use?  I've seen suggestions of saving a cookie or using local storage, but thats just not working for me. 
I'd like to save these selections in the database, if possible.  This is to be a distributed app, and the central office would like access to what users are creating. 
I dont care if its a feature class or a table.  Creating a webservice has been suggested, but I can't even wrap my head around it. 
I'm using Javascript and HTML, SQL Server 2008.  I dont know anything about .net, and I don't have time to start learning it now.

Thank you to any and all insight.
Really in a bind here....
E
0 Kudos
9 Replies
__Rich_
Occasional Contributor III
Presumably you could do what you want with with AGS, - 'web editing' implemented through a Feature Service, assuming you have a license > Basic?

Is that what you're after?
0 Kudos
evanpicard
New Contributor II
Presumably you could do what you want with with AGS, - 'web editing' implemented through a Feature Service, assuming you have a license > Basic?

Is that what you're after?


Yes, precisely.  I have AGS.  Just trying to figure out the nitty gritty.
0 Kudos
__Rich_
Occasional Contributor III
I know you have already written code to enable drawing and capturing of features etc. but could the Editor widget be of any use?

Have a look at this sample:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/ed_default_editingwidget.html
0 Kudos
evanpicard
New Contributor II
I know you have already written code to enable drawing and capturing of features etc. but could the Editor widget be of any use?

Have a look at this sample:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/ed_default_editingwidget.html


Yes, thats what I'm using, but I can't figure out how to get my selection of zipcodes, copied into new empty Featurelayer.
No editor tools ever "appear" in the tool bar.
Hint?

2 other issues -
1. from the sample -
  <body class="claro">
    <div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline',gutters:false" style="width:100%; height:100%;">
      <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'right'">
      </div> 
      <div data-dojo-type="dijit.layout.ContentPane" id="templatePickerPane" data-dojo-props="region:'left'">
        <div id="panelHeader">
          Default Editor
        </div>
        <div style="padding:10px;" id="editorDiv">
        </div>
      </div>
    </div>
  </body>

I get the editor below my map window. 
I can't get the editor window on the left, and the map on the right, no idea why.

2.  After I draw my polygon, and it queries the layer, the map zooms again, but I never coded that.  Any ideas why?


Thanks all.
E
0 Kudos
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
So you have Layer "A", and you want to copy a selection of features to Layer "B", is that correct?  And, you have a graphics layer holding all of your selected features, right? (selectedZipGraphic).

What you could do is  store all of your graphics in an array (they might already be in one by default) and  then "ADD" them to Layer "B".  Check out FeatureLayer.applyedits(adds?, updates?, deletes?, Callback?, errback?);
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/featurelayer.htm#apply...

You'll only need to call the "Adds" parameter and essentially Add each of the graphics..
0 Kudos
BenFousek
Occasional Contributor III

I'd like to save these selections in the database, if possible.

MySQl and PHP is an easy way to save graphics, maps, bookmarks, notes and more. I've tried SQL and .net, but it seemed like 10x the work with poorer results. The api is great because it allows you to create json from DOM objects, e.g. all the graphics on a specific graphics layer. For saving maps I create my own DOM object with all the map params, layer states, etc, and save it as plain text in MySQL via PHP. As a side note, my apps require the user to be logged in as to identify what belongs to who. An admin account can view everything.
------------------------------------
app.map._layers.gl_measure.add(app.map._layers.gl_identify.graphics[0])

This is an easy way to copy a graphic to another gl. I did this on console's command line to copy the first graphic in my identify layer to my measure layer. You have to refresh the map to get it to display or it will show up after next zoom or pan.
0 Kudos
__Rich_
Occasional Contributor III
Am I being too simplistic in thinking the most straightforward way for the OP to save features that have been added client-side is to follow the bog standard editing roadmap?

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/inside_editing.htm

He has ArcGIS Server available, all he needs to do is setup a feature service, backed by an ArcSDE-managed geodatabase (compatible with several RDBMSs e.g. SQL Server) and use the Editor widget.

Seems to me that this way he gets everything he wants out-of-the-box with no server-side programming required...
0 Kudos
BenFousek
Occasional Contributor III
It's easy for me to say "mySQL and PHP" and you to say "SDE and feature service", but it's going to require some work server and client side either way. I know he wants to save graphics, but not his overall goal, e.g. is it spatial information or just user markup?

I've been saving graphics, maps, bookmarks, etc this way before the api had feature layers and native editing support. I will continue a use and advocate this approach as it fits my needs and is in my view the most expedient.

This isn't the first time I've seen questions about this sort of thing on the forums and in reality it's hard to give an quality answer to such a question. So I'm going to create a example for the code gallery where user graphics can be saved and retrieved using mySQL and PHP with all the code for download. Expect it by the end of October. I'll post in forum when finished.

@geos_rfleet If you're up for a little friendly competition do the same with feature layers and editor. 😉
0 Kudos
__Rich_
Occasional Contributor III
Easy for me to say ASP.NET + SQL Server or various other combinations of programming platform + RDBMS 😉  (I can't see how PHP + MySQL is any less or more work to be honest, anyway, I digress...)

Sounds like he doesn't want to get into any server-side programming, hence my suggestion for merely 'configuring' the server side stuff using ArcGIS Desktop (ArcSDE is part of desktop) to author the database/services etc. for you via a nice friendly *cough* GUI.

Rolling your own is fine who are comfortable with all the technologies involved at each tier and definitely required if the software provide doesn't do what you want off the shelf and you can't buy in something to fill the gap.  Once the software 'catches up' with you then you can always re-evaluate whether to ditch the proprietary approach and migrate to the stock components.

Interoperability with other people's systems might be a consideration too e.g. the OP mentions a "central office" that needs to see what the users have created - what tools do the people at "central office" use?
How much effort would it be for the OP to expose any standard interfaces either public (like the OGC specs) or proprietary like ArcGIS Server via a home-grown solution?

All I'm trying to do is present the OP with options then he can make a more informed choice appropriate to his skill set etc.

Not much point in me providing an example of how to save edits back to a database through a feature service when there's already examples available, something about wheels and re-inventing them 🙂  (though I am envious if you have spare time to spend creating your sample!)

We can all (ok, maybe not all!) write custom software either simple or complex and make it stand on its head, it's choosing the right horse for the right course, of course 😉

Suggest we let the OP digest the information and come back if he needs anything further...
0 Kudos