Can you point me to an example or show me some code demonstrating the best way to combine 2 shape files into 1?
Combine shape files
Hi Taylor,
Before combining shape files, please make sure the two shape files are under the same shape type like polygon,linestring etc…
Some codes like the below and hope it helps:
LayerOverlay overlay = wpfMap1.Overlays["mapOverlay"] as LayerOverlay;
ShapeFileFeatureLayer file1Layer = overlay.Layers["file1"] as ShapeFileFeatureLayer;
ShapeFileFeatureLayer file2Layer = overlay.Layers["file2"] as ShapeFileFeatureLayer;
file1Layer.Open();
var rectangleAllFeatures = file1Layer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
file1Layer.Close();
file2Layer.Open();
var ringAllFeatures = file2Layer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
file2Layer.Close();
ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, @"…\Data\result.shp", new DbfColumn[] { new DbfColumn("Name", DbfColumnType.String, 100, 0) });
ShapeFileFeatureLayer resultLayer = new ShapeFileFeatureLayer(@"…\Data\result.shp", ShapeFileReadWriteMode.ReadWrite);
resultLayer.Open();
resultLayer.FeatureSource.BeginTransaction();
int id = 1;
foreach (Feature item in rectangleAllFeatures)
{
resultLayer.FeatureSource.AddFeature(new Feature(item.GetShape().GetWellKnownText(), id.ToString(), item.ColumnValues));
id++;
}
foreach (Feature item in ringAllFeatures)
{
resultLayer.FeatureSource.AddFeature(new Feature(item.GetShape().GetWellKnownText(), id.ToString(), item.ColumnValues));
id++;
}
resultLayer.FeatureSource.CommitTransaction();
resultLayer.Close();
Regards,
Johnny