I have a shapefile that contains MultilineShapes. I need to edit the geometry, and I could not find an example of how to do this.
Thank you.
Elisa
I have a shapefile that contains MultilineShapes. I need to edit the geometry, and I could not find an example of how to do this.
Thank you.
Elisa
There are two parts to what you are trying to accomplish.
-First, there is the editing of the shapefile where you want to update a the geometry of a feature. I can show you a few lines of code for doing that.
-Second, there is the interaction with the geometry of the feature that can be manipulated using EditInteractionOverlay or TrackInteractiveOverlay and there are different Code Community samples that show some examples of what can be done. For example, tracking a line, dragging a vertex of a line, snapping a vertex etc. See the Code Community samples:
wiki.thinkgeo.com/wiki/Map_Suite_De...ys_Samples
What part do you need most guiding on?
Val:
I need assistance with the first part. I have been to accomplish this using the following step,
but there has to be an easier way:
get the feature
get the feature’s id
get all the column name and column values for feature
get feature’s geometry
delete feature
close shapefile
rebuild shapefile’s index
open shapefile
edit geometry
set geometry’s id to store id value from feature
create new feature from geometry
add new feature with stored column names,values (dictionary) to shapefile
close shapefile
rebuild shapefile index
Thanks
Elisa
Elisa,
Thanks for your post and questions.
Following code snippet shows you how to extract a feature (or features) from one existing shape file and make it editable, I hope I do not make any misunderstanding of your questions.
ShapeFileFeatureLayer shapeFileFetureLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer("AustinStreetsShapeLayer");
shapeFileFetureLayer.Open();
Feature feature = shapeFileFetureLayer.QueryTools.GetFeatureById("5164", ReturningColumnsType.AllColumns);
shapeFileFetureLayer.Close();
winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature);
winformsMap1.EditOverlay.CalculateAllControlPoints();
winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
winformsMap1.Refresh(winformsMap1.EditOverlay);
Any more questions please feel free to let me know.
Thanks.
Yale
Yale:
I am still confused. I simply need to replace the vertices of a multiline shape. From your sample I do not understand how to update the shapefile with the new geometry. In the example below I a flipping the vertices of the line. I was hoping to find a way to do this without having to delete
the original line, update the shapefile index, and then add the new line. I simply want to replace the line’s geometry with the updated geometry:
roads.Open();
Feature feature = shapeFileFetureLayer.QueryTools.GetFeatureById(“5164”, ReturningColumnsType.AllColumns);
Collection<FeatureSourceColumn> cols = roads.FeatureSource.GetColumns();
Dictionary<string, string> values1 = new Dictionary<string, string>();
for (int v = 0; v < cols.Count; v++)
{
values1.Add(cols[v].ColumnName, feature].ColumnValues[cols[v].ColumnName].Trim());
}
MultilineShape lineshape2 = (MultilineShape)(features.GetShape());
Collection<LineShape> lines = lineshape2.Lines;
Collection<LineShape> lines_rev = lineshape2.Lines;
MultilineShape lineshape_rev = new MultilineShape(lines_rev);
string id = features.Id;
roads.FeatureSource.BeginTransaction();
roads.FeatureSource.DeleteFeature(id);
roads.FeatureSource.CommitTransaction();
roads.Close();
ShapeFileFeatureLayer.Rebuild(“c:\working\roads.shp”);
roads.Open();
lineshape_rev.Id = id;
Feature newfeature = new Feature(lineshape_rev);
roads.FeatureSource.BeginTransaction();
roads.FeatureSource.AddFeature(newfeature.GetShape(), values1);
roads.FeatureSource.CommitTransaction();
roads.Close();
ShapeFileFeatureLayer.Rebuild(“c:\working\roads.shp”);
I tried doing this without the delete/rebuild index, but I could not get it to save the changes to the geometry.
I will be doing this procedure as a batch of about 2000 lines in a 365,000 line file. The only way I see to do this is to
save all of the new features and their values to arrays, delete all of the originals, rebuild the index, and then add in
the updates and rebuild again, but this seems like overkill and time restrictive.
Elisa
Elisa
Yale:
I am sorry, I forgot to include the code to reverse the line:
lines_rev[0].ReversePoints();
To give you another example, see the code below where I get all the features based on a column value, start the edit, loop thru all the features and change the geometry of the MultiLineShapes reversing the LineShapes. I think it will give you another idea of how things can be done:
layer1.Open();
layer1.FeatureSource.BeginTransaction();
Collection<Feature> features = layer1.FeatureSource.GetFeaturesByColumnValue("FENAME", "Bunny", ReturningColumnsType.AllColumns);
foreach (Feature feature in features)
{
//Gets the MultilineShape and reverse each of its LineShapes
MultilineShape newMultiLineShape = (MultilineShape)feature.GetShape();
foreach (LineShape lineShape in newMultiLineShape.Lines)
{
lineShape.ReversePoints();
}
//Sets the Id of the MultilineShape the same as the feature
newMultiLineShape.Id = feature.Id;
//Updates the feature with the new geometry.
layer1.FeatureSource.UpdateFeature(newMultiLineShape, feature.ColumnValues);
}
layer1.FeatureSource.CommitTransaction();
layer1.Close();