NetTopologySuite / NetTopologySuite.IO.Esri

BSD 3-Clause "New" or "Revised" License
31 stars 16 forks source link

Cannot Write Shapefile with LineStrings using ShapefileWriter #34

Closed jjm-ms2soft closed 2 weeks ago

jjm-ms2soft commented 10 months ago

I'm trying to write a shapefile that may contain a mix of LineStrings and MultiLineStrings. I'm getting the writer like so:

var options = new ShapefileWriterOptions(ShapeType.PolyLine, fields)
{
    Projection = GeographicCoordinateSystem.WGS84.WKT
};
using var writer = Shapefile.OpenWrite(shpPath, options);

... code to create DbfFields and set geometry

writer.Write();

When I try to write the file I get a "Cannot cast LineString to MultiLineString" error stemming from the ShapefileWriter class. The override of the Geometry property is trying to cast the Geometry to T.

The Shapefile.OpenWrite() method will return a PolyLineWriter. The PolyLineWriter is a ShapeFileWriter. Hence the error when trying to write a LineString.

If I use Features (as opposed to directly constructing DbfFields) and use writer.Write(Features) it works because Write(Feature) will turn the LineString into a MultiLineString for me in ShpPolyLineWriter.GetShapeGeometry().

But features don't handle null values, due to the issue described in "Null value" (can't determine type). It would be nice if either features handled null values, or writer.Write() could handle LineStrings.

KubaSzostak commented 6 months ago

Thank you @jjm-ms2soft for for submitting this issue. Unfortunately, we are unable to investigate further without additional information. If you are still interested in fixing this issue please provide code to create DbfFields and set geometry. Without the code it will be hard to narrow down the issue.

KubaSzostak commented 2 weeks ago

We have requested more information regarding this issue, but have not received a response or additional information regarding this issue. Therefore, we are closing this issue. Please feel free to reopen it if you are able to provide the necessary details.