tobinbradley/dirt-simple-postgis-http-api

Nearest Point

Closed this issue · 4 comments

First off like to thank you for this project.

Not sure if I am inputting things wrong but when I tried to get nearest point I get this

{
"statusCode": 500,
"code": "XX000",
"error": "Internal Server Error",
"message": "0 is an invalid target SRID"
}

This is my request URL http://127.0.0.1:3100/v1/nearest/ala_23/-171.7776728%2C-13.83859403%2C4326?geom_column=geom&columns=Name&limit=10

My SRID is 4326. Not sure why the target SRID is needed?

Where do I get version 3 please?

Thanks

When you loaded your data into Postgres you didn't specify the projection and the tool you were using wasn't able to figure it out, so PostGIS doesn't know what projection your data is in (hence the 0 SRID). The SRID passed to the route isn't a target SRID, it's telling the route the SRID of the input point, which allows your input point to be in a different projection than your table geometry, something we commonly see with local governments (tables in a local projection) and web apps (coordinates in lng/lat). In order to do that PostGIS has to know your table geometry's projection.

If you reload your data and specify the projection or set it explicitly via ST_SetSRID you should be fine. Assuming your table geometry is 4326, something like:

update ala_23 set geom = ST_SetSRID(geom, 4326);

The master branch is v3 (v1 and v2 are their own branches), so if you're using master you're already on version 3.

Hope that helps!

Thanks a bunch man. Really really appreciate the quick response. Yes will do that. I used the Shape2Postgres utility and I thought for sure I used 4326. WIll try soon again and let you know. Thanks.

No worries! You can confirm that's the problem via:

SELECT ST_SRID(geom) FROM ala_23 LIMIT 1;

If you get a 0, that's the problem. You can also check and see what the geometry_columns view thinks.

Yes its working for me now. Somehow it reset the SRID when I changed the mode on the import utility but I didn't catch it before so it was rest to 0. Perfect. Pretty amazing stuff. Was looking at using a geocoder but the nearest function does what I need. Will learn more of your solution and try to contribute where I can. Thanks a bunch man. Really appreciate it.