Build — geocatalog.build¶
Index raster, array and vector files — local or in a bucket — into a catalog, and append new files to a saved one.
Raster¶
geocatalog.build.build_raster_catalog(filepaths, *, filename_regex=None, date_format='%Y%m%d', crs=None, engine='memory', out_path=None, write_bbox=True, sort_by=('start_time', 'geometry_hilbert'), partition_by=None, batch_size=10000, n_workers=1, ordered=False, storage_options=None, concurrency='sequential', max_concurrent=8)
¶
Build a raster catalog — in-memory (default) or streamed to GeoParquet.
For each input file, opens it with rasterio, extracts its bounds
(optionally projected through a lazy WarpedVRT if crs
is set so no pixels are read), and parses the time interval from
the filename via filename_regex. The result is a catalog
queryable in milliseconds even over tens of thousands of files —
rasterio builds the spatial R-tree lazily on first access.
Files whose filenames don't match the regex are skipped with a warning, not raised — so a heterogeneous directory partially populated by one product still produces a usable catalog.
Two backends:
engine="memory"(default): collects rows into agpd.GeoDataFrameand returns anInMemoryGeoCatalog. Peak RAM isO(n_rows). Good up to ~10⁵ files.engine="duckdb": streams rows through apyarrow.parquet.ParquetWriterdirectly toout_path, then sorts via DuckDB(start_time, ST_Hilbert(ST_Centroid(geometry)))for row-group pruning. Peak RAM isO(batch_size). Scales to 10⁶+ files. Returns aDuckDBGeoCatalogopened on the freshly written artifact. Requires the[duckdb]extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepaths
|
Sequence[str | Path]
|
Files to index. Anything |
required |
filename_regex
|
str | None
|
A regex with a named group capturing the date:
either |
None
|
date_format
|
str
|
|
'%Y%m%d'
|
crs
|
Any | None
|
CRS to project each file's bounds into. |
None
|
engine
|
StorageEngine
|
|
'memory'
|
out_path
|
str | Path | None
|
Destination GeoParquet path. Required when
|
None
|
write_bbox
|
bool
|
Emit the GeoParquet 1.1 per-row |
True
|
sort_by
|
tuple[str, ...] | None
|
Sort keys for the post-write DuckDB rewrite. Each
plain column name passes through; the literal token
|
('start_time', 'geometry_hilbert')
|
partition_by
|
tuple[str, ...] | None
|
Optional Hive partition columns for directory
output when |
None
|
batch_size
|
int
|
Rows per Arrow record batch in the streaming
writer. Default 10 000. Only consulted when
|
10000
|
n_workers
|
int
|
Process-pool size for per-file metadata extraction.
|
1
|
ordered
|
bool
|
With |
False
|
concurrency
|
_Concurrency
|
Extraction strategy for the |
'sequential'
|
max_concurrent
|
int
|
Maximum in-flight file extractions when
|
8
|
Returns:
| Type | Description |
|---|---|
InMemoryGeoCatalog | DuckDBGeoCatalog
|
|
InMemoryGeoCatalog | DuckDBGeoCatalog
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
No files matched (or |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/raster.py
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 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 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
Xarray (extras: [xarray-raster])¶
geocatalog.build.build_xarray_catalog(filepaths, *, crs=None, data_vars=None, time_var='time', engine='memory', out_path=None, write_bbox=True, sort_by=('start_time', 'geometry_hilbert'), partition_by=None, batch_size=10000, n_workers=1, ordered=False, storage_options=None)
¶
Build an xarray-shaped catalog — in-memory (default) or streamed.
For each input file, opens it with xr.open_dataset, derives the
spatial footprint from the min/max of its (x, y) / (lon, lat) /
(longitude, latitude) coordinates, and reads the time interval from
the time_var coordinate. If rioxarray is loaded and the
dataset carries a CRS through its rio accessor, that wins;
otherwise the catalog falls back to crs.
Backends mirror build_raster_catalog. The streaming branch
(engine="duckdb") requires the [duckdb] extra and an
explicit crs — unlike the raster builder, xarray
coordinate bounds are not reprojected, so the CRS metadata must
match the dataset's native coords. Passing crs=None in
the duckdb branch raises ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepaths
|
Sequence[str | Path]
|
Files to index. |
required |
crs
|
Any | None
|
CRS to tag the catalog with when files don't carry
their own. Coordinate bounds are not reprojected — there's
no |
None
|
data_vars
|
Sequence[str] | None
|
Subset of data variables recorded per row. Loaders
consult this to pick which arrays to materialise. |
None
|
time_var
|
str
|
Coordinate name for the time axis. Default |
'time'
|
engine
|
StorageEngine
|
|
'memory'
|
out_path
|
str | Path | None
|
Destination GeoParquet path. Required when
|
None
|
write_bbox
|
bool
|
Emit the GeoParquet 1.1 covering |
True
|
sort_by
|
tuple[str, ...] | None
|
Sort keys for the post-write DuckDB rewrite; literal
|
('start_time', 'geometry_hilbert')
|
partition_by
|
tuple[str, ...] | None
|
Optional Hive partition columns for directory
output when |
None
|
batch_size
|
int
|
Rows per Arrow record batch. Default 10 000. |
10000
|
n_workers
|
int
|
Process-pool size for per-file extraction. |
1
|
ordered
|
bool
|
With |
False
|
Returns:
| Type | Description |
|---|---|
InMemoryGeoCatalog | DuckDBGeoCatalog
|
|
InMemoryGeoCatalog | DuckDBGeoCatalog
|
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
ValueError
|
If no files yielded a row or |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/xarray_backend.py
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 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 | |
Model states (extras: [xarray-raster])¶
geocatalog.build.build_state_catalog(filepaths, *, crs=None, names=CF_NAMES, data_vars=None, engine='memory', out_path=None, write_bbox=True, sort_by=('start_time', 'geometry_hilbert'), batch_size=10000, n_workers=1, storage_options=None)
¶
Index model-state files: one row per file, with the state columns filled.
Each file is indexed like build_xarray_catalog does (footprint from
the coordinates, valid-time interval from the time axis), and the
reserved state columns are read from its metadata through names:
kind, run_time, member, producer and parents. A
field that is not found is null. Lead time is not stored: a row's
leads are its valid times minus run_time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepaths
|
Sequence[str | Path]
|
NetCDF / Zarr files, one run and member each. |
required |
crs
|
Any | None
|
CRS of the files' coordinates, when they don't carry one (coordinates are not reprojected). |
None
|
names
|
StateNames
|
Where each field lives: a mapping from |
CF_NAMES
|
data_vars
|
Sequence[str] | None
|
Data variables recorded per row (as in
|
None
|
engine
|
StorageEngine
|
|
'memory'
|
out_path
|
str | Path | None
|
Destination GeoParquet path for |
None
|
write_bbox
|
bool
|
Emit the GeoParquet 1.1 |
True
|
sort_by
|
tuple[str, ...] | None
|
Sort keys for the DuckDB rewrite ( |
('start_time', 'geometry_hilbert')
|
batch_size
|
int
|
Rows per Arrow record batch ( |
10000
|
n_workers
|
int
|
Process-pool size for per-file extraction
( |
1
|
storage_options
|
dict[str, Any] | None
|
obstore options for remote files ( |
None
|
Returns:
| Type | Description |
|---|---|
InMemoryGeoCatalog | DuckDBGeoCatalog
|
A catalog of kind |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the |
ValueError
|
If no file was given, the CRS is unknown, a file's
|
Example
from geocatalog.build import build_state_catalog from geocatalog.states import CF_NAMES catalog = build_state_catalog(paths, crs="EPSG:4326", names=CF_NAMES) catalog.gdf[["kind", "run_time", "member"]].iloc[0].tolist() ['forecast', Timestamp('2026-01-01 00:00:00'), '0']
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/states.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 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 280 281 282 | |
Vector¶
geocatalog.build.build_vector_catalog(filepaths, *, filename_regex=None, date_format='%Y%m%d', crs=None, layer=None, engine='memory', out_path=None, write_bbox=True, sort_by=('start_time', 'geometry_hilbert'), partition_by=None, batch_size=10000, n_workers=1, ordered=False, storage_options=None)
¶
Build a vector catalog — in-memory (default) or streamed to GeoParquet.
For each input file, opens it with geopandas.read_file, optionally
reprojects to crs, and records the file's
total_bounds polygon as the catalog footprint. Time is parsed
from the filename via filename_regex, mirroring
build_raster_catalog. Empty files and non-matching filenames are
skipped with a warning.
Backends mirror build_raster_catalog:
engine="memory"(default): collects rows into a gdf and returns anInMemoryGeoCatalog. First-non-empty file's native CRS latches the catalog CRS whencrs=None.engine="duckdb": streams rows to a GeoParquet atout_pathand returns aDuckDBGeoCatalog. CRS-latching is disabled — every file is reprojected tocrs(EPSG:4326 by default). Requires the[duckdb]extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepaths
|
Sequence[str | Path]
|
Files to index. Anything |
required |
filename_regex
|
str | None
|
A regex with a |
None
|
date_format
|
str
|
|
'%Y%m%d'
|
crs
|
Any | None
|
CRS for footprint + storage. For |
None
|
layer
|
str | int | None
|
Layer name or index for multi-layer files (GeoPackage,
GDB). |
None
|
engine
|
StorageEngine
|
|
'memory'
|
out_path
|
str | Path | None
|
Destination GeoParquet path. Required when
|
None
|
write_bbox
|
bool
|
Emit the GeoParquet 1.1 covering |
True
|
sort_by
|
tuple[str, ...] | None
|
Sort keys for the post-write DuckDB rewrite; literal
|
('start_time', 'geometry_hilbert')
|
partition_by
|
tuple[str, ...] | None
|
Optional Hive partition columns for directory
output when |
None
|
batch_size
|
int
|
Rows per Arrow record batch. Default 10 000. |
10000
|
n_workers
|
int
|
Process-pool size for per-file extraction. |
1
|
ordered
|
bool
|
With |
False
|
Returns:
| Type | Description |
|---|---|
InMemoryGeoCatalog | DuckDBGeoCatalog
|
|
InMemoryGeoCatalog | DuckDBGeoCatalog
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no files yielded a row, or |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/formats/vector.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 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 274 275 276 277 278 279 280 | |
Appending to a saved catalog¶
geocatalog.build.append_files(archive, filepaths, extract_fn, *, crs, kind, partition_by, write_bbox=True, batch_size=10000, n_workers=1, max_open_writers=_DEFAULT_MAX_OPEN_WRITERS)
¶
Append new files to a Hive-partitioned GeoParquet archive.
Only the new rows are extracted and written; existing shards are left
untouched, so append work is O(N_new) plus the number of new
partitions touched (and one read of the archive's filepath
column). The archive is created if it does not exist.
Appending is idempotent: files whose filepath is already indexed
in the archive (or repeated within filepaths) are skipped, so
re-running the same call — including after an interruption that left
only some of the new shards moved in — never duplicates rows; it
completes the append instead.
Before any rows are written, the caller-supplied partition_by is
validated against the archive's existing layout (the directory tree
of key=value dirs). A mismatch raises ValueError rather than
silently producing a mixed-layout archive that downstream readers
can't reconstruct cleanly. A fresh archive (no existing shards)
accepts the caller's partition_by as the source of truth.
New shards are written at the archive's _schema_version, so a
pre-upgrade (v0) archive stays at a single version after an append
and keeps opening: an archive is upgraded as a whole, never shard by
shard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
str | Path
|
Hive-partitioned GeoParquet directory. |
required |
filepaths
|
Sequence[str | Path]
|
New source files to index. |
required |
extract_fn
|
Callable[[str | Path], dict[str, Any] | None]
|
Picklable per-file extractor, same contract as
|
required |
crs
|
Any
|
CRS to encode in the new shard metadata. |
required |
kind
|
CatalogKind
|
Catalog kind (loader dispatch). |
required |
partition_by
|
Sequence[str]
|
Hive partition columns. |
required |
write_bbox
|
bool
|
Emit the GeoParquet 1.1 |
True
|
batch_size
|
int
|
Rows per Arrow record batch. |
10000
|
n_workers
|
int
|
Process-pool size for extraction. |
1
|
max_open_writers
|
int
|
Cap on concurrently open shard writers; see
|
_DEFAULT_MAX_OPEN_WRITERS
|
Returns:
| Type | Description |
|---|---|
DuckDBGeoCatalog
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
CatalogSchemaError
|
The archive's shards are newer than the reader, or already at mixed versions. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/storage/streaming.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 | |