[osm] country and postal code polygon readers

This commit is contained in:
Al
2016-10-01 01:11:35 -04:00
parent c77e36deab
commit 5d7405b2fd
3 changed files with 39 additions and 0 deletions

View File

@@ -308,3 +308,13 @@ class OSMSubdivisionPolygonReader(OSMPolygonReader):
class OSMBuildingPolygonReader(OSMPolygonReader):
def include_polygon(self, props):
return 'building' in props or 'building:part' in props or props.get('type', None) == 'building'
class OSMCountryPolygonReader(OSMPolygonReader):
def include_polygon(self, props):
return 'ISO3166-1:alpha2' in props
class OSMPostalCodesPolygonReader(OSMPolygonReader):
def include_polygon(self, props):
return props.get('boundary') == 'postal_code'

View File

@@ -112,10 +112,13 @@ rm $JAPAN_ADDRESSES_LATLONS
# Border data set for use in R-tree index/reverse geocoding, parsing, language detection
echo "Filtering for borders: `date`"
PLANET_COUNTRIES="planet-countries.osm"
PLANET_BORDERS_O5M="planet-borders.o5m"
PLANET_BORDERS="planet-borders.osm"
PLANET_ADMIN_BORDERS_OSM="planet-admin-borders.osm"
VALID_COUNTRY_KEYS="ISO3166-1:alpha2="
VALID_ADMIN_BORDER_KEYS="boundary=administrative or boundary=town or boundary=city_limit or boundary=civil_parish or boundary=civil or boundary=ceremonial or place=island or place=city or place=town or place=village or place=hamlet or place=municipality or place=settlement"
VALID_POPULATED_PLACE_KEYS="place=city or place=town or place=village or place=hamlet or placement=municipality or place=locality or place=settlement or place=census-designated or place:ph=village"
@@ -134,6 +137,7 @@ osmconvert $PLANET_BORDERS_O5M --max-objects=1000000000 --all-to-nodes -o=$PLANE
rm $PLANET_BORDERS_O5M
osmfilter $PLANET_BORDERS_LATLONS --keep="$VALID_ADMIN_BORDER_KEYS or $VALID_LOCALITY_KEYS" -o=$PLANET_BORDERS
rm $PLANET_BORDERS_LATLONS
osmfilter $PLANET_O5M --keep="$VALID_COUNTRY_KEYS" --drop-author --drop-version -o=$PLANET_COUNTRIES
echo "Filtering for rail stations"
VALID_RAIL_STATION_KEYS="railway=station"

View File

@@ -452,6 +452,21 @@ class OSMBuildingReverseGeocoder(OSMReverseGeocoder):
include_property_patterns = OSMReverseGeocoder.include_property_patterns | set(['building', 'building:levels', 'building:part', 'addr:*'])
class OSMPostalCodeReverseGeocoder(OSMReverseGeocoder):
persistent_polygons = True
cache_size = 10000
simplify_polygons = False
polygon_reader = OSMPostalCodesPolygonReader
include_property_patterns = OSMReverseGeocoder.include_property_patterns | set(['postal_code'])
class OSMCountryReverseGeocoder(OSMReverseGeocoder):
persistent_polygons = True
cache_size = 1000
simplify_polygons = False
polygon_reader = OSMCountryPolygonReader
if __name__ == '__main__':
# Handle argument parsing here
parser = argparse.ArgumentParser()
@@ -468,6 +483,12 @@ if __name__ == '__main__':
parser.add_argument('-b', '--osm-building-polygons-file',
help='Path to OSM building polygons file (with dependencies, .osm format)')
parser.add_argument('-p', '--osm-postal-code-polygons-file',
help='Path to OSM postal code polygons file (with dependencies, .osm format)')
parser.add_argument('-c', '--osm-country-polygons-file',
help='Path to OSM country polygons file (with dependencies, .osm format)')
parser.add_argument('-o', '--out-dir',
default=os.getcwd(),
help='Output directory')
@@ -481,6 +502,10 @@ if __name__ == '__main__':
index = OSMSubdivisionReverseGeocoder.create_from_osm_file(args.osm_subdivisions_file, args.out_dir)
elif args.osm_building_polygons_file:
index = OSMBuildingReverseGeocoder.create_from_osm_file(args.osm_building_polygons_file, args.out_dir)
elif args.osm_country_polygons_file:
index = OSMCountryReverseGeocoder.create_from_osm_file(args.osm_country_polygons_file, args.out_dir)
elif args.osm_postal_code_polygons_file:
index = OSMPostalCodeReverseGeocoder.create_from_osm_file(args.osm_postal_code_polygons_file, args.out_dir)
elif args.quattroshapes_dir:
index = QuattroshapesReverseGeocoder.create_with_quattroshapes(args.quattroshapes_dir, args.out_dir)
else: