Commit 99f4c263 authored by Mario Chirinos's avatar Mario Chirinos

MultyPolygon

parent 30c6cf08
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
""" """
Install: Install:
$ sudo pip install sentinelsat $ sudo pip3 install sentinelsat
$ sudo apt-get install libgdal-dev $ sudo apt-get install libgdal-dev
Example: Example:
......
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys, os import sys, os
import json import json
########### lee archivo de configuración ################ ############ lee archivo de configuración ################
dirname = os.path.dirname(__file__) dirname = os.path.dirname(__file__)
configfile = os.path.join(dirname, '../config/config.json') configfile = os.path.join(dirname, '../config/config.json')
...@@ -17,11 +17,11 @@ with open(configfile, 'r') as f: ...@@ -17,11 +17,11 @@ with open(configfile, 'r') as f:
SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL'] SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL']
########################################################### ###########################################################
sys.path.append(SENTINEL_PATH) sys.path.append(SENTINEL_PATH)
from geosentinel import APISentinel from geosentinel import APISentinel
from geosentinel import polygonToBox from geosentinel import polygonToBox
from osgeo import ogr
from datetime import date from datetime import date
from collections import OrderedDict
#def findSentinelProducts(wkt, startDate, endDate, platform, cloud): #def findSentinelProducts(wkt, startDate, endDate, platform, cloud):
# sentinel = APISentinel.APISentinel('asalazarg', 'geo135asg') # sentinel = APISentinel.APISentinel('asalazarg', 'geo135asg')
...@@ -39,13 +39,28 @@ def main(argv): ...@@ -39,13 +39,28 @@ def main(argv):
cfg = json.loads(jsonFile) cfg = json.loads(jsonFile)
sentinel = APISentinel.APISentinel(cfg['username'], cfg['password']) sentinel = APISentinel.APISentinel(cfg['username'], cfg['password'])
geometry = ogr.CreateGeometryFromWkt(cfg['wkt'])
wktList = []
if geometry.GetGeometryType() == ogr.wkbPolygon:
wkt = polygonToBox.getWKTPolygonBoundingBox(cfg['wkt'], True) wkt = polygonToBox.getWKTPolygonBoundingBox(cfg['wkt'], True)
productList = sentinel.getProducts(wkt, (cfg['startDate'], cfg['endDate']), {"producttype":productType[cfg["productLevel"]], "platformname":cfg['platform'], "cloudcoverpercentage":"[0 TO "+str(cfg['clouds'])+"]"}, "Contains") wktList.append(wkt)
print(wkt)
elif geometry.GetGeometryType() == ogr.wkbMultiPolygon:
for i in range(0, geometry.GetGeometryCount()):
g = geometry.GetGeometryRef(i).exportToWkt()
wkt = polygonToBox.getWKTPolygonBoundingBox(g, True)
print(wkt)
wktList.append(wkt)
productList = OrderedDict()
for wkt in wktList:
tmpList =sentinel.getProducts(wkt, (cfg['startDate'], cfg['endDate']), {"producttype":productType[cfg["productLevel"]], "platformname":cfg['platform'], "cloudcoverpercentage":"[0 TO "+str(cfg['clouds'])+"]"}, "Contains")
if len(productList)<=0: if len(productList)<=0:
print ("No products found with 'Contains' trying with 'Intersects'") print ("No products found with 'Contains' trying with 'Intersects'")
productList = sentinel.getProducts(wkt, (cfg['startDate'], cfg['endDate']), {"producttype":productType[cfg["productLevel"]], "platformname":cfg['platform'], "cloudcoverpercentage":"[0 TO "+str(cfg['clouds'])+"]"}) tmpList = sentinel.getProducts(wkt, (cfg['startDate'], cfg['endDate']), {"producttype":productType[cfg["productLevel"]], "platformname":cfg['platform'], "cloudcoverpercentage":"[0 TO "+str(cfg['clouds'])+"]"})
productList.update(tmpList)
# fileNames = [productList[k]['filename'].replace("SAFE", "zip").replace(productsCodes[cfg['productLevel']], cfg['productLevel']) for k in productList.keys() ] # fileNames = [productList[k]['filename'].replace("SAFE", "zip").replace(productsCodes[cfg['productLevel']], cfg['productLevel']) for k in productList.keys() ]
fileNames = [productList[k]['filename'].replace("SAFE", "zip") for k in productList.keys() ] fileNames = [productList[k]['filename'].replace("SAFE", "zip") for k in productList.keys() ]
...@@ -56,11 +71,9 @@ def main(argv): ...@@ -56,11 +71,9 @@ def main(argv):
print ( str(len(matchingProducts))+" of " + str(len(fileNames)) +" "+ cfg["productLevel"] + " products found.") print ( str(len(matchingProducts))+" of " + str(len(fileNames)) +" "+ cfg["productLevel"] + " products found.")
# rawDir = inDir.replace(cfg['productLevel'],productsCodes[cfg['productLevel']]) # rawDir = inDir.replace(cfg['productLevel'],productsCodes[cfg['productLevel']])
# print(rawDir)
text ="" text =""
while text != "yes" and text != "no": while text != "yes" and text != "no":
text = raw_input("Do you want to download this products to "+downloadDir+ " ? (yes, no)") text = input("Do you want to download this products to "+downloadDir+ " ? (yes, no)")
if text=="yes": if text=="yes":
sentinel.downloadProducts(productList,downloadDir) sentinel.downloadProducts(productList,downloadDir)
...@@ -87,7 +100,7 @@ def main(argv): ...@@ -87,7 +100,7 @@ def main(argv):
print ( str(len(matchingProducts))+" of " + str(len(fileNames)) +" L1C products found in L2A.") print ( str(len(matchingProducts))+" of " + str(len(fileNames)) +" L1C products found in L2A.")
text ="" text =""
while text != "yes" and text != "no": while text != "yes" and text != "no":
text = raw_input("Do you want to convert this products and save them to "+downloadDir+ " ? (yes, no)") text = input("Do you want to convert this products and save them to "+downloadDir+ " ? (yes, no)")
if text=="yes": if text=="yes":
#print("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1") #print("L1CProductListToL2A.sh "+rawDir+" "+inDir+" 1")
os.system("L1CProductListToL2A.sh "+linksDir+" "+L2ADir+" 1") os.system("L1CProductListToL2A.sh "+linksDir+" "+L2ADir+" 1")
...@@ -95,7 +108,7 @@ def main(argv): ...@@ -95,7 +108,7 @@ def main(argv):
text ="" text =""
linksDir=cfg["projectDir"]+"L2A/" linksDir=cfg["projectDir"]+"L2A/"
while text != "yes" and text != "no": while text != "yes" and text != "no":
text = raw_input("Do you want to link this products to "+linksDir+ " ? (yes, no)") text = input("Do you want to link this products to "+linksDir+ " ? (yes, no)")
if text=="yes": if text=="yes":
fileNames = [productList[k]['filename'].replace("SAFE", "zip").replace("L1C", "L2A") for k in productList.keys() ] fileNames = [productList[k]['filename'].replace("SAFE", "zip").replace("L1C", "L2A") for k in productList.keys() ]
......
#!/usr/bin/python #!/usr/bin/python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
from osgeo import ogr from osgeo import ogr
...@@ -19,8 +19,9 @@ def getWKTPolygonBoundingBox(polygon, wkt=False): ...@@ -19,8 +19,9 @@ def getWKTPolygonBoundingBox(polygon, wkt=False):
>>> print (g) >>> print (g)
-89.96360136135893 21.295577631081912 -89.24078398227726 20.754157792347172 -89.96360136135893 21.295577631081912 -89.24078398227726 20.754157792347172
''' '''
geometry = ogr.CreateGeometryFromWkt(polygon)
box = ogr.CreateGeometryFromWkt(polygon).GetEnvelope() #(minX, maxX, minY, maxY) box = geometry.GetEnvelope() #(minX, maxX, minY, maxY)
ulx = box[0] ulx = box[0]
uly = box[3] uly = box[3]
lrx = box[1] lrx = box[1]
......
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