Last active
June 17, 2020 14:39
-
-
Save DavidMoraisFerreira/a739fe2f7ed5125d86644f0ce15fb6ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH osm_potential_addresses AS ( | |
SELECT osm_id, "addr:housenumber", "addr:street", "addr:postcode", "addr:city", "ref:caclr", "note", "note:caclr", "fixme", way | |
FROM planet_osm_polygon | |
WHERE building IS NOT NULL | |
AND "addr:housenumber" IS NOT NULL | |
AND "addr:street" IS NOT NULL | |
AND "addr:postcode" IS NOT NULL | |
AND "addr:city" IS NOT NULL | |
UNION SELECT osm_id, "addr:housenumber", "addr:street", "addr:postcode", "addr:city", "ref:caclr", "note", "note:caclr", "fixme", way | |
FROM planet_osm_point | |
WHERE building IS NOT NULL | |
AND "addr:housenumber" IS NOT NULL | |
AND "addr:street" IS NOT NULL | |
AND "addr:postcode" IS NOT NULL | |
AND "addr:city" IS NOT NULL | |
) | |
SELECT osm.*, caclr.id_caclr_bat, ST_DISTANCE(ST_CENTROID(osm.way), ST_TRANSFORM(caclr.geom, 3857)) AS dist, ST_TRANSFORM(caclr.geom, 3857) as caclr_geom, ST_AsText(ST_ShortestLine(ST_CENTROID(osm.way), ST_TRANSFORM(caclr.geom, 3857))) | |
FROM osm_potential_addresses osm, addresses caclr | |
WHERE osm."ref:caclr" IS NULL | |
AND osm."addr:housenumber" = caclr.numero | |
--AND osm."addr:housenumber" ~ '-' | |
AND osm."addr:city" = caclr.commune | |
AND osm."addr:postcode" = caclr.code_postal::text | |
AND osm."addr:street" = caclr.rue | |
ORDER BY dist DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment