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)
Change History (11)
by , 6 years ago
Attachment: | ESP_adm0.shp added |
---|
by , 6 years ago
Attachment: | ESP_adm0.shx added |
---|
follow-up: 2 comment:1 by , 6 years ago
by , 6 years ago
Attachment: | ESP_adm0.prj added |
---|
by , 6 years ago
Attachment: | ESP_adm0.dbf added |
---|
comment:2 by , 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 , 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
comment:5 by , 6 years ago
Milestone: | PostGIS PostgreSQL → PostGIS 2.4.5 |
---|
comment:6 by , 6 years ago
Milestone: | PostGIS 2.4.5 → PostGIS 2.4.6 |
---|
comment:7 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I am no longer observing this since applying the fix for #4223. Closing.
Can you share WKB of both geographies?
Is 242 km an incorrect result? It sounds like the country-scale distance.