EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit 67d61165 authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Improving footprint extraction and GSC generation

parent 933650f2
No related branches found
No related tags found
No related merge requests found
from textwrap import dedent
from osgeo import gdal
def positions_to_poslist(positions, projection):
......@@ -9,26 +10,40 @@ def positions_to_poslist(positions, projection):
for pair in positions
])
def get_footprint_from_browse(browse):
def positions_from_corners(low, high):
minx, miny = low
maxx, maxy = high
return [
(minx, miny),
(maxx, miny),
(maxx, maxy),
(minx, maxy),
(minx, minx),
]
def get_footprint_from_browse(data_file, browse):
btype = browse['browse_type']
if btype == 'rectified_browse':
low, high = browse['rectified']['coord_list']
minx, miny = low
maxx, maxy = high
positions = [
(minx, miny),
(maxx, miny),
(maxx, maxy),
(minx, maxy),
(minx, minx),
]
positions = positions_from_corners(low, high)
elif btype == 'footprint_browse':
positions = browse['footprint']
elif btype == 'model_in_geotiff_browse':
# TODO: read from input dataset
raise NotImplementedError('Model in geotiff browses are not supported')
ds = gdal.Open(data_file)
gt = ds.GetGeoTransform()
width, height = ds.RasterXSize, ds.RasterXSize
low = (gt[0], gt[3] + gt[5] * height)
high = (gt[0] + gt[1] * width, gt[3])
positions = positions_from_corners(low, high)
elif btype == 'regular_grid_browse':
raise NotImplementedError('Regular grid browses are not supported')
......
......@@ -45,6 +45,7 @@ import subprocess
from urllib.parse import urlparse
from urllib.request import urlretrieve
from datetime import datetime
import json
from swiftclient.multithreading import OutputManager
from swiftclient.service import SwiftError, SwiftService, SwiftUploadObject
......@@ -361,7 +362,7 @@ class BrowseReportPreprocessor(BasePreprocessor):
'begin_time': browse['start_time'],
'end_time': browse['end_time'],
'product_type': browse['browse_type'],
'footprint': gsc_generator.get_footprint_from_browse(browse)
'footprint': gsc_generator.get_footprint_from_browse(data_file, browse)
}
out_filename = join(tmpdir, splitext(basename(browse['filename']))[0] + '.xml')
......@@ -548,13 +549,19 @@ def preprocessor_redis_wrapper(
while True:
logger.debug("waiting for redis queue '%s'..." % preprocess_queue_key)
queue, value = client.brpop([preprocess_queue_key, preprocess_md_queue_key])
preprocessor(
collection,
value[1],
replace=replace,
client=client,
register_queue_key=register_queue_key
)
if queue == preprocess_md_queue_key:
preprocessor = BrowseReportPreprocessor(json.loads(value))
else:
preprocessor = PackagePreprocessor(value)
# preprocessor(
# collection,
# value[1],
# replace=replace,
# client=client,
# register_queue_key=register_queue_key
# )
if __name__ == "__main__":
......
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