Skip to content

Commit

Permalink
Fixes part of #358 (the layer extent)
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti committed May 10, 2018
1 parent b29abc5 commit 272017b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions geonode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,33 @@ def bbox_to_projection(native_bbox, target_srid=4326):
proj = native_bbox[-1]
minx, maxx, miny, maxy = [float(a) for a in box]
source_srid = int(proj.split(":")[1])

def _v(coord, x, source_srid=4326, target_srid=3857):
if source_srid == 4326 and target_srid != 4326:
if x and coord >= 180.0:
return 179.0
elif x and coord <= -180.0:
return -179.0

if not x and coord >= 90.0:
return 89.0
elif not x and coord <= -90.0:
return -89.0
return coord

if source_srid != target_srid:
try:
wkt = bbox_to_wkt(minx, maxx, miny, maxy, srid=source_srid)
wkt = bbox_to_wkt(_v(minx, x=True, source_srid=source_srid, target_srid=target_srid),
_v(maxx, x=True, source_srid=source_srid, target_srid=target_srid),
_v(miny, x=False, source_srid=source_srid, target_srid=target_srid),
_v(maxy, x=False, source_srid=source_srid, target_srid=target_srid),
srid=source_srid)
poly = GEOSGeometry(wkt, srid=source_srid)
poly.transform(target_srid)
return tuple([str(x) for x in poly.extent]) + ("EPSG:%s" % poly.srid,)
except BaseException:
tb = traceback.format_exc()
logger.error(tb)
logger.debug(tb)

return native_bbox

Expand Down Expand Up @@ -1310,8 +1328,8 @@ def chmod_tree(dst, permissions=0o777):
for dirname in dirnames:
path = os.path.join(dirpath, dirname)
os.chmod(path, permissions)


def slugify_zh(text, separator='_'):
"""
Make a slug from the given text, which is simplified from slugify.
Expand Down Expand Up @@ -1343,4 +1361,4 @@ def slugify_zh(text, separator='_'):
text = re.sub(DUPLICATE_DASH_PATTERN, DEFAULT_SEPARATOR, text).strip(DEFAULT_SEPARATOR)
if separator != DEFAULT_SEPARATOR:
text = text.replace(DEFAULT_SEPARATOR, separator)
return text
return text

0 comments on commit 272017b

Please sign in to comment.