Hi Brian,
I have made two simple samples using that both two ways you mentioned above. The first way we can use ValueStyle, and the second way I show a simple sample just generate a part shapefile from the original shapefile to show you how to split one large shapefile to some small ones. Following is the code snippet:
1. Set ValueStyle based upon a feature column value.
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
ShapeFileFeatureLayer landlockedCountryLayer = new ShapeFileFeatureLayer(@"..\SampleData\Data\Countries02.shp");
landlockedCountryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
// Draw features based on values
ValueStyle valueStyle = new ValueStyle();
valueStyle.ColumnName = "LANDLOCKED";
valueStyle.ValueItems.Add(new ValueItem("Y", AreaStyles.Country1));
landlockedCountryLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
LayerOverlay worldOverlay = new LayerOverlay();
worldOverlay.Layers.Add("LandlockedCountryLayer", landlockedCountryLayer);
winformsMap1.Overlays.Add(worldOverlay);
winformsMap1.CurrentExtent = new RectangleShape(-255.234375, 180.678985595703, 255.234375, -187.055389404297);
winformsMap1.Refresh();
2. Split one shapefile and associated data into multiple shapefiles.
private void GenerateAPartShapeFile(string originalShapefilePath, string newShapefilePath)
{
ShapeFileFeatureLayer originalLayer = new ShapeFileFeatureLayer(originalShapefilePath);
ShapeFileFeatureLayer.BuildIndexFile(originalShapefilePath, BuildIndexMode.DoNotRebuild);
ShapeFileFeatureLayer.CloneShapeFileStructure(originalShapefilePath, newShapefilePath);
ShapeFileFeatureLayer landlockedCountryLayer = new ShapeFileFeatureLayer(newShapefilePath, ShapeFileReadWriteMode.ReadWrite);
UpdateNewShapeFile(originalLayer, landlockedCountryLayer);
ShapeFileFeatureLayer.BuildRecordIdColumn(newShapefilePath, "RECID", BuildRecordIdMode.Rebuild);
}
private void UpdateNewShapeFile(ShapeFileFeatureLayer originalLayer, ShapeFileFeatureLayer newLayer)
{
newLayer.Open();
newLayer.EditTools.BeginTransaction();
originalLayer.Open();
Collection<Feature> features = originalLayer.FeatureSource.GetFeaturesByColumnValue("LANDLOCKED", "Y", ReturningColumnsType.AllColumns);
foreach (Feature feature in features)
{
newLayer.EditTools.Add(feature);
}
newLayer.EditTools.CommitTransaction();
originalLayer.Close();
newLayer.Close();
}
Because we don't have your data to test, so I can not test the performance to tell you which way is better, maybe you can test with your data to chose the appropriate one.:)
Thanks,
Any questions please let me know.
James