[osm] Trying fixed-point precision in converting OSM coordinates to avoid issues with polygon self-intersection when the lines are very close together (e.g. parts of Berlin, UK country polygon)
This commit is contained in:
@@ -17,6 +17,8 @@ import re
|
|||||||
|
|
||||||
from geodata.encoding import safe_decode
|
from geodata.encoding import safe_decode
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
beginning_re = re.compile('^[^0-9\-]+', re.UNICODE)
|
beginning_re = re.compile('^[^0-9\-]+', re.UNICODE)
|
||||||
end_re = re.compile('[^0-9]+$', re.UNICODE)
|
end_re = re.compile('[^0-9]+$', re.UNICODE)
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ def degrees_to_decimal(degrees, minutes, seconds):
|
|||||||
return degrees + (minutes / 60.0) + (seconds / 3600.0)
|
return degrees + (minutes / 60.0) + (seconds / 3600.0)
|
||||||
|
|
||||||
|
|
||||||
def latlon_to_decimal(latitude, longitude):
|
def latlon_to_decimal(latitude, longitude, return_type=Decimal):
|
||||||
have_lat = False
|
have_lat = False
|
||||||
have_lon = False
|
have_lon = False
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ def latlon_to_decimal(latitude, longitude):
|
|||||||
elif lat_dir:
|
elif lat_dir:
|
||||||
d, c = lat_dir.groups()
|
d, c = lat_dir.groups()
|
||||||
sign = direction_sign(c)
|
sign = direction_sign(c)
|
||||||
latitude = float(d) * sign
|
latitude = return_type(d) * sign
|
||||||
have_lat = True
|
have_lat = True
|
||||||
else:
|
else:
|
||||||
latitude = re.sub(beginning_re, u'', latitude)
|
latitude = re.sub(beginning_re, u'', latitude)
|
||||||
@@ -92,10 +94,10 @@ def latlon_to_decimal(latitude, longitude):
|
|||||||
elif lon_dir:
|
elif lon_dir:
|
||||||
d, c = lon_dir.groups()
|
d, c = lon_dir.groups()
|
||||||
sign = direction_sign(c)
|
sign = direction_sign(c)
|
||||||
longitude = float(d) * sign
|
longitude = return_type(d) * sign
|
||||||
have_lon = True
|
have_lon = True
|
||||||
else:
|
else:
|
||||||
longitude = re.sub(beginning_re, u'', longitude)
|
longitude = re.sub(beginning_re, u'', longitude)
|
||||||
longitude = re.sub(end_re, u'', longitude)
|
longitude = re.sub(end_re, u'', longitude)
|
||||||
|
|
||||||
return float(latitude), float(longitude)
|
return return_type(latitude), return_type(longitude)
|
||||||
|
|||||||
Reference in New Issue
Block a user