Skip to content

Commit

Permalink
fix srid problem in vector layer and revise the PR based on @gubuntu
Browse files Browse the repository at this point in the history
…feedback

fix kartoza#435
  • Loading branch information
boney-bun committed Jul 17, 2018
1 parent d48b2ee commit 302df67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
15 changes: 3 additions & 12 deletions geonode/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,9 @@ def get_bbox(filename):
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"
try:
prj_file = open(prj_path, 'r')
prj_txt = prj_file.read()
prj_file.close()
except Exception:
raise GeoNodeException("Invalid Projection. Layer is missing CRS!")
srs = osr.SpatialReference(wkt=prj_txt)
srs.AutoIdentifyEPSG()
epsg_code = srs.GetAuthorityCode(None)
srs = layer.srs
srs.identify_epsg()
epsg_code = srs.srid
# can't find epsg code, then check if bbox is within the 4326 boundary
if epsg_code is None and (x_min <= bbox_x0 <= x_max \
and x_min <= bbox_x1 <= x_max \
Expand Down
7 changes: 7 additions & 0 deletions geonode/tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@ def test_layer_upload_metadata(self):
uploaded.metadata_xml = thelayer_metadata
regions_resolved, regions_unresolved = resolve_regions(regions)
self.assertIsNotNone(regions_resolved)
except GeoNodeException, e:
# layer have projection file, but has no valid srid
self.assertEqual(
str(e),
"Invalid Layers. "
"Needs an authoritative SRID in its CRS to be accepted")

# except:
# # Sometimes failes with the message:
# # UploadError: Could not save the layer air_runways,
Expand Down

0 comments on commit 302df67

Please sign in to comment.