You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have two datasets now: one is LineString data and the other is Polygon data. I added these two datasets to a FeatureCollection and tried to generate a shapefile using Shapefile.WriteAllFeatures. However, I encountered an error message saying "Invalid geometry type provided (Polygon). Expected: Multilinestring." I would like to know if this is because a FeatureCollection cannot contain different types of geometries. How can I solve this problem? Thank you.
code:
var ntsService = new NtsGeometryServices(new PrecisionModel(), 4326);
var wktReader = new WKTReader(ntsService);
var featureCollection = new List<IFeature>();
foreach (var item in wktArrays)
{
var geometry = wktReader.Read(item.Wkt);
foreach (var name in item.Attributes.GetNames())
{
if (item.Attributes.GetType(name) == typeof(object))
{
item.Attributes.DeleteAttribute(name);
}
}
var feature = new Feature { Geometry = geometry, Attributes = item.Attributes };
featureCollection.Add(feature);
}
var now = DateTime.Now;
var folderDate = now.ToString("yyyy") + now.ToString("MM") + now.ToString("dd") + now.ToString("HH")
+ now.ToString("mm") + now.ToString("ss");
var shapeFilePath = Path.Combine(App.WebHostEnvironment.ContentRootPath, Options.ShapeFilePath, fileName, folderDate);
if (!Directory.Exists(shapeFilePath))
{
Directory.CreateDirectory(shapeFilePath);
}
var savePath = Path.Combine(shapeFilePath, fileName);
Shapefile.WriteAllFeatures(featureCollection, savePath);
The text was updated successfully, but these errors were encountered:
Thank you @txpppp for your feedback. The issue isn't caused by FeatureCollection, it's a Shapefile limitation. As per specification:
All the non-Null shapes in a shapefile are required to be of the same shape type.
...
Currently, shapefiles are restricted to contain the same type of shape as specified above. In the future, shapefiles may be allowed to contain more than one shape type. If mixed shape types are implemented, the shape type field in the header will flag the file as such.
Hello, I have two datasets now: one is LineString data and the other is Polygon data. I added these two datasets to a FeatureCollection and tried to generate a shapefile using Shapefile.WriteAllFeatures. However, I encountered an error message saying "Invalid geometry type provided (Polygon). Expected: Multilinestring." I would like to know if this is because a FeatureCollection cannot contain different types of geometries. How can I solve this problem? Thank you.
code:
The text was updated successfully, but these errors were encountered: