diff --git a/ocitysmap-init.sql b/ocitysmap-init.sql new file mode 100644 index 0000000..4bb207d --- /dev/null +++ b/ocitysmap-init.sql @@ -0,0 +1,20 @@ +-- Create a view that associates each city with an area representing +-- its territory, based on the administrative boundaries available in +-- OSM database. For french cities, these boundaries are admin_level 8, +-- and are for the moment only available for part of the country. + +create or replace view cities_area + as select name as city, st_buildarea(way) as area + from planet_osm_line where boundary='administrative' and admin_level='8';"""); + +-- Create an aggregate used to build the list of squares that each +-- street intersects + +CREATE AGGREGATE textcat_all( + basetype = text, + sfunc = textcat, + stype = text, + initcond = '' +); + + diff --git a/ocitysmap/street_index.py b/ocitysmap/street_index.py index 33c5989..72a703b 100644 --- a/ocitysmap/street_index.py +++ b/ocitysmap/street_index.py @@ -380,17 +380,6 @@ class OCitySMap: values (%d, %d, st_geomfromtext('%s', 4002))""" % (i, j, poly)) - # Create a view that associates the name of a city with the - # area covering it. As of today, only parts of the french - # cities have these administrative boundaries available in - # OSM. When available, this boundary is used to filter out the - # streets that are not inside the selected city but still in - # the bounding box rendered on the map. So these streets will - # be shown but not listed in the street index. - cursor.execute("""create or replace view cities_area - as select name as city, st_buildarea(way) as area - from planet_osm_line - where boundary='administrative' and admin_level='8';""") db.commit() # The inner select query creates the list of (street, square) @@ -398,8 +387,26 @@ class OCitySMap: # left_join + the test on cities_area is used to filter out # the streets outside the city administrative boundaries. The # outer select builds an easy to parse list of the squares for - # each street. A typical result entry is: + # each street. + # + # A typical result entry is: # [ "Rue du Moulin", "0,1;1,2;1,3" ] + # + # REMARKS: + # + # * The cities_area view is created once for all at + # installation. It associates the name of a city with the + # area covering it. As of today, only parts of the french + # cities have these administrative boundaries available in + # OSM. When available, this boundary is used to filter out + # the streets that are not inside the selected city but + # still in the bounding box rendered on the map. So these + # streets will be shown but not listed in the street index. + # + # * The textcat_all() aggregate must also be installed in the + # database + # + # See ocitysmap-init.sql for details cursor.execute("""select name, textcat_all(x || ',' || y || ';') from (select distinct name, x, y from planet_osm_line