Hi,
In order to avoid packaging shape files with my saved projects, I am looking at reading shape files and converting them to feature layers before adding them to an overlay. That way, the saved project does not include any paths to the original shape file on the users system.
The code for this was pretty simple and the relevant bit is below. However, when I serialize the overlay, it plugs on for ages and I end up with a huge file. The test I did was using the Countries02.shp and another tiny shape file of 100kb. Both shape files are WGS-84 lat/long projection. The resultant saved file was 192 MB and it took 17 minutes to save the file!
Am I doing something wrong in the code below to cause the serialized output to be so huge? Perhaps the feature needs to be indexed prior to loading it to the overlay? If so, I'm not sure how to go about doing that.
Regards,
Damian
ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(fileName);
// ... do some intermediate processing on the shapefile to determine projection, etc.
// Now, convert the shapefile features into In Memory features.
InMemoryFeatureLayer featureLayer = new InMemoryFeatureLayer();
ExplorerHelper.SetStyleByWellKnownType(featureLayer);
featureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
// Add the column names to the FeatureLayer
Collection<FeatureSourceColumn> columnValues = layer.FeatureSource.GetColumns();
featureLayer.Open();
featureLayer.EditTools.BeginTransaction();
foreach (FeatureSourceColumn column in columnValues)
{
featureLayer.Columns.Add(new FeatureSourceColumn(column.ColumnName));
}
featureLayer.EditTools.CommitTransaction();
featureLayer.Close();
// Add each feature to the featurelayer
foreach (Feature feature in layer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns))
{
Feature tempFeature = new Feature();
switch (feature.GetWellKnownType())
{
case WellKnownType.GeometryCollection:
break;
case WellKnownType.Invalid:
break;
case WellKnownType.Line:
LineShape tempLine = new LineShape(feature.GetWellKnownText());
tempFeature = new Feature(tempLine, feature.ColumnValues);
break;
case WellKnownType.Multiline:
MultilineShape tempMLine = new MultilineShape(feature.GetWellKnownText());
tempFeature = new Feature(tempMLine, feature.ColumnValues);
break;
case WellKnownType.Multipoint:
MultipointShape tempMPoint = new MultipointShape(feature.GetWellKnownText());
tempFeature = new Feature(tempMPoint, feature.ColumnValues);
break;
case WellKnownType.Multipolygon:
MultipolygonShape tempMPoly = new MultipolygonShape(feature.GetWellKnownText());
tempFeature = new Feature(tempMPoly, feature.ColumnValues);
break;
case WellKnownType.Point:
PointShape tempPoint = new PointShape(feature.GetWellKnownText());
tempFeature = new Feature(tempPoint, feature.ColumnValues);
break;
case WellKnownType.Polygon:
PolygonShape tempPoly = new PolygonShape(feature.GetWellKnownText());
tempFeature = new Feature(tempPoly, feature.ColumnValues);
break;
default:
break;
}
featureLayer.Open();
featureLayer.EditTools.BeginTransaction();
featureLayer.FeatureSource.AddFeature(tempFeature);
featureLayer.EditTools.CommitTransaction();
featureLayer.Close();
layerOverlay.Layers.Add(layerName, featureLayer);
}