Opened 6 years ago

Closed 6 years ago

#4159 closed defect (fixed)

ST_Distance failing with a geography and a point with specific values

Reported by: GustavoAcid Owned by: pramsey
Priority: medium Milestone: PostGIS 2.4.6
Component: postgis Version: 2.2.x
Keywords: ST_Distance Cc:

Description

In our project we are loading geographies from different countries from shapefiles to Postgis (using shp2pgsql) and later querying if specific points are within some distance from said geographies.

The problem arose when we made the query if this specific coordenates (-3.6765233, 40.5036783) are inside the Spanish territory (shapefile used attached). The point is in the center of Madrid, but ST_Distance between the geography and the points gives 242445.14066125 as result.

Query Used

SELECT ST_Distance(regions.area, ST_SetSRID(ST_Point(-3.6765233, 40.5036783), 4326)::geography) as result
     FROM regions 
     WHERE id = 1;

Attachments (4)

ESP_adm0.shp (3.7 MB ) - added by GustavoAcid 6 years ago.
ESP_adm0.shx (108 bytes ) - added by GustavoAcid 6 years ago.
ESP_adm0.prj (145 bytes ) - added by GustavoAcid 6 years ago.
ESP_adm0.dbf (5.6 KB ) - added by GustavoAcid 6 years ago.

Change History (11)

by GustavoAcid, 6 years ago

Attachment: ESP_adm0.shp added

by GustavoAcid, 6 years ago

Attachment: ESP_adm0.shx added

comment:1 by komzpa, 6 years ago

Can you share WKB of both geographies?

Is 242 km an incorrect result? It sounds like the country-scale distance.

by GustavoAcid, 6 years ago

Attachment: ESP_adm0.prj added

by GustavoAcid, 6 years ago

Attachment: ESP_adm0.dbf added

in reply to:  1 comment:2 by GustavoAcid, 6 years ago

Replying to komzpa:

Can you share WKB of both geographies?

I'm kind of new with Spatial Data, how can I retrieve the WKB of both geographies?

Is 242 km an incorrect result? It sounds like the country-scale distance.

Yes, it is incorrect. The point is in the center of the first Geography. If I do the same query with (-3.6765233, 40.5036783) the result is 0 as expected.

comment:3 by GustavoAcid, 6 years ago

WKB generated using ST_AsBinary:

Point:

SELECT ST_AsBinary(ST_SetSRID(ST_Point(-3.6765233, 40.5036783), 4326)::geography);
                 st_asbinary
----------------------------------------------
\x010100000021db430c85690dc0391ad18778404440 

Spain Geography: https://drive.google.com/file/d/10KzfU3mCr2Rp5ORMMNnLjxBWzYleVug9/view?usp=sharing

Last edited 6 years ago by GustavoAcid (previous) (diff)

comment:4 by pramsey, 6 years ago

Hm, problem is gone at 2.5, but is there at 2.4.

comment:5 by pramsey, 6 years ago

Milestone: PostGIS PostgreSQLPostGIS 2.4.5

comment:6 by pramsey, 6 years ago

Milestone: PostGIS 2.4.5PostGIS 2.4.6

comment:7 by pramsey, 6 years ago

Resolution: fixed
Status: newclosed

I am no longer observing this since applying the fix for #4223. Closing.

Note: See TracTickets for help on using tickets.