From 954e52ac3da448458c52c903bf930751d9c68d01 Mon Sep 17 00:00:00 2001 From: xhong Date: Thu, 9 Jan 2025 21:37:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=88=AC=E5=8F=96=E6=97=B6=E6=9C=AC=E5=9C=B0ROI=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=94=A8=E4=BA=8E=E6=95=B0=E6=8D=AE=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HLS_SuPER/HLS_SuPER.py | 11 +++++++---- README.md | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/HLS_SuPER/HLS_SuPER.py b/HLS_SuPER/HLS_SuPER.py index 53deb7c..d9b635a 100644 --- a/HLS_SuPER/HLS_SuPER.py +++ b/HLS_SuPER/HLS_SuPER.py @@ -23,6 +23,7 @@ import time import json import earthaccess +from shapely import Polygon from shapely.geometry import polygon, box import geopandas as gpd from datetime import datetime as dt @@ -178,22 +179,24 @@ def format_roi(roi): Returns a geopandas dataframe for clipping and a list of vertices for searching. """ if os.path.isfile(roi): # and roi.endswith(("geojson", "shp")): - print(roi) try: # Open ROI if file roi = gpd.read_file(roi) - if len(roi) > 1: + # (Add) 添加对多种几何图形类型的支持, 将MultiPolygon合并为Polygon + if len(roi) > 1 or roi.geometry[0].geom_type == "MultiPolygon": # Merge all Polygon geometries and create external boundary logging.info( "Multiple polygons detected. Creating single geometry of external coordinates." ) single_geometry = roi.unary_union.convex_hull roi = gpd.GeoDataFrame(geometry=[single_geometry], crs=roi.crs) - logging.info(roi) # Check if ROI is in Geographic CRS, if not, convert to it if roi.crs.is_geographic: # List Vertices in correct order for search - vertices_list = list(roi.geometry[0].exterior.coords) + # (Add) 使用外包矩形坐标作为检索使用的坐标 + minx, miny, maxx, maxy = roi.total_bounds + bounding_box = box(minx, miny, maxx, maxy) + vertices_list = list(bounding_box.exterior.coords) else: roi_geographic = roi.to_crs("EPSG:4326") diff --git a/README.md b/README.md index 612d743..e8a8fcf 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ mamba activate lpdaac_windows ### 3.2 脚本可用参数 -- `-roi`:感兴趣区,需要按照 **左下右上** 的逆时针顺序设置点坐标 +- `-roi`:感兴趣区,需要按照 **左下右上** 的逆时针顺序设置点坐标,同时还支持 `shp` 与 `geojson/json` 格式文件 - `-clip`:是否对影像进行裁剪,默认 `False` - `-tile`:HLS影像瓦片ID,例如 `T49RGQ` - `-dir`:输出目录,必须是已存在的目录 @@ -146,8 +146,8 @@ python .\\HLS_SuPER\\HLS_SuPER.py -roi '112.9834,30.5286,114.32373,31.64448' -ti python .\\HLS_SuPER\\HLS_SuPER.py -roi '112.9834,30.5286,114.32373,31.64448' -tile T49RGQ -dir .\\data\\HLS\\L30\\TIR -start 2024-01-01 -end 2024-01-31 -prod HLSL30 -bands TIR1,TIR2,Fmask -scale True ``` -- 【测试用】不进行云量筛选,直接爬取 L30 2024 年暑期光谱波段与热红外波段 +- 【测试用】根据给定的范围文件 `*.geojson`,不进行云量筛选,直接爬取 L30 与 S30 2024 年的核心光谱波段 ```sh -python .\\HLS_SuPER\\HLS_SuPER.py -roi '112.9834,30.5286,114.32373,31.64448' -tile T49RGQ -dir .\\data\\HLS\\L30\\subset\\2024 -start 2024-06-01 -end 2024-08-31 -prod HLSL30 -bands BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,TIR1,TIR2,Fmask -scale True +python .\\HLS_SuPER\\HLS_SuPER.py -roi .\\data\\vectors\\wuling_guanqu_polygon.geojson -tile T49RGQ -dir .\\data\\HLS\\ALL\\2024 -start 2024-06-01 -end 2024-09-01 -prod both -bands BLUE,GREEN,RED,NIR1,SWIR1,SWIR2,Fmask -scale True ```