안녕하세요. 이전 블로그에서 단일 밴드 래스터에 대해 h3 인덱스와 postgresql을 사용하여 래스터 분석을 수행하는 방법에 대해 이야기했습니다. 이 블로그에서는 멀티밴드 래스터를 처리하고 쉽게 인덱스를 생성하는 방법에 대해 설명합니다. sentinel-2 이미지를 사용하고 처리된 h3 셀에서 NDVI를 생성하고 결과를 시각화합니다
네팔 포카라 지역의 https://apps.sentinel-hub.com/eo-browser/에서 sentinel 2 데이터를 다운로드하고 있습니다. 호수가 이미지 그리드에 있는지 확인하여 쉽게 확인할 수 있습니다. NDVI 결과를 검증해 보세요
모든 밴드의 센티넬 이미지를 다운로드하려면 :
또한 NDVI, False color tiff only 또는 특정 밴드 등 필요에 가장 적합한 사전 생성된 색인을 다운로드할 수도 있습니다. 처리는 저희가 직접 하고 싶어서 밴드를 다 다운받고 있어요
원시 형식을 다운로드할 때 모든 밴드를 센티넬과 별도의 tiff로 얻습니다
이 작업은 GIS 도구나 gdal을 통해 수행할 수 있습니다
파일 이름에 슬래시가 들어가지 않도록 다운로드한 파일의 이름을 band1,band2로 바꿔야 합니다
이 연습에서는 밴드 9까지 처리하겠습니다. 요구 사항에 따라 밴드를 선택할 수 있습니다
gdal_merge.py -separate -o sentinel2_composite.tif band1.tif band2.tif band3.tif band4.tif band5.tif band6.tif band7.tif band8.tif band9.tif
gdalwarp -overwrite -dstnodata 0 "$input_file" "${output_file}_nodata.tif"
gdal_translate -of COG "$input_file" "$output_file"
cog2h3 저장소에 제공된 bash 스크립트를 사용하여 이를 자동화하고 있습니다
sudo bash pre.sh sentinel2_composite.tif
이제 마지막으로 전처리 스크립트를 완료했으므로 합성 톱니바퀴 이미지의 각 밴드에 대해 h3 셀을 계산해 보겠습니다.
pip install cog2h3
export DATABASE_URL="postgresql://user:password@host:port/database"
우리는 이 감시 이미지에 해상도 10을 사용하고 있지만 스크립트 자체에서 h3 셀을 래스터의 가장 작은 픽셀보다 작게 만드는 래스터에 대한 최적의 해상도를 인쇄하는 것을 볼 수 있습니다.
cog2h3 --cog sentinel2_composite_preprocessed.tif --table sentinel --multiband --res 10
postgresql에서 결과를 계산하고 저장하는 데 1분 정도 걸렸습니다.
로그 :
2024-08-24 08:39:43,233 - INFO - Starting processing 2024-08-24 08:39:43,234 - INFO - COG file already exists at sentinel2_composite_preprocessed.tif 2024-08-24 08:39:43,234 - INFO - Processing raster file: sentinel2_composite_preprocessed.tif 2024-08-24 08:39:43,864 - INFO - Determined Min fitting H3 resolution for band 1: 11 2024-08-24 08:39:43,865 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:44,037 - INFO - Resampling Done for band 1 2024-08-24 08:39:44,037 - INFO - New Native H3 resolution for band 1: 10 2024-08-24 08:39:44,738 - INFO - Calculation done for res:10 band:1 2024-08-24 08:39:44,749 - INFO - Determined Min fitting H3 resolution for band 2: 11 2024-08-24 08:39:44,749 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:44,757 - INFO - Resampling Done for band 2 2024-08-24 08:39:44,757 - INFO - New Native H3 resolution for band 2: 10 2024-08-24 08:39:45,359 - INFO - Calculation done for res:10 band:2 2024-08-24 08:39:45,366 - INFO - Determined Min fitting H3 resolution for band 3: 11 2024-08-24 08:39:45,366 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:45,374 - INFO - Resampling Done for band 3 2024-08-24 08:39:45,374 - INFO - New Native H3 resolution for band 3: 10 2024-08-24 08:39:45,986 - INFO - Calculation done for res:10 band:3 2024-08-24 08:39:45,994 - INFO - Determined Min fitting H3 resolution for band 4: 11 2024-08-24 08:39:45,994 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:46,003 - INFO - Resampling Done for band 4 2024-08-24 08:39:46,003 - INFO - New Native H3 resolution for band 4: 10 2024-08-24 08:39:46,605 - INFO - Calculation done for res:10 band:4 2024-08-24 08:39:46,612 - INFO - Determined Min fitting H3 resolution for band 5: 11 2024-08-24 08:39:46,612 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:46,619 - INFO - Resampling Done for band 5 2024-08-24 08:39:46,619 - INFO - New Native H3 resolution for band 5: 10 2024-08-24 08:39:47,223 - INFO - Calculation done for res:10 band:5 2024-08-24 08:39:47,230 - INFO - Determined Min fitting H3 resolution for band 6: 11 2024-08-24 08:39:47,230 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:47,239 - INFO - Resampling Done for band 6 2024-08-24 08:39:47,239 - INFO - New Native H3 resolution for band 6: 10 2024-08-24 08:39:47,829 - INFO - Calculation done for res:10 band:6 2024-08-24 08:39:47,837 - INFO - Determined Min fitting H3 resolution for band 7: 11 2024-08-24 08:39:47,837 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:47,845 - INFO - Resampling Done for band 7 2024-08-24 08:39:47,845 - INFO - New Native H3 resolution for band 7: 10 2024-08-24 08:39:48,445 - INFO - Calculation done for res:10 band:7 2024-08-24 08:39:48,453 - INFO - Determined Min fitting H3 resolution for band 8: 11 2024-08-24 08:39:48,453 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:48,461 - INFO - Resampling Done for band 8 2024-08-24 08:39:48,461 - INFO - New Native H3 resolution for band 8: 10 2024-08-24 08:39:49,046 - INFO - Calculation done for res:10 band:8 2024-08-24 08:39:49,054 - INFO - Determined Min fitting H3 resolution for band 9: 11 2024-08-24 08:39:49,054 - INFO - Resampling original raster to: 200.786148m 2024-08-24 08:39:49,062 - INFO - Resampling Done for band 9 2024-08-24 08:39:49,063 - INFO - New Native H3 resolution for band 9: 10 2024-08-24 08:39:49,647 - INFO - Calculation done for res:10 band:9 2024-08-24 08:39:51,435 - INFO - Converting H3 indices to hex strings 2024-08-24 08:39:51,906 - INFO - Overall raster calculation done in 8 seconds 2024-08-24 08:39:51,906 - INFO - Creating or replacing table sentinel in database 2024-08-24 08:40:03,153 - INFO - Table sentinel created or updated successfully in 11.25 seconds. 2024-08-24 08:40:03,360 - INFO - Processing completed
이제 postgresql에 데이터가 있으므로 분석을 해보겠습니다.
select * from sentinel
explain analyze select h3_ix , (band8-band4)/(band8+band4) as ndvi from public.sentinel
쿼리 계획 :
QUERY PLAN | -----------------------------------------------------------------------------------------------------------------+ Seq Scan on sentinel (cost=0.00..28475.41 rows=923509 width=16) (actual time=0.014..155.049 rows=923509 loops=1)| Planning Time: 0.080 ms | Execution Time: 183.764 ms |
As you can see here for all the rows in that area the calculation is instant . This is true for all other indices and you can compute complex indices join with other tables using the h3_ix primary key and derive meaningful result out of it without worrying as postgresql is capable of handling complex queries and table join.
Lets visualize and verify if the computed indices are true
create table ndvi_sentinel as( select h3_ix , (band8-band4)/(band8+band4) as ndvi from public.sentinel )
ALTER TABLE ndvi_sentinel ADD COLUMN geometry geometry(Polygon, 4326) GENERATED ALWAYS AS (h3_cell_to_boundary_geometry(h3_ix)) STORED;
create index on ndvi_sentinel(geometry);
As we know value between -1.0 to 0.1 should represent Deep water or dense clouds
lets see if thats true ( making first category as transparent to see the underlying image )
As there were clouds around the lake hence nearby fields are covered by cloud which makes sense
Thank you for reading ! See you in next blog
위 내용은 멀티밴드 래스터 처리(Sentinel-hndex 및 인덱스 생성)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!