Creating New Feature From Geometry Object

723
1
06-25-2014 04:30 AM
DuncanRager
New Contributor
Greetings,

I'm interested in passing a geometry object with certain attributes to an exposed feature class for committed edits. Essentially, I want to manually create a new feature without the template pane or editor widget. The geometry and attributes are both pre-defined, and the user just needs to select one pair from a group and push an "Add to Geodatabase" button.

I'm reading through the documentation and I can't see a clear way to do this. I see that if I don't want the pane or widget, then I need to use a geometry service, but I don't see a "create feature" method, or something that accepts a geometry object or attributes.

Thanks for the help,

Colin
0 Kudos
1 Reply
DuncanRager
New Contributor
Figured things out so I figured I'd offer the pretty straight-forward solution here. Not sure why I couldn't find it to start, but simply put, you use the applyEdits() method on a feature layer, supplying it with a JSON formatted array of graphics/geometries and attributes.

Here's the code:

function showResults(featureSet) {
       
       // Clear prior graphics
       map.graphics.clear();
       
       // Assign symbology to selected features
       var parcelSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, 
           new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, 
           new dojo.Color([98, 194, 204]), 2), new dojo.Color([98, 194, 204, 0.5]));
           
       // Put result in array    
  var resultFeatures = featureSet.features;
 
  if (resultFeatures.length > 0) {
   
   // Empty out array for new features
   features = [];
  
   // Loop through each feature (here it's limited to one feature)
   for (var i=0, il=resultFeatures.length; i<1; i++) {
    
     var feature = resultFeatures;
     feature.setSymbol(parcelSymbol);

     var geometry = feature.geometry;
     var parcelGraphic = new esri.Graphic(geometry);
     var attr = {};
     parcelGraphic.setAttributes(attr);
     features.push(parcelGraphic);
    
   }
  }


Hope it helps,

Colin
0 Kudos