Skip to content

Commit

Permalink
Merge pull request #16 from osm-bzh/vm_test
Browse files Browse the repository at this point in the history
No more materialized view for places and admin boundaries
  • Loading branch information
MaelREBOUX authored Apr 2, 2018
2 parents bc2b780 + 71274b3 commit 16076b4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 51 deletions.
44 changes: 0 additions & 44 deletions database/create_views.sql
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@


-- places
CREATE MATERIALIZED VIEW places AS
(SELECT
osm_id,
name,
COALESCE(tags -> 'name:fr'::text) as name_fr,
COALESCE(tags -> 'name:br'::text) as name_br, -- breton
COALESCE(tags -> 'name:eu'::text) as name_eu, -- basque
COALESCE(tags -> 'name:oc'::text) as name_oc, -- occitan
COALESCE(tags -> 'name:gsw'::text) as name_gsw, -- alsacien
COALESCE(tags -> 'name:ca'::text) as name_ca, -- catalan
COALESCE(tags -> 'name:co'::text) as name_co, -- corse
place as type,
admin_level,
COALESCE(tags->'is_capital'::text) as is_capital,
z_order,
population::integer as population,
way as geometry
FROM planet_osm_point
WHERE
place in ('country','state','region','county','city','town','village','hamlet','suburb','locality','isolated_dwelling')
-- keep only integer values for population
AND (population ~ '^\d+$' OR population IS NULL)
) ;


-- admin_places
-- see http://dba.stackexchange.com/questions/104943/osm2pgsql-select-relation-member-by-role
-- because planet_osm_rels.rels is not a hstore attribute
Expand Down Expand Up @@ -123,20 +96,3 @@ JOIN (
) x
USING(osm_id));



-- admin_boundaries
CREATE MATERIALIZED VIEW admin_boundaries AS
(
SELECT
b.way::geometry(LineString,3857) AS way,
admin_level::integer AS admin_level,
coalesce(b.tags->'maritime','no') AS maritime,
count(r.*)::integer AS nb,
string_agg(id::text,',') AS rels
FROM planet_osm_roads b
LEFT JOIN planet_osm_rels r ON (r.parts @> ARRAY[osm_id] AND r.members @> ARRAY['w' || osm_id] AND regexp_replace(r.tags::text,'[{}]',',') ~ format('(,admin_level,%s.*,boundary,administrative|,boundary,administrative.*,admin_level,%s,)',admin_level,admin_level))
WHERE boundary='administrative' AND admin_level IS NOT NULL
GROUP BY 1,2,3
);

2 changes: 0 additions & 2 deletions database/drop_views.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@

DROP MATERIALIZED VIEW admin_boundaries;
DROP MATERIALIZED VIEW admin_places;
DROP MATERIALIZED VIEW places;
28 changes: 27 additions & 1 deletion database/layers_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,20 @@ SELECT osm_id, way, aeroway AS type FROM planet_osm_line WHERE aeroway IN ('ap


-- admin_boundaries
SELECT row_number() over() AS id, * FROM admin_boundaries ORDER BY admin_level DESC
SELECT
row_number() over() AS id,
b.way::geometry(LineString,3857) AS way,
admin_level::integer AS admin_level,
coalesce(b.tags->'maritime','no') AS maritime,
count(r.*)::integer AS nb,
string_agg(id::text,',') AS rels
FROM planet_osm_roads b
LEFT JOIN planet_osm_rels r ON (r.parts @> ARRAY[osm_id] AND r.members @> ARRAY['w' || osm_id] AND regexp_replace(r.tags::text,'[{}]',',') ~ format('(,admin_level,%s.*,boundary,administrative|,boundary,administrative.*,admin_level,%s,)',admin_level,admin_level))
WHERE boundary='administrative' AND admin_level IS NOT NULL
GROUP BY 1,2,3
ORDER BY admin_level DESC

SELECT b.way::geometry(LineString,3857) AS way, admin_level::integer AS admin_level, coalesce(b.tags->'maritime','no') AS maritime, count(r.*)::integer AS nb, string_agg(id::text,',') AS rels FROM planet_osm_roads b LEFT JOIN planet_osm_rels r ON (r.parts @> ARRAY[osm_id] AND r.members @> ARRAY['w' || osm_id] AND regexp_replace(r.tags::text,'[{}]',',') ~ format('(,admin_level,%s.*,boundary,administrative|,boundary,administrative.*,admin_level,%s,)',admin_level,admin_level)) WHERE boundary='administrative' AND admin_level IS NOT NULL GROUP BY 1,2,3 ORDER BY admin_level DESC


-- admin_places (vue matérialisée)
Expand Down Expand Up @@ -255,7 +268,20 @@ WHERE
SELECT osm_id, COALESCE(highway, '') as type, COALESCE(tags -> 'name:br'::text,'') as name, way FROM planet_osm_line WHERE highway IN ('motorway','motorway_link','trunk','trunk_link','primary','primary_link','secondary','secondary_link','tertiary','tertiary_link','road','path','track','service','footway','bridleway','cycleway','steps','pedestrian','living_street','unclassified','residential','raceway')


-- places
SELECT
osm_id,
COALESCE(tags -> 'name:br'::text) as name,
place as type,
admin_level,
COALESCE(tags->'is_capital'::text) as is_capital,
z_order,
way
FROM planet_osm_point
WHERE (tags -> 'name:br'::text IS NOT NULL)
ORDER BY z_order ;

SELECT osm_id, COALESCE(tags -> 'name:br'::text) as name, place as type, admin_level, COALESCE(tags->'is_capital'::text) as is_capital, z_order, way FROM planet_osm_point WHERE (tags -> 'name:br'::text IS NOT NULL) ORDER BY z_order


-- =======================================================================
Expand Down
37 changes: 36 additions & 1 deletion labels.mss
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@

#place::small[type='hamlet'][zoom>=13],
#place::small[type='locality'][zoom>=13],
#place::small[type='isolated_dwelling'][zoom>=13] {
#place::small[type='isolated_dwelling'][zoom>=13],
#place::small[type='farm'][zoom>=13] {
text-name: '[name]';
text-face-name: @sans;
text-placement: point;
Expand Down Expand Up @@ -346,6 +347,40 @@
}
}

