Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a bug on determining srid when upload a vector layer #437

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions geonode/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,22 @@ def get_bbox(filename):
bbox_x0, bbox_y0, bbox_x1, bbox_y1 = None, None, None, None

if is_vector(filename):
# 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"
try:
prj_file = open(prj_path, 'r')
except Exception:
raise GeoNodeException("Invalid Projection. Layer is missing CRS!")
prj_txt = prj_file.read()
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
srid = layer.srs.srid if layer.srs else 'EPSG:4326'
# 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):
gtif = gdal.Open(filename)
gt = gtif.GetGeoTransform()
Expand Down Expand Up @@ -375,7 +387,8 @@ def get_bbox(filename):
bbox_y0 = min(ext[0][1], ext[2][1])
bbox_x1 = max(ext[0][0], ext[2][0])
bbox_y1 = max(ext[0][1], ext[2][1])
srid = srs.GetAuthorityCode(None) if srs else 'EPSG:4326'
# eliminate default EPSG srid as it will be added when this function returned
srid = srs.GetAuthorityCode(None) if srs else '4326'

return [bbox_x0, bbox_x1, bbox_y0, bbox_y1, "EPSG:%s" % str(srid)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even an expert geonode developer can miss this 😂

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been tested by unittest. If not, then we should add.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we need to submit PR to upstream GeoNode for issues like this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boney-bun cc @lucernae we should be doing all GeoNode PRs directly upstream.

Also why is this merged when we decided to not assume 4326 if no projection defined?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gubuntu i merged this PR so others can start working on upload (including me) in the testing.
the new PR for checking the range within 4326 is in #442.
could you kindly verify it?
once satisfied, i'm going to make PR to upstream.


Expand Down