Skip to content

Commit

Permalink
Merge pull request #1769 from girder/geospatial-flag
Browse files Browse the repository at this point in the history
Better report if rasterized vector files are geospatial
  • Loading branch information
manthey authored Jan 9, 2025
2 parents e31d221 + bb292d0 commit b0916f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 10 additions & 6 deletions sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b0916f0

Please sign in to comment.