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

502 non readable raster #517

Merged
merged 4 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [#465](https://github.com/LayerManager/layman/issues/465) Fix situation, when Layman does not start if *.qgis file of the first layer with QML style does not exist. It was already fixed in v1.14.1.
- [#464](https://github.com/LayerManager/layman/issues/464) Fix publishing layers with unusual attribute names (e.g. `x,` or `Číslo`) and QML styles. It was already fixed in v1.14.1.
- [#459](https://github.com/LayerManager/layman/issues/459) Fix situation, when sometimes publication stayed in PENDING status after failure. It was already fixed in v1.14.1.
- [#502](https://github.com/LayerManager/layman/issues/502) Fix error message, when invalid raster file is sent.
- Rename item `username` to `workspace` in error 41.
- Detailed [test-related documentation for developers](tests/README.md).
- [#487](https://github.com/LayerManager/layman/issues/487) Upgrade
Expand Down
28 changes: 20 additions & 8 deletions src/layman/layer/filesystem/gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@ def delete_layer(workspace, layername):
pass


def open_raster_file(filepath, mode=gdal.GA_ReadOnly):
dataset = gdal.Open(filepath, mode)
if not dataset:
raise LaymanError(2, {
'parameter': 'file',
'message': f"Unable to open raster file.",
'expected': f"At least one file with any of extensions: .geojson, .shp, .tiff, .tif, .jp2, .png, .jpg; or one of them in single .zip file.",
'file': filepath,
})
return dataset


def get_color_interpretations(filepath):
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
dataset = open_raster_file(filepath)
result = []
for band_id in range(1, dataset.RasterCount + 1):
band = dataset.GetRasterBand(band_id)
Expand All @@ -51,7 +63,7 @@ def get_color_interpretations(filepath):


def get_overview_counts(filepath):
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
dataset = open_raster_file(filepath)
result = []
for band_id in range(1, dataset.RasterCount + 1):
band = dataset.GetRasterBand(band_id)
Expand Down Expand Up @@ -79,7 +91,7 @@ def assert_valid_raster(input_path):


def get_nodata_values(filepath):
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
dataset = open_raster_file(filepath, gdal.GA_ReadOnly)
result = []
for band_id in range(1, dataset.RasterCount + 1):
band = dataset.GetRasterBand(band_id)
Expand All @@ -89,7 +101,7 @@ def get_nodata_values(filepath):


def get_mask_flags(filepath):
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
dataset = open_raster_file(filepath, gdal.GA_ReadOnly)
all_mask_flags = [
gdalconst.GMF_ALL_VALID,
gdalconst.GMF_ALPHA,
Expand All @@ -106,13 +118,13 @@ def get_mask_flags(filepath):


def get_pixel_size(filepath):
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
dataset = open_raster_file(filepath, gdal.GA_ReadOnly)
geo_transform = dataset.GetGeoTransform()
return [geo_transform[1], geo_transform[5]]


def get_raster_size(filepath):
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
dataset = open_raster_file(filepath, gdal.GA_ReadOnly)
x_size = dataset.RasterXSize
y_size = dataset.RasterYSize
return [x_size, y_size]
Expand All @@ -122,7 +134,7 @@ def get_statistics(filepath):
# If Nodata is set and it's lowest value in dataset and at least one pixel has Nodata value,
# GetStatistics does not return Nodata value as MIN, but lowest value that is not Nodata value.
# It's probably similar for MAX.
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
dataset = open_raster_file(filepath, gdal.GA_ReadOnly)
result = []
for band_id in range(1, dataset.RasterCount + 1):
band = dataset.GetRasterBand(band_id)
Expand Down Expand Up @@ -312,7 +324,7 @@ def delete_normalized_raster_workspace(workspace):

def get_bbox(workspace, layer):
filepath = get_normalized_raster_layer_main_filepath(workspace, layer)
data = gdal.Open(filepath, gdalconst.GA_ReadOnly)
data = open_raster_file(filepath, gdalconst.GA_ReadOnly)
geo_transform = data.GetGeoTransform()
minx = geo_transform[0]
maxy = geo_transform[3]
Expand Down
7 changes: 3 additions & 4 deletions src/layman/layer/filesystem/input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import pathlib

from osgeo import ogr, gdal
from osgeo import ogr

from layman.http import LaymanError
from layman import settings, patch_mode
Expand Down Expand Up @@ -123,8 +123,7 @@ def check_vector_main_file(main_filepath, *, check_crs=True):


def check_raster_main_file(main_filepath, *, check_crs=True):
in_data_source = gdal.Open(main_filepath)
assert in_data_source is not None
fs_gdal.open_raster_file(main_filepath)
fs_gdal.assert_valid_raster(main_filepath)
if check_crs:
check_raster_layer_crs(main_filepath)
Expand All @@ -137,7 +136,7 @@ def spatial_ref_crs_to_crs_id(spatial_ref):


def get_raster_crs(main_filepath):
in_data_source = gdal.Open(main_filepath)
in_data_source = fs_gdal.open_raster_file(main_filepath)
return in_data_source.GetSpatialRef()


Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def fill_in_partial_info_statuses(info, chain_info):
file_type = info.get('file', dict()).get('file_type')
item_keys = get_layer_info_keys(file_type) if file_type else settings.FILE_TYPE_UNKNOWN

return layman_util.fill_in_partial_info_statuses(info, chain_info, TASKS_TO_LAYER_INFO_KEYS, item_keys)
return layman_util.get_info_with_statuses(info, chain_info, TASKS_TO_LAYER_INFO_KEYS, item_keys)


def get_layer_info(workspace, layername, context=None):
Expand Down
2 changes: 1 addition & 1 deletion src/layman/map/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_providers():

def fill_in_partial_info_statuses(info, chain_info):
item_keys = get_map_info_keys()
return layman_util.fill_in_partial_info_statuses(info, chain_info, TASKS_TO_MAP_INFO_KEYS, item_keys)
return layman_util.get_info_with_statuses(info, chain_info, TASKS_TO_MAP_INFO_KEYS, item_keys)


def get_map_info(workspace, mapname, context=None):
Expand Down
5 changes: 3 additions & 2 deletions src/layman/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import wraps
import importlib
import copy
import inspect
import re
import unicodedata
Expand Down Expand Up @@ -464,8 +465,8 @@ def get_publication_status(workspace, publication_type, publication_name, comple
return publication_status


def fill_in_partial_info_statuses(info, chain_info, task_to_layer_info_keys, item_keys):
filled_info = info
def get_info_with_statuses(info, chain_info, task_to_layer_info_keys, item_keys):
filled_info = copy.deepcopy(info)

if chain_info is None or celery_util.is_chain_successful(chain_info):
return filled_info
Expand Down
Loading