PostGis IO module for NTS.
Branch | Status |
---|---|
develop | |
master |
Stable releases are hosted on the default NuGet feed. You can install them using the following command on the package manager command line
PM> Install-Package NetTopologySuite.IO.PostGis
PostGis IO module for NTS.
License: BSD 3-Clause "New" or "Revised" License
PostGis IO module for NTS.
Branch | Status |
---|---|
develop | |
master |
Stable releases are hosted on the default NuGet feed. You can install them using the following command on the package manager command line
PM> Install-Package NetTopologySuite.IO.PostGis
Could be significantly more efficient than the default?
Since creating this repository and now there have been considerable changes in the develop branch:
Hi,
the version 2.1.0 introduced this issue: all XY geometries are stored in postgis as XYZ geometries, with NaN value in Z.
Example: I store POINT(0 0)
using Npgsql and NTS.
Using NetTopologySuite.IO.PostGis v2.0.0, postgis' st_ndims
returns: 2
and st_astext
returns: POINT (0 0)
Using NetTopologySuite.IO.PostGis v2.1.0, postgis' st_ndims
returns: 3
and st_astext
returns: POINT Z (0 0 -1.#IND)
-1.#IND
is a NaN
representation in Windows https://stackoverflow.com/a/347940.
I'm using:
Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite
5.0.7 (and later)PostgreSQL 11.11, compiled by Visual C++ build 1800, 64-bit
managed in Azure as Single ServerPOSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="110" GEOS="3.7.0-CAPI-1.11.0 3.7.1" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.4, released 2018/03/19 GDAL_DATA not found" LIBXML="2.7.8" LIBJSON="0.12" LIBPROTOBUF="1.2.1" RASTER
How to reproduce the issue:
NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite();
using NpgsqlConnection conn = new(connectionString);
conn.Open();
using (var cmd = new NpgsqlCommand(@"
CREATE TEMP TABLE test
(
geometry geometry,
CONSTRAINT enforce_dims CHECK (st_ndims(geometry) = 2)
)", conn))
{
cmd.ExecuteNonQuery();
}
using (var cmd = new NpgsqlCommand("INSERT INTO test (geometry) VALUES (@g)", conn))
{
cmd.Parameters.AddWithValue("@g", new WKTReader().Read("POINT(0 0)"));
cmd.ExecuteNonQuery();
}
The above code works in net6.0 with Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite
5.0.5 (using NetTopologySuite.IO.PostGis
2.0.0). Using the next version 5.0.7 (using NetTopologySuite.IO.PostGis
2.1.0) it throws Npgsql.PostgresException with the message 23514: new row for relation "test" violates check constraint "enforce_dims"
.
The PostGisReader is smart enougth to see the Z coordinate is NaN, returning a 2 dimensional coordinate.
I think the issue has been introduced with the following commit:
ddd394c#diff-b1018343089a37cb228d0c3357039b782d592ad2591204f0d4c6d41089d1ecf8L585
Version 2.1.0 is:
if (sequence.HasZ)
version 2.0.0 was:
if (sequence.HasZ && !double.IsNaN(sequence.GetZ(0)))
Currently the PostGisWriter
emits SRID value for every child geometry in a multi-geometry.
This does not match Postgis ST_AsEWKB output for these geometries.
This might not be an issue, but it is different.
In #5 I addressed a problem with ordinates handling, but the issue seems wider, so I'm opening a discussion here.
Both PostGisWriter and PostGisReader have a HandleOrdinates property on them. These properties determine the ordinates sent and received,
In effect, there seems to be no way to simply send or receive a point, with all its ordinates (and nothing but its ordinates): the user must currently set the ordinates manually on the writer and reader beforehand. Aside from being odd and unnecessary, this makes it awkward to work in situations where geometry objects of varying ordinates are used: writing both 2D and 3D points involves having two writers and two readers (or constantly changing the ordinates properties on them).
Here's a proposal for a new behavior:
Ordinates.None
would mean that the reader/writer have no particular setting, and would always simply pass through the object as-is, without adding or removing anything.Ordinates.None
would become the default behavior for PostGisWriter and PostGisReader.Note that the Ordinates.None
behavior is already somewhat present in PostGisWriter, but is disabled as described in #6.
If this is accepted, I'll submit a PR for the changes including tests.
Would you guys be open to a PR bringing this up-to-date to modern C# standards? A while back the question was raised with regards to NTS itself - which tracks JTS - but unless I'm mistaken the IO modules don't track anything and should be more free?
To improve an overall performance of an app it makes sense to use async IO since it's not blocking and allows to process data in background and prevent the pooled thread from being blocked. The only blocker here is that BinaryReader
has no async methods and all logic should be rewritten, but to avoid repeating internals and bringing errors to the existing code there is System.IO.Pipelines
.
When writing:
XX000: WKB structure does not match expected size!
Data:
Severity: ERROR
InvariantSeverity: ERROR
SqlState: XX000
MessageText: WKB structure does not match expected size!
File: lwgeom_pg.c
Line: 250
Routine: pg_error
Originally flagged in npgsql/npgsql#3467
We are updating our EF Core provider to version 3.0, but we handle geometry in the driver plugin using this library. How should we update our NTS driver plugin to support version 2.0 and use it for EFCore.PG 3.0? I have found no preview package version 2.0 of NetTopologySuite.IO.PostGis on NuGet. If you're not going to support it anymore, we will all required stuff in out library.
/cc @roji
Setup an automated build similar to the NTS core.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.