Skip to content

Instantly share code, notes, and snippets.

@CrazyLionHeart
Created June 19, 2013 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrazyLionHeart/5813733 to your computer and use it in GitHub Desktop.
Save CrazyLionHeart/5813733 to your computer and use it in GitHub Desktop.
Поиск полигона улицы с домом внутри Москвы или Московской области по Openstreet Map
SELECT search_street.way, format('%s, %s, %s', mo_m.fullname, all_other.fullname, search_street.fullname) as fullname
FROM
(
SELECT way, name as fullname
FROM planet_osm_polygon
WHERE admin_level = '4' AND (name = 'Москва' OR name = 'Московская область')
AND boundary = 'administrative'
) as mo_m
INNER JOIN
(
SELECT way, name as fullname
FROM planet_osm_polygon
WHERE admin_level = ANY ('{6, 8, 9, 10}'::text[])
AND boundary = 'administrative'
) as all_other ON (all_other.way @ mo_m.way)
INNER JOIN
(
SELECT
way, format('%s, %s', "addr:street", "addr:housenumber") as fullname
FROM planet_osm_polygon
WHERE
to_tsvector("addr:street") @@ to_tsquery('russian', 'Анадырский')
AND to_tsvector('russian', "addr:housenumber") @@ to_tsquery('russian', '63')
ORDER BY way
) as search_street ON (ST_ContainsProperly(all_other.way, search_street.way))
WHERE
ST_ContainsProperly(mo_m.way, search_street.way)
ORDER BY search_street.way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment