NetTopologySuite / NetTopologySuite.IO.ShapeFile

The ShapeFile IO module for NTS.
35 stars 25 forks source link

ShapefileDataWriter can't save MulitPoint geometry #24

Closed sweco-sedahd closed 4 years ago

sweco-sedahd commented 5 years ago

This example: var geomFactory = new GeometryFactory();

var features = new List<IFeature>();
var attrTbl = new AttributesTable();
attrTbl.Add("Id", 10);
var coordinates = new Coordinate[2];
coordinates[0] = new Coordinate(123.0, 023.0);
coordinates[1] = new Coordinate(123.0, 100.0);
var mPoint = geomFactory.CreateMultiPointFromCoords(coordinates);
var ft = new Feature(mPoint, attrTbl);
features.Add(ft);

var shpWriter = new ShapefileDataWriter("outShape.shp", geomFactory);
var header = ShapefileDataWriter.GetHeader(features[0], features.Count);
shpWriter.Header = header;
shpWriter.Write(features);

Failes int the last Write call with exception: System.ArgumentException: Expected geometry that implements 'IPoint', but was 'MultiPoint'

This is because the call from Write to Shapefile.GetShapeType() with the first geometry returns PointZM bacause the call to GetNonEmptyGeometry uses GetGeometryN() to get the first point in the mulitpoint and returns it.

The function GetNonEmptyGeometry() could return the geometry itself if it is not null in this case or maby Shapefile.GetShapeType() could not use it to filter geometry.

cbodonnell commented 4 years ago

Any updates on this issue?

cbodonnell commented 4 years ago

Any updates on this issue?

I opted to get around this issue by including multiple Point features in my List instead of one MultiPoint feature.

DGuidi commented 4 years ago

should be ok now