From 4156b8abd152664d64a31190b70fe0dcfb30fc14 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Tue, 15 May 2018 17:05:09 +0100 Subject: [PATCH 1/4] Add admin area polygons to the RAWR tiles. These will be used for figuring out which features are in which countries, so that we can back-fill some of their missing properties and add more information to them which helps with styling. --- raw_tiles/source/__init__.py | 3 +++ raw_tiles/source/admin_areas.sql | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 raw_tiles/source/admin_areas.sql diff --git a/raw_tiles/source/__init__.py b/raw_tiles/source/__init__.py index 7574301..03d2d10 100644 --- a/raw_tiles/source/__init__.py +++ b/raw_tiles/source/__init__.py @@ -10,6 +10,7 @@ 'land_polygons', 'buffered_land', 'ne_10m_urban_areas', + 'admin_areas', ] @@ -29,6 +30,8 @@ def parse_sources(source_names): sources.append(GenericTableSource('buffered_land')) elif source_name == 'ne_10m_urban_areas': sources.append(GenericTableSource('ne_10m_urban_areas')) + elif source_name == 'admin_areas': + sources.append(GenericTableSource('admin_areas')) else: raise ValueError('No known source with name %r' % (source_name,)) diff --git a/raw_tiles/source/admin_areas.sql b/raw_tiles/source/admin_areas.sql new file mode 100644 index 0000000..02a5635 --- /dev/null +++ b/raw_tiles/source/admin_areas.sql @@ -0,0 +1,28 @@ +SELECT + gid AS __id__, + ST_AsBinary(geom) AS __geometry__, + jsonb_build_object( + 'source', 'openstreetmap.org', + 'kind', 'admin_area', + 'admin_level', 2, + 'iso_code', iso_code + ) AS __properties__ + +FROM ( + SELECT + gid, + -- extract only polygons. we might get linestring and point fragments when + -- the box and geometry touch but don't overlap. we don't want these, so + -- want to throw them away. + ST_CollectionExtract(ST_Intersection(the_geom, {{box}}), 3) AS geom, + iso_code + + FROM admin_areas + + WHERE + the_geom && {{box}} AND + admin_leve = '2' +) maybe_empty_intersections + +WHERE + NOT ST_IsEmpty(geom) From 69e6be95a1e8b3bf54f4052feb964b771c676db1 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Tue, 15 May 2018 17:06:40 +0100 Subject: [PATCH 2/4] More information about where failures are happening during RAWR generation. --- raw_tiles/source/generic.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/raw_tiles/source/generic.py b/raw_tiles/source/generic.py index 91e70a7..516a995 100644 --- a/raw_tiles/source/generic.py +++ b/raw_tiles/source/generic.py @@ -1,6 +1,7 @@ from raw_tiles.util import bbox_for_tile from raw_tiles.util import st_box2d_for_bbox from raw_tiles.util import time_block +from sys import exc_info # returns a geometry which is the given bounds expanded by `factor`. that is, @@ -39,8 +40,15 @@ def __call__(self, table_reader, tile): box2d = tile.box2d() template_name = self.table_name + ".sql" - table = table_reader.read_table( - template_name, self.table_name, st_box2d=box2d) + + try: + table = table_reader.read_table( + template_name, self.table_name, st_box2d=box2d) + except Exception as e: + raise type(e), \ + '%s in table %r' % (str(e), self.table_name), \ + exc_info()[2] + source_locations.append(table) return source_locations, timing From 93f0b7d1bbeacc62d2939a65be5abda520f4604d Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Tue, 15 May 2018 17:06:53 +0100 Subject: [PATCH 3/4] Fix buffered land SQL. --- raw_tiles/source/buffered_land.sql | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/raw_tiles/source/buffered_land.sql b/raw_tiles/source/buffered_land.sql index 0f5ee48..48b72f8 100644 --- a/raw_tiles/source/buffered_land.sql +++ b/raw_tiles/source/buffered_land.sql @@ -3,7 +3,7 @@ SELECT ST_AsBinary(geom) AS __geometry__, jsonb_build_object( 'source', 'tilezen.org', - 'min_zoom', scalerank, + 'min_zoom', 0, 'kind', 'maritime', 'maritime_boundary', TRUE ) AS __properties__ @@ -14,8 +14,7 @@ FROM ( -- extract only polygons. we might get linestring and point fragments when -- the box and geometry touch but don't overlap. we don't want these, so -- want to throw them away. - ST_CollectionExtract(ST_Intersection(the_geom, {{box}}), 3) AS geom, - scalerank + ST_CollectionExtract(ST_Intersection(the_geom, {{box}}), 3) AS geom FROM buffered_land @@ -24,5 +23,4 @@ FROM ( ) maybe_empty_intersections WHERE - NOT ST_IsEmpty(the_geom) - + NOT ST_IsEmpty(geom) From ff13c98d6e5807a6e69b92ab24abeca74b7b3a14 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Tue, 15 May 2018 19:16:00 +0100 Subject: [PATCH 4/4] Added comment explaining why 'admin_leve' confusingly doesn't have an 'l' on the end. --- raw_tiles/source/admin_areas.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/raw_tiles/source/admin_areas.sql b/raw_tiles/source/admin_areas.sql index 02a5635..3d0b24f 100644 --- a/raw_tiles/source/admin_areas.sql +++ b/raw_tiles/source/admin_areas.sql @@ -21,6 +21,8 @@ FROM ( WHERE the_geom && {{box}} AND + -- NOTE: this isn't a typo, it's the result of importing this from a shape + -- file, where column names are only allowed to be 8 characters wide! admin_leve = '2' ) maybe_empty_intersections