Answer the question
In order to leave comments, you need to log in
How to find a region by latitude and longitude?
I have the coordinate of the user's location and I need to find out which region of the Russian Federation this point belongs to. What is the easiest way to do this?
Plus, I need to tighten the logic depending on the region. That is, I will have a table in the database with all the regions, and for each additional info, which I will use later.
I looked at Yandex api: in principle, I found AdministrativeAreaName in the response of the geocoder. It looks like, but I’m not sure that it will always work, plus I don’t quite understand how I can compare with the table: I need to get all possible AdministrativeAreaName options to compare with a column in the table ... They advised me
to look in the direction of OpenStreetMaps, but stopped at the fact that pear install http_request2 did not installed on homestead, on which I have a project, and this dependency is neededhttps://github.com/pear/Services_Openstreetmap/
In general, I don’t quite know which way to dig: to be fast, without crap and correctly :)
Answer the question
In order to leave comments, you need to log in
1. Download local.osm.pbf from gis-lab
2. Extract boundaries:
mkdump:
osmosis \
--rb file=local.osm.pbf \
--tf accept-relations boundary=administrative --uw --un \
outPipe.0=rels \
\
--rb file=local.osm.pbf \
--tf accept-ways boundary=administrative --un \
outPipe.0=ways \
\
--merge \
inPipe.0=rels \
inPipe.1=ways \
\
--wb file=local-bounds.osm.pbf
node,way name:ru text linear
node,way name:en text linear
node,way alt_name text linear
node,way alt_name:ru text linear
node,way official_name text linear
node,way admin_level text linear
node,way boundary text linear
node,way name text linear
node,way ref text linear
node,way place text linear
local=> select osm_id,name,boundary,admin_level from (select ST_Transform(ST_SetSRID(ST_MakePoint(37.6,55.6),4326),3857) as point) a,adm_polygon b where a.point && b.way and ST_Within(a.point,b.way) and boundary='administrative' order by admin_level::INT asc;
osm_id | name | boundary | admin_level
----------+-------------------------------+----------------+-------------
-1029256 | Центральный федеральный округ | administrative | 3
-102269 | Москва | administrative | 4
-1282181 | Южный административный округ | administrative | 5
-950664 | район Чертаново Южное | administrative | 8
(4 rows)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question