EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit bed3e615 authored by Lubomir Dolezal's avatar Lubomir Dolezal
Browse files

georeference now takes a list of geotransforms and tries until one pass

parent 51f689b4
No related branches found
No related tags found
2 merge requests!49Production release 1.1.1,!42Redis statuses
......@@ -69,7 +69,9 @@ preprocessing:
data_file_globs:
- "*imagery_*.tif"
georeference:
type: gcp
geotransforms:
- type: gcp
- type: no_op
calc:
formulas:
# complex b1/b2 to b1 uint16 for all 4 polarizations
......@@ -132,11 +134,21 @@ preprocessing:
- "*IMG_*.JP2"
additional_file_globs:
- "*DIM_*"
- "*RPC_*"
georeference:
geotransforms:
- type: rpc
- type: no_op
SP07:
data_file_globs:
- "*IMG_*.JP2"
additional_file_globs:
- "*DIM_*"
- "*RPC_*"
georeference:
geotransforms:
- type: rpc
- type: no_op
# this configuration is still a stub - not all product types are done
# https://gitlab.eox.at/esa/prism/vs/-/issues/56
# https://gitlab.eox.at/esa/prism/vs/-/issues/23
......@@ -356,51 +356,55 @@ preprocessing
How the extracted files shall be georeferenced.
type
geotransforms
The type of georeferencing to apply. One of ``gcp``, ``rpc``,
``corner``, ``world``.
A list of georeference methods with options to try.
type
options
The type of georeferencing to apply. One of ``gcp``, ``rpc``,
``corner``, ``world``.
options
Additional options for the georeferencing. Depends on the type of
georeferencing.
Additional options for the georeferencing. Depends on the type of
georeferencing.
order
order
The polynomial order to use for GCP related georeferencing.
The polynomial order to use for GCP related georeferencing.
projection
projection
The projection to use for ungeoreferenced images.
The projection to use for ungeoreferenced images.
rpc_file_template
rpc_file_template
The file glob template to use to find the RPC file. Template
parameters are {filename}, {fileroot}, and {extension}.
The file glob template to use to find the RPC file. Template
parameters are {filename}, {fileroot}, and {extension}.
warp_options
warp_options
Warp options. See
https://gdal.org/python/osgeo.gdal-module.html#WarpOptions for
details
Warp options. See
https://gdal.org/python/osgeo.gdal-module.html#WarpOptions for
details
corner_names
corner_names
The metadata field name including the corner names. Tuple of four:
bottom-left, bottom-right, top-left and top-right
The metadata field name including the corner names. Tuple of four:
bottom-left, bottom-right, top-left and top-right
orbit_direction_name
orbit_direction_name
The metadata field name containing the orbit direction
The metadata field name containing the orbit direction
force_north_up
force_north_up
Circumvents the naming of corner names and assumes a north-up orientation of the image.
Circumvents the naming of corner names and assumes a north-up orientation of the image.
tps
tps
Whether to use TPS transformation instead of GCP polynomials.
Whether to use TPS transformation instead of GCP polynomials.
calc
......
......@@ -117,44 +117,47 @@ definitions:
".*":
type: string
georeference:
description: The definition of a georeferencing step.
type: object
type: object
properties:
type:
description: The type of georeferencing to apply.
type: string
enum: [gcp, rpc, corner, world] # TODO: more
options:
description: Additional options for the georeferencing. Depends on the type of georeferencing.
type: object
properties:
order:
description: The polynomial order to use for GCP reprojection.
type: number
projection:
description: The projection to use for ungeoreferenced images.
type: string
rpc_file_template:
description: The file glob template to use to find the RPC file. Template parameters are {filename}, {fileroot}, and {extension}.
type: string
warp_options:
description: "Warp options. See https://gdal.org/python/osgeo.gdal-module.html#WarpOptions for details"
corner_names:
description: "The metadata field name including the corner names. Tuple of four: bottom-left, bottom-right, top-left and top-right"
type: array
items:
geotransforms:
description: A list of geotransform methods to use
type: array
items:
type: object
properties:
type:
description: The type of georeferencing to apply.
type: string
orbit_direction_name:
description: The metadata field name containing the orbit direction
type: string
force_north_up:
description:
type: boolean
tps:
description: Whether to use TPS transformation instead of GCP polynomials.
type: boolean
required: [type]
enum: [gcp, rpc, corner, world, no_op] # TODO: more
options:
description: Additional options for the georeferencing. Depends on the type of georeferencing.
type: object
properties:
order:
description: The polynomial order to use for GCP reprojection.
type: number
projection:
description: The projection to use for ungeoreferenced images.
type: string
rpc_file_template:
description: The file glob template to use to find the RPC file. Template parameters are {filename}, {fileroot}, and {extension}.
type: string
warp_options:
description: "Warp options. See https://gdal.org/python/osgeo.gdal-module.html#WarpOptions for details"
corner_names:
description: "The metadata field name including the corner names. Tuple of four: bottom-left, bottom-right, top-left and top-right"
type: array
items:
type: string
orbit_direction_name:
description: The metadata field name containing the orbit direction
type: string
force_north_up:
description:
type: boolean
tps:
description: Whether to use TPS transformation instead of GCP polynomials.
type: boolean
calc:
description: Definition of a calculation step.
type: object
......
......@@ -11,25 +11,39 @@ from ..util import gdal, osr, replace_ext
logger = logging.getLogger(__name__)
def georeference_step(source_dir: os.PathLike, target_dir: os.PathLike, type: str, **options: dict):
type_name = type.lower()
if type_name == 'gcp':
georef_func = gcp_georef
elif type_name == 'rpc':
georef_func = rpc_georef
elif type_name == 'world':
georef_func = world_georef
elif type_name == 'corners':
georef_func = corner_georef
else:
raise Exception('Invalid georeference type %s' % type_name)
for filename in [path for path in glob(join(source_dir, '**'), recursive=True) if not os.path.isdir(path)]:
target_filename = join(target_dir, basename(filename))
georef_func(filename, target_filename, **options)
def georeference_step(source_dir: os.PathLike, target_dir: os.PathLike, geotransforms: List[dict]):
success = False
for options in geotransforms:
type_name = options['type'].lower()
if type_name == 'gcp':
georef_func = gcp_georef
elif type_name == 'rpc':
georef_func = rpc_georef
elif type_name == 'world':
georef_func = world_georef
elif type_name == 'corners':
georef_func = corner_georef
elif type_name == 'no_op':
georef_func = no_op
else:
raise Exception('Invalid georeference type %s' % type_name)
try:
for filename in [path for path in glob(join(source_dir, '**'), recursive=True) if not os.path.isdir(path)]:
target_filename = join(target_dir, basename(filename))
georef_func(filename, target_filename, **options)
except:
# if any file fails, try another method
continue
else:
# all files georeferenced without exception, no need to try another methods
success = True
break
if not success and len(types) > 0:
raise Exception('No configured georeference method passed: %s' % ','.join([item['type'] for item in geotransforms]))
def gcp_georef(input_filename: os.PathLike, target_filename: os.PathLike, order: int=1, projection: str='EPSG:4326',
tps: bool=False):
tps: bool=False, warp_options: dict=None):
succeded = False
# simple case: get the geotransform from some GCPs
......@@ -68,9 +82,11 @@ def gcp_georef(input_filename: os.PathLike, target_filename: os.PathLike, order:
target_filename,
input_filename,
dstSRS=projection,
**(warp_options or {}),
**options,
)
def rpc_georef(input_filename: os.PathLike, target_filename: os.PathLike, rpc_file_template: str='{fileroot}.RPC', warp_options: dict=None):
fileroot, extension = splitext(input_filename)
rpc_file_glob = rpc_file_template.format(
......@@ -141,6 +157,10 @@ def world_georef():
pass
def no_op(input_filename: os.PathLike, target_filename: os.PathLike):
# does not perform any operation
# configure as last step if you want other geotransform method to either pass or fail and then perform no other
shutil.move(input_filename, target_filename)
def gcps_from_borders(size: Tuple[float, float], coords: List[Tuple[float, float]], orbit_direction: str, force_north_up: bool=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment