Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
geom = feat.GetGeometryRef()
print('Geometry of feature 1:', geom)
###############################################
# convert the shapefile to geojson
###############################################
gjfile = shapefile.split(".")[0]+".geojson"
com = "ogr2ogr -f GeoJSON -t_srs crs:84 " + gjfile + " " + shapefile
flag = os.system(com)
if flag == 0:
print('Shapefile converted to Geojson format: ' + gjfile)
else:
print('Error converting shaoefile to Geojson')
# convert the geojson to wkt for the API search
footprint = geojson_to_wkt(read_geojson(gjfile))
# old code to open a geojson file directly
# with open(geojsonfile) as f:
# polydata = gj.load(f)
###############################################
# search the ESA Sentinel data hub
###############################################
# set query parameters
query_kwargs = {
'area': footprint,
'platformname': 'Sentinel-1',
'producttype': 'GRD',
# orbitdirection='ASCENDING'),
'date': (datefrom, dateto),
search_kwargs["instrumentshortname"] = instrument
if producttype:
search_kwargs["producttype"] = producttype
if cloud:
if sentinel not in ["2", "3"]:
logger.error("Cloud cover is only supported for Sentinel 2 and 3.")
exit(1)
search_kwargs["cloudcoverpercentage"] = (0, cloud)
if query is not None:
search_kwargs.update((x.split("=") for x in query))
if geometry is not None:
search_kwargs["area"] = geojson_to_wkt(read_geojson(geometry))
if uuid is not None:
uuid_list = [x.strip() for x in uuid]
products = {}
for productid in uuid_list:
try:
products[productid] = api.get_product_odata(productid)
except SentinelAPIError as e:
if "Invalid key" in e.msg:
logger.error("No product with ID '%s' exists on server", productid)
exit(1)
else:
raise
elif name is not None:
search_kwargs["identifier"] = name[0] if len(name) == 1 else "(" + " OR ".join(name) + ")"
products = api.query(order_by=order_by, limit=limit, **search_kwargs)
geom = feat.GetGeometryRef()
print('Geometry of feature 1:', geom)
###############################################
# convert the shapefile to geojson
###############################################
gjfile = shapefile.split(".")[0]+".geojson"
com = "ogr2ogr -f GeoJSON -t_srs crs:84 " + gjfile + " " + shapefile
flag = os.system(com)
if flag == 0:
print('Shapefile converted to Geojson format: ' + gjfile)
else:
print('Error converting shaoefile to Geojson')
# convert the geojson to wkt for the API search
footprint = geojson_to_wkt(read_geojson(gjfile))
# old code to open a geojson file directly
# with open(geojsonfile) as f:
# polydata = gj.load(f)
###############################################
# search the ESA Sentinel data hub
###############################################
# set query parameters
query_kwargs = {
'area': footprint,
'platformname': 'Sentinel-2',
'producttype': 'S2MSI1C',
# orbitdirection='ASCENDING'),
'date': (datefrom, dateto),
log.info('Start Date: %s', self.startdate)
log.info('End Date: %s', self.enddate)
log.info('Filter Max: %s', self.filter_max)
log.info('Order By: %s', self.order_by)
log.info('GeoJSON: %s', self.geojson_bbox)
log.info('Keywords: %s', self.keywords)
log.info('Now is: {}'.format( datetime.now() ))
log.info('6 hours ago was: {}'.format( datetime.now() - timedelta(hours=6)) )
print("Execute DHUS Search.. ")
# search products
api = SentinelAPI(self.dhus_user, self.dhus_pass, self.dhus_url)
try:
footprint = geojson_to_wkt(read_geojson(self.geojson_bbox))
except:
log.error('Cannot open GeoJSON file: {}'.format(self.geojson_bbox))
return False
products = api.query(
area=footprint,
date=(self.startdate, self.enddate),
order_by=self.order_by,
limit=self.filter_max,
**self.keywords
)
log.info("Retrieving {} products:".format(len(products)))
products_summary="\n"
for key, product in products.items():
products_summary+='ID: {}, {}\n'.format(key,product['summary'])
Parameters
----------
geojson_path
cloud
start_date
end_date
conf
Returns
-------
A dicitonary of products
"""
api = SentinelAPI(conf["sen2"]["user"], conf["sen2"]["pass"], 'https://scihub.copernicus.eu/dhus')
footprint = geojson_to_wkt(read_geojson(geojson_path))
products = api.query(footprint,
platformname = 'Sentinel-2',
cloudcoverpercentage = (0, cloud),
date = (start_date, end_date))
return products