i have one shape file.for that shape file i want to add some more data.how to insert data into the existing shape file.
How to insert data into my existing shape file
Hi Raj,
Here is the code,
ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(@"");
layer.Open();
layer.FeatureSource.BeginTransaction();
layer.FeatureSource.AddFeature(feature1);
layer.FeatureSource.AddFeature(feature2);
layer.FeatureSource.AddFeature(feature3);
layer.FeatureSource.CommitTransaction();
Regards,
Edgar
LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"];
InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"];
foreach (Feature feature in Map1.EditOverlay.Features)
{
if (!shapeLayer.InternalFeatures.Contains(feature.Id))
{
shapeLayer.InternalFeatures.Add(feature.Id, feature);
ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer("D:/Map/SecurityGroups/Culvert.shp");
layer.Open();
layer.ReadWriteMode = ThinkGeo.MapSuite.Core.ShapeFileReadWriteMode.ReadWrite;
layer.FeatureSource.BeginTransaction();
layer.FeatureSource.AddFeature(feature);
layer.FeatureSource.CommitTransaction();
}
}
lIke this if i write code iam getting error in commit tranasaction() method like "Stream does not support writing."so please provide some sort of code to add new features to the existing shape file.so that i will get idea to implement in my project.
Hi Rajanikanth,
Can you check if the shape file's property is read-only? Also, please try changing the code to the one shown as following:
LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"];
InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"];
ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer("D:/Map/SecurityGroups/Culvert.shp");
layer.ReadWriteMode = ThinkGeo.MapSuite.Core.ShapeFileReadWriteMode.ReadWrite;
layer.Open();
layer.FeatureSource.BeginTransaction();
foreach (Feature feature in Map1.EditOverlay.Features)
{
if (!shapeLayer.InternalFeatures.Contains(feature.Id))
{
shapeLayer.InternalFeatures.Add(feature.Id, feature);
layer.FeatureSource.AddFeature(feature);
}
}
layer.FeatureSource.CommitTransaction();
If it still runs into error, could you give us a demo including the test data?
Thanks,
Johnny