I have a big list of locations with their coordinates in a city that is fully divided by a river that's running from north to south. Now I want to determine for each location if it is located east or west of that river. If it was possible to get the coordinates of the river in a granular enough manner, I could achieve that goal by comparing coordinates between location and the river. I have not found a way to get these coordinates so far. I'm new to OSM, however, and would be thrilled if someone could point me in the right direction here. asked 18 Feb '21, 14:55 RedAlakazam |
If you use osm2pgsql to load the OSM data into PostGIS database (based on postsql) then you can use use the ST_closestpoint() function to find the closest point on a way (your river) to a point. You can then take the two points (one on the river and the one you are interested in) and use the ST_Azimuth() function to determine the direction of travel between the two points. If the the river is serpentine you may get a result other than what you wish for (if the point is within a loop or near a curve in the river the azimuth could be quite different than you want). I don’t have enough experience with this stuff to suggest a way around that issue though. answered 19 Feb '21, 02:24 n76 |
Another computational option would be: 1. Create polygon around whole city. 2. Get river geometry as a line. 3. split polygon in two along that line. 4. for every point, ask "is this point in the left-land polygon", if not it'll be on the right. If I understand the question correctly, the main issue is extracting the river's coordinates. This could potentially be done in PostGIS if the data is loaded (something along the lines of answered 19 Feb '21, 15:11 Frederik Ramm ♦ |
I ended up using @stf's suggestion of using the ST_AZIMUTH() function.
Making the left/right distinction at 180 degrees worked out perfectly in this case. @Frederik Ramm's suggestion of splitting the map in two using the river would've lead to a more robust solution but the river had some arms with the same name which made it inconvenient in my case. answered 22 Feb '21, 18:21 RedAlakazam |