From bb292d056481535a7982e83945557caa5e55a28e Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 9 Jan 2025 15:17:36 -0500 Subject: [PATCH] Better report if rasterized vector files are geospatial --- CHANGELOG.md | 6 ++++++ sources/gdal/large_image_source_gdal/__init__.py | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddde0c7f0..60692f886 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 1.30.7 + +### Improvements + +- Better report if rasterized vector files are geospatial ([#1769](../../pull/1769)) + ## 1.30.6 ### Features diff --git a/sources/gdal/large_image_source_gdal/__init__.py b/sources/gdal/large_image_source_gdal/__init__.py index b6aaefc6d..5f7b2ae3e 100644 --- a/sources/gdal/large_image_source_gdal/__init__.py +++ b/sources/gdal/large_image_source_gdal/__init__.py @@ -192,6 +192,7 @@ def _openVectorSource(self, vec): proj = None except Exception: proj = None + self._geospatial = proj is not None # Define raster parameters pixel_size = max(x_max - x_min, y_max - y_min) / ( self.VECTOR_IMAGE_SIZE if proj is None else self.PROJECTED_VECTOR_IMAGE_SIZE) @@ -214,7 +215,8 @@ def _openVectorSource(self, vec): ds.SetGeoTransform((x_min, pixel_size, 0, y_min, 0, pixel_size)) if proj: ds.SetProjection(proj) - msg = f'Rasterizing a vector layer to {x_res} x {y_res}' + msg = (f'Rasterizing a vector layer to {x_res} x {y_res} ' + f'({"not " if not self._geospatial else ""} geospatial)') self.logger.info(msg) gdal.RasterizeLayer(ds, [1], layer, burn_values=[255]) if not hasattr(self.__class__, '_openVectorLock'): @@ -659,11 +661,13 @@ def geospatial(self): """ This is true if the source has geospatial information. """ - return bool( - self.dataset.GetProjection() or - (self.dataset.GetGCPProjection() and self.dataset.GetGCPs()) or - self.dataset.GetGeoTransform(can_return_null=True) or - hasattr(self, '_netcdf')) + if not hasattr(self, '_geospatial'): + self._geospatial = bool( + self.dataset.GetProjection() or + (self.dataset.GetGCPProjection() and self.dataset.GetGCPs()) or + self.dataset.GetGeoTransform(can_return_null=True) or + hasattr(self, '_netcdf')) + return self._geospatial def getMetadata(self): metadata = super().getMetadata()