Skip to content

Commit

Permalink
i.sentinel.download: catch WKT too long with -b flag (#56)
Browse files Browse the repository at this point in the history
i.sentinel.download: catch WKT too long with -b flag:

Rationale: RFC 2616 HTTP/1.1 imposes a 2000 char limit on WKT when sent via HTTP GET (sentinelsat).

Hence:
* raise fatal error when AOI map (-b flag) has too many vertices, recommending to use 'v.generalize' to simplify the boundaries
* check added if AOI map contains areas (by ninsbl)
* use vector_info_topo() from PyGRASS rather than GRASS Python scripting API
  • Loading branch information
neteler committed Nov 21, 2019
1 parent 3146712 commit f24fbb3
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,25 @@ def get_aoi(vector=None):
if vector:
args['input'] = vector

if gs.vector_info_topo(vector)['areas'] <= 0:
gs.fatal(_("No areas found in AOI map <{}>...").format(vector))
else:
gs.warning(_("More than one area found in AOI map <{}>. \
Using only the first area...").format(vector))

# are we in LatLong location?
s = gs.read_command("g.proj", flags='j')
kv = gs.parse_key_val(s)
if '+proj' not in kv:
gs.fatal('Unable to get AOI: unprojected location not supported')
geom_dict = gs.parse_command('v.out.ascii', format='wkt', **args)
geom = geom = [key for key in geom_dict][0]
num_vertices = len(str(geom_dict.keys()).split(','))
geom = [key for key in geom_dict][0]
if kv['+proj'] != 'longlat':
gs.message(_("Generating WKT from AOI map ({} vertices)...").format(num_vertices))
if num_vertices > 500:
gs.fatal(_("AOI map has too many vertices to be sent via HTTP GET (sentinelsat). \
Use 'v.generalize' to simplify the boundaries"))
coords = geom.replace('POLYGON((', '').replace('))', '').split(', ')
poly = 'POLYGON(('
poly_coords = []
Expand All @@ -184,6 +195,12 @@ def get_aoi(vector=None):
for key in coord_latlon:
poly_coords.append((' ').join(key.split('|')[0:2]))
poly += (', ').join(poly_coords) + '))'
# Note: poly must be < 2000 chars incl. sentinelsat request (see RFC 2616 HTTP/1.1)
if len(poly) > 1850:
gs.fatal(_("AOI map has too many vertices to be sent via HTTP GET (sentinelsat). \
Use 'v.generalize' to simplify the boundaries"))
else:
gs.message(_("Sending WKT from AOI map to ESA..."))
return poly
else:
return geom
Expand Down Expand Up @@ -277,7 +294,7 @@ def list(self):
else:
ccp = 'cloudcover_NA'

print ('{0} {1} {2} {3}'.format(
print('{0} {1} {2} {3}'.format(
self._products_df_sorted['uuid'][idx],
self._products_df_sorted['beginposition'][idx].strftime("%Y-%m-%dT%H:%M:%SZ"),
ccp,
Expand Down Expand Up @@ -390,7 +407,7 @@ def set_uuid(self, uuid_list):

def main():
user = password = None
api_url='https://scihub.copernicus.eu/dhus'
api_url = 'https://scihub.copernicus.eu/dhus'

if options['settings'] == '-':
# stdin
Expand Down

0 comments on commit f24fbb3

Please sign in to comment.