Skip to content

Commit

Permalink
fix bug on srid when upload a vector layer
Browse files Browse the repository at this point in the history
  • Loading branch information
boney-bun committed Jul 5, 2018
1 parent 27add96 commit 0f59fcb
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions geonode/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ def get_bbox(filename):
bbox_x0, bbox_y0, bbox_x1, bbox_y1 = None, None, None, None

if is_vector(filename):
y_min = -85
y_max = 85
x_min = -180
x_max = 85
datasource = DataSource(filename)
layer = datasource[0]
bbox_x0, bbox_y0, bbox_x1, bbox_y1 = layer.extent.tuple
# gdal's SourceData seems to be unreliable in determining EPSG code.
# obtain EPSG code from a prj file instead
prj_path = filename.split(".shp")[0] + ".prj"
Expand All @@ -355,9 +362,17 @@ def get_bbox(filename):
srs = osr.SpatialReference(wkt=prj_txt)
srs.AutoIdentifyEPSG()
epsg_code = srs.GetAuthorityCode(None)
datasource = DataSource(filename)
layer = datasource[0]
bbox_x0, bbox_y0, bbox_x1, bbox_y1 = layer.extent.tuple
# can't find epsg code, then check if bbox is within the WGS84 boundary
if epsg_code is None and (x_min <= bbox_x0 <= x_max \
and x_min <= bbox_x1 <= x_max \
and y_min <= bbox_y0 <= y_max \
and y_min <= bbox_y1 <= y_max):
# set default epsg code
epsg_code = '4326'
else:
# otherwise, stop the upload process
raise GeoNodeException("Invalid Projection. Please use valid EPSG code")

# eliminate default EPSG srid as it will be added when this function returned
srid = epsg_code if epsg_code else '4326'
elif is_raster(filename):
Expand Down

0 comments on commit 0f59fcb

Please sign in to comment.