#place::suburb[type='neighbourhood'][zoom>=13][zoom<=16] {
text-name: '[name]';
text-face-name: @sans_bold_italic;
text-placement: point;
text-fill: @suburb_text;
text-size: 13;
text-halo-fill: @suburb_halo;
text-halo-radius: 2.0;
text-wrap-width: 50;
text-label-position-tolerance: 20;
text-allow-overlap: false;

[zoom=13] {
text-size: 9;
text-character-spacing: 1;
text-line-spacing: 2;
}
[zoom=14] {
text-size: 11;
text-character-spacing: 1;
text-line-spacing: 2;
}
[zoom=15] {
text-size: 14;
text-character-spacing: 2;
text-line-spacing: 2;
}
[zoom=16] {
text-size: 16;
text-character-spacing: 4;
text-line-spacing: 2;
}
}


// =====================================================================
// POI LABELS
Expand Down
6 changes: 3 additions & 3 deletions project.mml
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
"user": "osm",
"password": "osmbr",
"dbname": "osm",
"table": "(SELECT row_number() over() AS id, * FROM admin_boundaries ORDER BY admin_level DESC) AS data",
"table": "( SELECT b.way::geometry(LineString,3857) AS way, admin_level::integer AS admin_level, coalesce(b.tags->'maritime','no') AS maritime, count(r.*)::integer AS nb, string_agg(id::text,',') AS rels FROM planet_osm_roads b LEFT JOIN planet_osm_rels r ON (r.parts @> ARRAY[osm_id] AND r.members @> ARRAY['w' || osm_id] AND regexp_replace(r.tags::text,'[{}]',',') ~ format('(,admin_level,%s.*,boundary,administrative|,boundary,administrative.*,admin_level,%s,)',admin_level,admin_level)) WHERE boundary='administrative' AND admin_level IS NOT NULL GROUP BY 1,2,3 ORDER BY admin_level DESC ) AS data",
"key_field": "",
"geometry_field": "way",
"asynchronous_request": "true",
Expand Down Expand Up @@ -645,9 +645,9 @@
"user": "osm",
"password": "osmbr",
"dbname": "osm",
"table": "( SELECT osm_id, geometry, type, name_br AS name, z_order, is_capital, population FROM places WHERE name_br IS NOT NULL ORDER BY z_order ) AS data",
"table": "( SELECT osm_id, COALESCE(tags -> 'name:br'::text) as name, place as type, admin_level, COALESCE(tags->'is_capital'::text) as is_capital, z_order, way FROM planet_osm_point WHERE (tags -> 'name:br'::text IS NOT NULL) ORDER BY z_order ) AS data",
"key_field": "osm_id",
"geometry_field": "geometry",
"geometry_field": "way",
"asynchronous_request": "true",
"max_async_connection": "4",
"simplify_geometries": "true",
Expand Down

0 comments on commit 16076b4

Please sign in to comment.