Commit 9785a4b0 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

fixed another issue related to an AOI crossing the dateline

misc.database_tools:
- get_pgSQL_geospatial_query_cond(): implemented new keyword 'crossing_dateline_check'
- updated __version__
Former-commit-id: 45f4b9af
Former-commit-id: e859d44d
parent f5eea438
...@@ -15,7 +15,7 @@ from . import config ...@@ -15,7 +15,7 @@ from . import config
from .processing.process_controller import process_controller from .processing.process_controller import process_controller
__version__ = '20170330.01' __version__ = '20170330.02'
__author__ = 'Daniel Scheffler' __author__ = 'Daniel Scheffler'
__all__ = ['algorithms', __all__ = ['algorithms',
'io', 'io',
......
...@@ -377,7 +377,7 @@ def get_dem_by_extent(cornerCoords_tgt, prj, tgt_xgsd, tgt_ygsd): ...@@ -377,7 +377,7 @@ def get_dem_by_extent(cornerCoords_tgt, prj, tgt_xgsd, tgt_ygsd):
#from py_tools_ds.ptds.geo.projection import EPSG2WKT #from py_tools_ds.ptds.geo.projection import EPSG2WKT
#prj = EPSG2WKT(32612) #prj = EPSG2WKT(32612)
# handle coordinates directly above 180 degress meridian # handle coordinates crossing the 180 degress meridian
xvals = [x for x,y in tgt_corner_coord_lonlat] xvals = [x for x,y in tgt_corner_coord_lonlat]
if max(xvals) - min(xvals) >180: if max(xvals) - min(xvals) >180:
tgt_corner_coord_lonlat = [(x, y) if x > 0 else (x + 360, y) for x, y in tgt_corner_coord_lonlat] tgt_corner_coord_lonlat = [(x, y) if x > 0 else (x + 360, y) for x, y in tgt_corner_coord_lonlat]
......
...@@ -347,10 +347,17 @@ def create_record_in_postgreSQLdb(conn_params, tablename, vals2write_dict, timeo ...@@ -347,10 +347,17 @@ def create_record_in_postgreSQLdb(conn_params, tablename, vals2write_dict, timeo
def get_pgSQL_geospatial_query_cond(conn_params, table2query, geomCol2use='bounds', tgt_corners_lonlat=None, def get_pgSQL_geospatial_query_cond(conn_params, table2query, geomCol2use='bounds', tgt_corners_lonlat=None,
scene_ID=None, queryfunc = 'ST_Intersects'): scene_ID=None, queryfunc = 'ST_Intersects', crossing_dateline_check=True):
assert tgt_corners_lonlat if scene_ID is None else scene_ID, "Provide eihter scene_ID or tgt_corners_lonlat!" assert tgt_corners_lonlat if scene_ID is None else scene_ID, "Provide eihter scene_ID or tgt_corners_lonlat!"
if tgt_corners_lonlat: if tgt_corners_lonlat:
# handle coordinates crossing the 180 degress meridian (dateline)
# FIXME in that case the polygone has to be split at the dateline. otherwise pgSQL may yield wrong results
if crossing_dateline_check:
xvals = [x for x, y in tgt_corners_lonlat]
if max(xvals) - min(xvals) > 180:
tgt_corners_lonlat = [(x, y) if x > 0 else (x + 360, y) for x, y in tgt_corners_lonlat]
from .helper_functions import cornerLonLat_to_postgreSQL_poly from .helper_functions import cornerLonLat_to_postgreSQL_poly
pGSQL_poly = cornerLonLat_to_postgreSQL_poly(tgt_corners_lonlat) pGSQL_poly = cornerLonLat_to_postgreSQL_poly(tgt_corners_lonlat)
src_geom = "'SRID=4326;%s'::geometry" %pGSQL_poly # source geometry is given src_geom = "'SRID=4326;%s'::geometry" %pGSQL_poly # source geometry is given
...@@ -409,7 +416,8 @@ def get_overlapping_scenes_from_postgreSQLdb(conn_params, table='scenes_proc', s ...@@ -409,7 +416,8 @@ def get_overlapping_scenes_from_postgreSQLdb(conn_params, table='scenes_proc', s
refcond = ['scenes.datasetid = %s' %datasetid] refcond = ['scenes.datasetid = %s' %datasetid]
geocond = [get_pgSQL_geospatial_query_cond(conn_params, table, tgt_corners_lonlat=tgt_corners_lonlat, geocond = [get_pgSQL_geospatial_query_cond(conn_params, table, tgt_corners_lonlat=tgt_corners_lonlat,
scene_ID=scene_ID, queryfunc='ST_Intersects')] scene_ID=scene_ID, queryfunc='ST_Intersects',
crossing_dateline_check=True)]
join = "INNER JOIN scenes ON (%s.sceneid = scenes.id) " %table if table != 'scenes' and datasetids else '' join = "INNER JOIN scenes ON (%s.sceneid = scenes.id) " %table if table != 'scenes' and datasetids else ''
conditions = [c for c in conditions if not c.startswith('datasetid')] conditions = [c for c in conditions if not c.startswith('datasetid')]
...@@ -441,7 +449,8 @@ def get_overlapping_MGRS_tiles(conn_params, scene_ID=None, tgt_corners_lonlat=No ...@@ -441,7 +449,8 @@ def get_overlapping_MGRS_tiles(conn_params, scene_ID=None, tgt_corners_lonlat=No
# geocond3 = get_pgSQL_geospatial_query_cond(conn_params, 'mgrs_tiles', geomCol2use='geom', queryfunc='ST_Within', # geocond3 = get_pgSQL_geospatial_query_cond(conn_params, 'mgrs_tiles', geomCol2use='geom', queryfunc='ST_Within',
# tgt_corners_lonlat=tgt_corners_lonlat, scene_ID=scene_ID) # tgt_corners_lonlat=tgt_corners_lonlat, scene_ID=scene_ID)
geocond = get_pgSQL_geospatial_query_cond(conn_params, 'mgrs_tiles', geomCol2use='geom', queryfunc='ST_Intersects', geocond = get_pgSQL_geospatial_query_cond(conn_params, 'mgrs_tiles', geomCol2use='geom', queryfunc='ST_Intersects',
tgt_corners_lonlat=tgt_corners_lonlat, scene_ID=scene_ID) tgt_corners_lonlat=tgt_corners_lonlat, scene_ID=scene_ID,
crossing_dateline_check=True)
#query = "SELECT %s FROM %s WHERE %s OR %s OR %s" % (', '.join(vals2get), 'mgrs_tiles', geocond1, geocond2,geocond3) #query = "SELECT %s FROM %s WHERE %s OR %s OR %s" % (', '.join(vals2get), 'mgrs_tiles', geocond1, geocond2,geocond3)
query = "SELECT %s FROM %s WHERE %s" % (', '.join(vals2get), 'mgrs_tiles', geocond) query = "SELECT %s FROM %s WHERE %s" % (', '.join(vals2get), 'mgrs_tiles', geocond)
cursor = connection.cursor() cursor = connection.cursor()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment