Raster to DGGS
Raster to DGGS conversion functions.
This submodule provides functions to convert raster data to various discrete global grid systems (DGGS).
raster2olc_cli()
¶
Command line interface for raster to OLC conversion
Source code in vgrid/conversion/raster2dggs/raster2olc.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
raster2qtm_cli()
¶
Command line interface for raster2qtm conversion
Source code in vgrid/conversion/raster2dggs/raster2qtm.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
raster2rhealpix_cli()
¶
Command line interface for raster2rhealpix
Source code in vgrid/conversion/raster2dggs/raster2rhealpix.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
Raster to H3 Module
Convert raster data to H3 DGGS using either:
- binning — pixel centroids are aggregated into H3 cells (
statsrequired). - nearest_neighbour — H3 grid over the raster bbox; each cell takes the value of the nearest raster pixel center (LAEA planar distance).
get_nearest_h3_resolution(raster_path)
¶
Automatically determine the optimal H3 resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate H3 resolution that best matches the raster's spatial resolution.
Source code in vgrid/conversion/raster2dggs/raster2h3.py
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 | |
raster2h3(raster_path, resolution=None, output_format='gpd', fix_antimeridian=None, method='binning', stats='mean')
¶
Convert raster data to H3 DGGS format.
Parameters¶
raster_path : str
Path to the raster file (must have a defined CRS).
resolution : int, optional
H3 resolution [0..15]. If None, matched to pixel size.
output_format : str, optional
See :func:~vgrid.utils.io.convert_to_output_format.
fix_antimeridian : str, optional
Passed to H3 grid / geometry builders.
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation when multiple pixels map
to one H3 cell (see RASTER_STATS_OPTIONS). Ignored for nearest_neighbour.
Source code in vgrid/conversion/raster2dggs/raster2h3.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
Raster to S2 Module
This module provides functionality to convert raster data to S2 DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_s2_resolution(raster_path)
¶
Automatically determine the optimal S2 resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate S2 resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal S2 resolution level
Examples¶
cell_size, resolution = get_nearest_s2_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 5
Source code in vgrid/conversion/raster2dggs/raster2s2.py
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 106 107 108 109 110 111 112 | |
raster2s2(raster_path, resolution=None, output_format='gpd', fix_antimeridian=None, method='binning', stats='mean')
¶
Convert raster data to S2 DGGS format.
Converts raster data to S2 DGGS format with automatic resolution determination and multi-band support. Each pixel is assigned to an S2 cell and the first sample value per cell is preserved.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
S2 resolution level. If None, automatically determined based on raster pixel size.
Valid range: 0-30.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
fix_antimeridian : str, optional
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none
Defaults to None when omitted.
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents an S2 cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2s2("data.tif") print(f"Converted {len(result)} S2 cells")
Convert with specific resolution¶
result = raster2s2("data.tif", resolution=10)
Convert to GeoJSON file¶
result = raster2s2("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2s2.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
Raster to A5 Module
This module provides functionality to convert raster data to A5 DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_a5_resolution(raster_path)
¶
Automatically determine the optimal A5 resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate A5 resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal A5 resolution level
Examples¶
cell_size, resolution = get_nearest_a5_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 5
Source code in vgrid/conversion/raster2dggs/raster2a5.py
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 106 107 108 109 110 111 | |
raster2a5(raster_path, resolution=None, output_format='gpd', options=None, split_antimeridian=False, method='binning', stats='mean')
¶
Convert raster data to A5 DGGS format.
Converts raster data to A5 (Adaptive 5) DGGS format with automatic resolution determination and multi-band support.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
A5 resolution level. If None, automatically determined based on raster pixel size.
Valid range: 0-15.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
options : dict, optional
Options for a52geo.
split_antimeridian : bool, optional
When True, apply antimeridian fixing to the resulting polygons.
Defaults to False when None or omitted.
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents an A5 cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2a5("data.tif") print(f"Converted {len(result)} A5 cells")
Convert with specific resolution¶
result = raster2a5("data.tif", resolution=5)
Convert to GeoJSON file¶
result = raster2a5("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2a5.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
Raster to RHEALPix Module
This module provides functionality to convert raster data to RHEALPix (Rectified HEALPix) DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_rhealpix_resolution(raster_path)
¶
Automatically determine the optimal RHEALPix resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate RHEALPix resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal RHEALPix resolution level
Examples¶
cell_size, resolution = get_nearest_rhealpix_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 5
Source code in vgrid/conversion/raster2dggs/raster2rhealpix.py
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 106 107 108 109 110 111 112 113 114 115 | |
raster2rhealpix(raster_path, resolution=None, output_format='gpd', fix_antimeridian=None, method='binning', stats='mean')
¶
Convert raster data to RHEALPix DGGS format.
Converts raster data to RHEALPix (Rectified HEALPix) DGGS format with automatic resolution determination and multi-band support.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
RHEALPix resolution level. If None, automatically determined based on raster pixel size.
Valid range: 0-30.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
fix_antimeridian : str, optional
Antimeridian fixing method: shift, shift_balanced, shift_west, shift_east, split, none
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns¶
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents a RHEALPix cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2rhealpix("data.tif") print(f"Converted {len(result)} RHEALPix cells")
Convert with specific resolution¶
result = raster2rhealpix("data.tif", resolution=10)
Convert to GeoJSON file¶
result = raster2rhealpix("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2rhealpix.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
raster2rhealpix_cli()
¶
Command line interface for raster2rhealpix
Source code in vgrid/conversion/raster2dggs/raster2rhealpix.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
Raster to DGGAL Module
Convert raster data to DGGAL DGGS using either binning or nearest-neighbour assignment.
get_nearest_dggal_resolution(dggs_type, raster_path)
¶
Automatically determine the optimal DGGAL resolution for a given raster.
Source code in vgrid/conversion/raster2dggs/raster2dggal.py
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 | |
raster2dggal(dggs_type, raster_path, resolution=None, output_format='gpd', split_antimeridian=False, method='binning', stats='mean')
¶
Convert raster data to DGGAL DGGS format.
Parameters¶
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning" (see RASTER_STATS_OPTIONS).
Source code in vgrid/conversion/raster2dggs/raster2dggal.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
Raster to DGGRID Module
Convert raster data to DGGRID DGGS using either binning or nearest-neighbour assignment.
get_nearest_dggrid_resolution(dggrid_instance, dggs_type, raster_path)
¶
Automatically determine the optimal DGGRID resolution for a given raster.
Source code in vgrid/conversion/raster2dggs/raster2dggrid.py
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 | |
raster2dggrid(dggrid_instance, dggs_type, raster_path, resolution=None, output_format='gpd', split_antimeridian=False, aggregate=False, options=None, method='binning', stats='mean')
¶
Convert raster data to DGGRID DGGS format.
Parameters¶
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning" (see RASTER_STATS_OPTIONS).
Source code in vgrid/conversion/raster2dggs/raster2dggrid.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
Raster to ISEA4T Module
Convert raster data to ISEA4T DGGS using either binning or nearest-neighbour assignment.
Note: This module is only supported on Windows systems due to OpenEaggr dependency.
get_nearest_isea4t_resolution(raster_path)
¶
Automatically determine the optimal ISEA4T resolution for a given raster.
Source code in vgrid/conversion/raster2dggs/raster2isea4t.py
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 | |
raster2isea4t(raster_path, resolution=None, output_format='gpd', fix_antimeridian=None, method='binning', stats='mean')
¶
Convert raster data to ISEA4T DGGS format.
Parameters¶
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning" (see RASTER_STATS_OPTIONS).
Source code in vgrid/conversion/raster2dggs/raster2isea4t.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
Raster to QTM Module
This module provides functionality to convert raster data to QTM (Quaternary Triangular Mesh) DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_qtm_resolution(raster_path)
¶
Automatically determine the optimal QTM resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate QTM resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal QTM resolution level
Examples¶
cell_size, resolution = get_nearest_qtm_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 5
Source code in vgrid/conversion/raster2dggs/raster2qtm.py
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 106 107 108 | |
raster2qtm(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to QTM DGGS format.
Converts raster data to QTM (Quaternary Triangular Mesh) DGGS format with automatic resolution determination and multi-band support. Each pixel is assigned to a QTM cell and the first sample value per cell is preserved.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
QTM resolution level. If None, automatically determined based on raster pixel size.
Valid range: 1-30.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns¶
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents a QTM cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2qtm("data.tif") print(f"Converted {len(result)} QTM cells")
Convert with specific resolution¶
result = raster2qtm("data.tif", resolution=10)
Convert to GeoJSON file¶
result = raster2qtm("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2qtm.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
raster2qtm_cli()
¶
Command line interface for raster2qtm conversion
Source code in vgrid/conversion/raster2dggs/raster2qtm.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
Raster to OLC Module
This module provides functionality to convert raster data to OLC (Open Location Code) DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_olc_resolution(raster_path)
¶
Automatically determine the optimal OLC resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate OLC resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal OLC resolution level
Examples¶
cell_size, resolution = get_nearest_olc_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 8
Source code in vgrid/conversion/raster2dggs/raster2olc.py
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 106 107 | |
raster2olc(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to OLC DGGS format.
Converts raster data to OLC (Open Location Code) DGGS format with automatic resolution determination and multi-band support. Each pixel is assigned to an OLC cell and the first sample value per cell is preserved.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
OLC resolution level. If None, automatically determined based on raster pixel size.
Valid values: see olc_resolutions in vgrid.utils.io.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns¶
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents an OLC cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2olc("data.tif") print(f"Converted {len(result)} OLC cells")
Convert with specific resolution¶
result = raster2olc("data.tif", resolution=8)
Convert to GeoJSON file¶
result = raster2olc("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2olc.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
raster2olc_cli()
¶
Command line interface for raster to OLC conversion
Source code in vgrid/conversion/raster2dggs/raster2olc.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
Raster to Geohash Module
This module provides functionality to convert raster data to Geohash DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_geohash_resolution(raster_path)
¶
Automatically determine the optimal Geohash resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate Geohash resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal Geohash resolution level
Examples¶
cell_size, resolution = get_nearest_geohash_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 5
Source code in vgrid/conversion/raster2dggs/raster2geohash.py
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 106 107 108 109 | |
raster2geohash(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to Geohash DGGS format.
Converts raster data to Geohash DGGS format with automatic resolution determination and multi-band support.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
Geohash resolution level. If None, automatically determined based on raster pixel size.
Valid range: 1-12.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns¶
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents a Geohash cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2geohash("data.tif") print(f"Converted {len(result)} Geohash cells")
Convert with specific resolution¶
result = raster2geohash("data.tif", resolution=5)
Convert to GeoJSON file¶
result = raster2geohash("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2geohash.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
Raster to GEOREF Module
Convert raster pixels to GEOREF cells using either binning or nearest-neighbour assignment.
get_nearest_georef_resolution(raster_path)
¶
Pick a GEOREF resolution whose typical cell area is closest to the raster pixel area (m²).
Source code in vgrid/conversion/raster2dggs/raster2georef.py
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 | |
raster2georef(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to GEOREF DGGS format.
Parameters¶
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning" (see RASTER_STATS_OPTIONS).
Source code in vgrid/conversion/raster2dggs/raster2georef.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
Raster to Tilecode Module
This module provides functionality to convert raster data to Tilecode DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_tilecode_resolution(raster_path)
¶
Automatically determine the optimal Tilecode resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate Tilecode resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal Tilecode resolution level
Examples¶
cell_size, resolution = get_nearest_tilecode_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 5
Source code in vgrid/conversion/raster2dggs/raster2tilecode.py
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 106 107 108 109 110 111 | |
raster2tilecode(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to Tilecode DGGS format.
Converts raster data to Tilecode DGGS format with automatic resolution determination and multi-band support. Each pixel is assigned to a Tilecode cell and the first sample value per cell is preserved.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
Tilecode resolution level. If None, automatically determined based on raster pixel size.
Valid range: 0-26.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns¶
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents a Tilecode cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2tilecode("data.tif") print(f"Converted {len(result)} Tilecode cells")
Convert with specific resolution¶
result = raster2tilecode("data.tif", resolution=10)
Convert to GeoJSON file¶
result = raster2tilecode("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2tilecode.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
Raster to Quadkey Module
This module provides functionality to convert raster data to Quadkey DGGS format with automatic resolution determination and multi-band support.
Key Functions
get_nearest_quadkey_resolution(raster_path)
¶
Automatically determine the optimal Quadkey resolution for a given raster.
Analyzes the raster's pixel size and determines the most appropriate Quadkey resolution that best matches the raster's spatial resolution.
Parameters¶
raster_path : str Path to the raster file to analyze.
Returns¶
tuple A tuple containing (cell_size, resolution) where: - cell_size: The calculated cell size in square meters - resolution: The optimal Quadkey resolution level
Examples¶
cell_size, resolution = get_nearest_quadkey_resolution("data.tif") print(f"Cell size: {cell_size} m², Resolution: {resolution}") Cell size: 1000000.0 m², Resolution: 5
Source code in vgrid/conversion/raster2dggs/raster2quadkey.py
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 106 107 108 109 110 | |
raster2quadkey(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to Quadkey DGGS format.
Converts raster data to Quadkey DGGS format with automatic resolution determination and multi-band support. Each pixel is assigned to a Quadkey cell and the first sample value per cell is preserved.
Parameters¶
raster_path : str
Path to the raster file to convert.
resolution : int, optional
Quadkey resolution level. If None, automatically determined based on raster pixel size.
Valid range: 0-29.
output_format : str, default "gpd"
Output format. Options:
- "gpd": Returns GeoPandas GeoDataFrame (default)
- "csv": Returns CSV file path
- "geojson": Returns GeoJSON file path
- "geojson_dict": Returns GeoJSON FeatureCollection as Python dict
- "parquet": Returns Parquet file path
- "shapefile"/"shp": Returns Shapefile file path
- "gpkg"/"geopackage": Returns GeoPackage file path
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning": per-cell aggregation (see RASTER_STATS_OPTIONS).
Returns¶
geopandas.GeoDataFrame or str or dict The converted data in the specified format. Each row represents a Quadkey cell with geometry and band values from the original raster.
Examples¶
Convert with automatic resolution¶
result = raster2quadkey("data.tif") print(f"Converted {len(result)} Quadkey cells")
Convert with specific resolution¶
result = raster2quadkey("data.tif", resolution=10)
Convert to GeoJSON file¶
result = raster2quadkey("data.tif", output_format="geojson") print(f"Saved to: {result}")
Source code in vgrid/conversion/raster2dggs/raster2quadkey.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
Raster to Maidenhead Module
Convert raster pixels to Maidenhead locator cells using either binning or nearest-neighbour assignment.
get_nearest_maidenhead_resolution(raster_path)
¶
Pick a Maidenhead resolution whose typical cell area is closest to the raster pixel area (m²).
Source code in vgrid/conversion/raster2dggs/raster2maidenhead.py
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 | |
raster2maidenhead(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to Maidenhead DGGS format.
Parameters¶
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning" (see RASTER_STATS_OPTIONS).
Source code in vgrid/conversion/raster2dggs/raster2maidenhead.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
Raster to GARS Module
Convert raster pixels to GARS cells using either binning or nearest-neighbour assignment.
get_nearest_gars_resolution(raster_path)
¶
Pick a GARS resolution whose typical cell area is closest to the raster pixel area (m²).
Source code in vgrid/conversion/raster2dggs/raster2gars.py
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 | |
raster2gars(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to GARS DGGS format.
Parameters¶
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning" (see RASTER_STATS_OPTIONS).
Source code in vgrid/conversion/raster2dggs/raster2gars.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
Raster to DIGIPIN Module
Convert raster data to DIGIPIN DGGS using either:
- binning — pixel centroids aggregated into DIGIPIN cells (
statsrequired). - nearest_neighbour — DIGIPIN grid over the raster bbox; each cell takes the nearest raster pixel center.
get_nearest_digipin_resolution(raster_path)
¶
Automatically determine the optimal DIGIPIN resolution for a given raster.
Source code in vgrid/conversion/raster2dggs/raster2digipin.py
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 | |
raster2digipin(raster_path, resolution=None, output_format='gpd', method='binning', stats='mean')
¶
Convert raster data to DIGIPIN DGGS format.
Parameters¶
raster_path : str
Path to the raster file.
resolution : int, optional
DIGIPIN resolution [1..10]. If None, matched to pixel size.
output_format : str, optional
See :func:~vgrid.utils.io.convert_to_output_format.
method : str, optional
"binning" (default) or "nearest_neighbour" (see RASTER2DGGS_METHODS).
stats : str, optional
Used when method="binning" (see RASTER_STATS_OPTIONS).
Source code in vgrid/conversion/raster2dggs/raster2digipin.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |