1

I'm trying to use the data that is retuned from the nomatim API to perform a simple geospatial search. The users search for a place, i.e Leeds, and this returns simple info, including the following bounding box:

"boundingbox": [
      "53.6983747",
      "53.9458558",
      "-1.8004213",
      "-1.2903452"
 ],

Using this, I should be able to create a bounding box using the Postgis function:

geometry ST_MakeEnvelope(double precision xmin, double precision ymin, double precision xmax, double precision ymax, integer srid=unknown);

However, when I do this, I am unable to get correct geometries that I can then use, and plug into another function wherein I check if a point is within that geometry.

As far as I can tell, the SRID for the OSM data is 3857. When I perform the following:

ST_MakeEnvelope(53.6983747,-1.8004213,53.9458558,-1.2903452, 3857);

And then perform a search on this, I have to add 500000 metres to the ST_DWithin to be able to get a point which is right in the centre.

Does anyone know If there is a better way to approach this, or spot any mistakes in this? I have tried a couple different approaches and I cannot find any more accurate than this one.

For reference, this is the search I've been performing:

Select * from geometries 
where ST_DWithin(ST_Transform(geom,27700),ST_Transform(ST_SetSRID(ST_MakePoint(1.546033, 53.798075),3857),27700), 70)

at 75 I get the Newcastle box, and at 80 I get the Leeds box, and that point is in Leeds. I am very confused.

  • 1
    Osm data are in EPSG:4326. – user30184 Nov 6 '17 at 21:06
  • 3857 is spherical mercator, as used by Google Maps to render tiles. Your coordinates are lat/long which is 4326, which is typically used for vector overlays, as it corresponds to what you get from a GPS anywhere on the globe, even GeordieLandia :-) – John Powell Nov 6 '17 at 21:06
  • I have changed over to 4326 - Thank you! but I still get issues with the geoms created by the envelopes – Allavae Nov 6 '17 at 21:27
  • Edit your question and describe your current issues. – user30184 Nov 7 '17 at 5:29
1

As already stated in the comments, SRID of OSM data must be 4326.
And then you're confusing x (=lon) and y (=lat).

OSM returns:

"boundingbox": [
      ymin,
      ymax,
      xmin,
      xmax
 ]

So your query must look like this:

ST_MakeEnvelope(-1.8004213,53.6983747,-1.2903452,53.9458558, 4326);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.