Shape file Editing

223
1
08-01-2018 02:20 AM
Siva_SankaraReddy_T
New Contributor II

Hi,

 I create the Line shape file in arc map. is it possible for  Edit this Shape file in ArcGIS Runtime for .Net.

Tags (1)
0 Kudos
1 Reply
RichZwaap
Occasional Contributor III

Yes, this is possible using ShapeFileFeatureTable.  You can use the AddFeatureAsync (or AddFeaturesAsync) method to add new features, UpdateFeatureAsync (or UpdateFeaturesAsync) to update existing features, or DeleteFeatureAsync (or DeleteFeaturesAsync) to delete existing features.

Here's a quick example of adding new features:

// Create the shapefile table, specifying the path to the shapefile
var shapefile = new ShapefileFeatureTable(filePath);

// The shapefile must be loaded to perform operations on it
await shapefile.LoadAsync();

// Create the feature, specyfing the new feature's attributes and geometry
var feature = shapefile.CreateFeature(attributes, geometry);

// Add the newly created feature to the shapefile
await shapefile.AddFeatureAsync(feature);‍‍‍‍‍‍‍‍‍‍‍

And editing existing features:

// Create the shapefile table, specifying the path to the shapefile
var shapefile = new ShapefileFeatureTable(filePath);

// The shapefile must be loaded to perform operations on it
await shapefile.LoadAsync();

// Create the feature, specyfing the new feature's attributes and geometry
var feature = shapefile.CreateFeature(attributes, geometry);

// Add the newly created feature to the shapefile
await shapefile.AddFeatureAsync(feature);‍‍‍‍‍‍‍‍‍‍‍

// Query the shapefile to retrieve the feature or features to edit.  The query
// parameters can specify object IDs, attribute values, search geometries, and more
var queryResult = await shapefile.QueryFeaturesAsync(queryParameters);

// For this example, just get the first feature from the result
var feature = queryResult.First();

// Update the feature's geometry
feature.Geometry = newGeometry;

// Update attribute values.  Note that the type of the new value must match the type
// of the attribute field being updated (e.g. string, integer, date/time, etc)
feature.Attributes["SomeStringFieldName"] = "New attribute value!";
feature.Attributes["SomeDateFieldName"] = DateTimeOffset.UtcNow;

// Apply the edits to the shapefile
await shapefile.UpdateFeatureAsync(feature);
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope this helps.

0 Kudos