feat: 完善数据爬取时本地ROI文件用于数据筛选的支持.

This commit is contained in:
谢泓 2025-01-09 21:37:38 +08:00
parent 5ea6a1fb6e
commit 954e52ac3d
2 changed files with 10 additions and 7 deletions

View File

@ -23,6 +23,7 @@ import time
import json import json
import earthaccess import earthaccess
from shapely import Polygon
from shapely.geometry import polygon, box from shapely.geometry import polygon, box
import geopandas as gpd import geopandas as gpd
from datetime import datetime as dt 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. Returns a geopandas dataframe for clipping and a list of vertices for searching.
""" """
if os.path.isfile(roi): # and roi.endswith(("geojson", "shp")): if os.path.isfile(roi): # and roi.endswith(("geojson", "shp")):
print(roi)
try: try:
# Open ROI if file # Open ROI if file
roi = gpd.read_file(roi) 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 # Merge all Polygon geometries and create external boundary
logging.info( logging.info(
"Multiple polygons detected. Creating single geometry of external coordinates." "Multiple polygons detected. Creating single geometry of external coordinates."
) )
single_geometry = roi.unary_union.convex_hull single_geometry = roi.unary_union.convex_hull
roi = gpd.GeoDataFrame(geometry=[single_geometry], crs=roi.crs) roi = gpd.GeoDataFrame(geometry=[single_geometry], crs=roi.crs)
logging.info(roi)
# Check if ROI is in Geographic CRS, if not, convert to it # Check if ROI is in Geographic CRS, if not, convert to it
if roi.crs.is_geographic: if roi.crs.is_geographic:
# List Vertices in correct order for search # 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: else:
roi_geographic = roi.to_crs("EPSG:4326") roi_geographic = roi.to_crs("EPSG:4326")

View File

@ -114,7 +114,7 @@ mamba activate lpdaac_windows
### 3.2 脚本可用参数 ### 3.2 脚本可用参数
- `-roi`:感兴趣区,需要按照 **左下右上** 的逆时针顺序设置点坐标 - `-roi`:感兴趣区,需要按照 **左下右上** 的逆时针顺序设置点坐标,同时还支持 `shp``geojson/json` 格式文件
- `-clip`:是否对影像进行裁剪,默认 `False` - `-clip`:是否对影像进行裁剪,默认 `False`
- `-tile`HLS影像瓦片ID例如 `T49RGQ` - `-tile`HLS影像瓦片ID例如 `T49RGQ`
- `-dir`:输出目录,必须是已存在的目录 - `-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 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 ```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
``` ```