Open KubaSzostak opened 3 years ago
@kubaszostak , thanks for your valueable input, I assume your PR is ready for review?
Yes. It's ready for review.
Any update on this? It's been since Feb 2021.
Still curious if we have any update on this? @FObermaier what the next step to get this merged in?
not a big deal, but maybe we cah restore the original solution name NetTopologySuite.IO.Shapefile.sln
instead of NetTopologySuite.IO.Esri.sln
?
Thanks for the contribution. A totally minor issue: I see a lot of warnings and messages due to empty newline, whitespaces and unnecessary usings. some of then can be simply fixed using this default (I think) tool
@kubaszostak Just to let you know that this test (from #80) fails also with "ESRI" lib
/// <summary>
/// <see href="https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile/issues/70"/>
/// </summary>
[Test]
public void TestReadPolygonWithWrongShellOrientation()
{
/*
* The shell_bad_ccw.shp contains a single polygon, with:
* - a shell CCW-oriented (like a hole from ESRI specs
* - a hole CW-oriented (like a shell from ESRI specs)
*/
string filePath = Path.Combine(
CommonHelpers.TestShapefilesDirectory,
"shell_bad_ccw.shp");
Assert.That(File.Exists(filePath), Is.True);
var geoms = ShapefileReader.ReadAllGeometries(filePath);
Assert.That(geoms, Is.Not.Null);
Assert.That(geoms.Length, Is.EqualTo(1));
var geom = geoms[0];
Assert.That(geom, Is.Not.Null);
Assert.That(geom.IsValid, Is.True);
Assert.That(geom.NumGeometries, Is.EqualTo(1));
Assert.That(geom, Is.InstanceOf<Polygon>());
var poly = (Polygon)geom.GetGeometryN(0);
Assert.That(poly.Shell, Is.Not.Null);
Assert.That(poly.Holes, Is.Not.Null);
Assert.That(poly.Holes.Length, Is.EqualTo(1));
}
see also attached data shell_bad_ccw.zip.
There are two parts of library.
NetTopologySuite.IO.Esri.Core
andNetTopologySuite.IO.Esri
. The former provides forward-only readers and writers for Esri shapefiles. It is vanilla .NET Standard 2.0 library without any dependencies. The latter is is full featured NTS library. It provides unified access to shapefile triplet (SHP, SHX, DBF) through wrapping Core classes.Writing features to a shapefile
Reading features from a shapefile
Reading a SHP file geometries
Performance The core part of the library was designed with performance in mind. There is a lot of other optimizations, to name a few of them:
ShpCoordinates
.ShpShapeBuilder
which under the hood is a buffer with smart resizing capabilities.BinaryBuffer
class which avoids file I/O operations by reading/writing a whole shape record data at once instead of reading/writing every single coordinate one by one. Again - without resource costly memory realocating.BinaryBuffer
have also custom bit-converter functions with support for big-endian and little-endian byte order. It's implementation avoids realocating new byte[8] array again and again, any time you want to write single coordinate. This avoid bottleneck GC and much faster than BitConverter .Encoding
The .NET Framework supports a large number of character encodings and code pages. On the other hand, .NET Core only supports limited list of encodings. To retrieve an encoding that is present in the .NET Framework on the Windows desktop but not in .NET Core, you need to do the following:
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);