[osm] better lat/lon conversion for admin_center point
This commit is contained in:
@@ -1328,17 +1328,30 @@ class OSMAddressFormatter(object):
|
|||||||
print('did {} formatted places'.format(i))
|
print('did {} formatted places'.format(i))
|
||||||
|
|
||||||
for tags, poly in iter(self.components.osm_admin_rtree):
|
for tags, poly in iter(self.components.osm_admin_rtree):
|
||||||
|
point = None
|
||||||
if 'admin_center' in tags and 'lat' in tags['admin_center'] and 'lon' in tags['admin_center']:
|
if 'admin_center' in tags and 'lat' in tags['admin_center'] and 'lon' in tags['admin_center']:
|
||||||
admin_center = tags['admin_center']
|
admin_center = tags['admin_center']
|
||||||
point = Point(admin_center['lon'], admin_center['lat'])
|
|
||||||
else:
|
latitude = admin_center['lat']
|
||||||
|
longitude = admin_center['lon']
|
||||||
|
|
||||||
|
try:
|
||||||
|
latitude, longitude = latlon_to_decimal(latitude, longitude)
|
||||||
|
point = Point(longitude, latitude)
|
||||||
|
except Exception:
|
||||||
|
point = None
|
||||||
|
|
||||||
|
if point is None:
|
||||||
try:
|
try:
|
||||||
point = poly.context.representative_point()
|
point = poly.context.representative_point()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
point = poly.context.centroid
|
point = poly.context.centroid
|
||||||
|
|
||||||
|
try:
|
||||||
lat = point.y
|
lat = point.y
|
||||||
lon = point.x
|
lon = point.x
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
tags['lat'] = lat
|
tags['lat'] = lat
|
||||||
tags['lon'] = lon
|
tags['lon'] = lon
|
||||||
place_tags, country = self.node_place_tags(tags, city_or_below=True)
|
place_tags, country = self.node_place_tags(tags, city_or_below=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user