Skip to content

Commit

Permalink
Merge pull request #24 from tilezen/zerebubuth/add-admin-areas
Browse files Browse the repository at this point in the history
Add admin areas
  • Loading branch information
zerebubuth authored May 15, 2018
2 parents 7f7d485 + ff13c98 commit ee95bce
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
3 changes: 3 additions & 0 deletions raw_tiles/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'land_polygons',
'buffered_land',
'ne_10m_urban_areas',
'admin_areas',
]


Expand All @@ -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,))

Expand Down
30 changes: 30 additions & 0 deletions raw_tiles/source/admin_areas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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
-- 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

WHERE
NOT ST_IsEmpty(geom)
8 changes: 3 additions & 5 deletions raw_tiles/source/buffered_land.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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

Expand All @@ -24,5 +23,4 @@ FROM (
) maybe_empty_intersections

WHERE
NOT ST_IsEmpty(the_geom)

NOT ST_IsEmpty(geom)
12 changes: 10 additions & 2 deletions raw_tiles/source/generic.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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

0 comments on commit ee95bce

Please sign in to comment.