-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsh_grid_builder.sh
More file actions
executable file
·105 lines (89 loc) · 2.8 KB
/
Copy pathsh_grid_builder.sh
File metadata and controls
executable file
·105 lines (89 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Example of usage
#./sh_grid_builder.sh -i data/aoi.geojson -r "10,10" -p 3035 -t bounding-box -o output_bbox.gpkg
#./sh_grid_builder.sh -i data/aoi.geojson -r "(300,359)" -p 32632 -t pixelated -o output_pixelated.gpkg
#developed by Maxim Lamare (2026)
###############################
version="0.2.2"
usage()
{
cat << EOF
#usage: $0 options
This utility generates projection grid aligned bounding boxes and pixelated geometries
from AOI (Area of Interest) files for Sentinel Hub Batch V2 API on CDSE.
It wraps the sh-batch-grid-builder Python package.
OPTIONS:
-p EPSG code for the output CRS (e.g., 3035 for ETRS89 / LAEA Europe, 4326 for WGS84)
-h help message
-i path to input AOI file (GeoJSON, GPKG, or other formats supported by GeoPandas)
-o path to output file (GPKG format required)
-r grid resolution as "(x,y)" or "x,y" in CRS coordinate units (e.g., "10,10" for 10 meters)
-t output type: bounding-box or pixelated
-v version
EXAMPLES:
# Generate aligned bounding box with same resolution for x and y
$0 -i aoi.geojson -r "10,10" -p 3035 -t bounding-box -o output_bbox.gpkg
# Generate aligned bounding box with different x and y resolutions
$0 -i aoi.geojson -r "(300,359)" -p 32632 -t bounding-box -o output_bbox.gpkg
# Generate pixelated geometry
$0 -i aoi.geojson -r "10,10" -p 3035 -t pixelated -o output_pixelated.gpkg
# Example with geographic CRS (degrees)
$0 -i aoi.geojson -r "(0.001,0.001)" -p 4326 -t bounding-box -o output_bbox.gpkg
EOF
}
while getopts "hp:i:o:r:t:v" OPTION; do
case $OPTION in
p)
epsg=$OPTARG
;;
h)
usage
exit 0
;;
i)
input_aoi=$OPTARG
;;
o)
output=$OPTARG
;;
r)
resolution=$OPTARG
;;
t)
output_type=$OPTARG
;;
v)
echo sh_grid_builder version $version
exit 0
;;
?)
usage
exit 1
;;
esac
done
if [ -z $(which sh-grid-builder) ]; then
echo "ERROR: sh-grid-builder not found. Please install it: pip install sh-batch-grid-builder" && exit 2
fi
if [ -z "$input_aoi" ]; then
echo "ERROR: Input AOI file not specified" && exit 3
fi
if [ ! -f "$input_aoi" ]; then
echo "ERROR: Input AOI file '$input_aoi' does not exist" && exit 4
fi
if [ -z "$resolution" ]; then
echo "ERROR: Resolution not specified" && exit 3
fi
if [ -z "$epsg" ]; then
echo "ERROR: EPSG code not specified" && exit 3
fi
if [ -z "$output_type" ]; then
echo "ERROR: Output type not specified" && exit 3
fi
if [ "$output_type" != "bounding-box" -a "$output_type" != "pixelated" ]; then
echo "ERROR: Output type '$output_type' not valid. Must be 'bounding-box' or 'pixelated'" && exit 3
fi
if [ -z "$output" ]; then
echo "ERROR: Output file not specified" && exit 3
fi
sh-grid-builder "$input_aoi" --resolution "$resolution" --epsg $epsg --output-type $output_type -o "$output"