From 302df67df3bf3cb5032657cd4932679da7ef8817 Mon Sep 17 00:00:00 2001 From: Boney Bun Date: Tue, 17 Jul 2018 14:09:46 +0700 Subject: [PATCH] fix srid problem in vector layer and revise the PR based on @gubuntu feedback fix #435 --- geonode/layers/utils.py | 15 +++------------ geonode/tests/integration.py | 7 +++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/geonode/layers/utils.py b/geonode/layers/utils.py index 3ed1b7416db..8ff5821172f 100644 --- a/geonode/layers/utils.py +++ b/geonode/layers/utils.py @@ -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 \ diff --git a/geonode/tests/integration.py b/geonode/tests/integration.py index a43f320397b..b145a8e9562 100644 --- a/geonode/tests/integration.py +++ b/geonode/tests/integration.py @@ -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,