Closed richardthombs closed 3 years ago
@richardthombs I haven't looked at your repro yet, but do you maybe need to use geography
on PostGIS? Take a look at the PostGIS docs to understand the difference between geometry and geography.
@roji Thanks for the fast reply. Do you happen to know how I can coerce EF Core into using the Geography type with Npgsql?
Ah, think I see it: https://www.npgsql.org/efcore/mapping/nts.html#geography-geodetic-support
So basically I have to add this in OnModelCreating
:
if (Database.IsNpgsql()) builder.Entity<Place>().Property(x => x.Point).HasColumnType("geography (point)");
It would be very helpful if there was a global configuration option to switch the type translation to do this by default.
I guess I will close this and open a feature request instead :)
Thanks for your help @roji
I can't believe that something like this is really a bug, more likely it is my inadequate understanding of Postgres / PostGIS and NetTopologySuite.
TDLR: I am puzzled why this example code gives the correct distances when using
.UseSqlServer
but very different values when theDbContext
is created using.UseNpgSql
instead.Repo with a repro: richardthombs/spatial-test
For the SQL Server tests, I used SQL Server Express 14.0.1000.
For the Postgres tests, I used the postgis/postgis docker container launched as follows:
The test
Using this
Place
class:I create 3 instances
Then query the distance from a point:
I do this for SQL Server and for Postgres and get very different distances:
SQL Server seems to be in meters, but I have no clue what is going on with Postgres!