Core — geocatalog¶
The names every catalog workflow touches: the GeoCatalog protocol
every backend satisfies, the GeoSlice catalogs are queried with and
loaders read on, the open_catalog factory, and cross-catalog set
algebra.
Protocol¶
geocatalog.GeoCatalog
¶
Bases: Protocol
A queryable spatiotemporal index over geospatial files.
Implementations carry a backend-specific store (in-memory GeoDataFrame; DuckDB+GeoParquet; future others) but expose the same query / intersect / union / iter-slices surface. Downstream code (loaders, the patch bridge, training loops) targets this Protocol, not a concrete class, so swapping the backend never touches the consumer.
Attributes:
| Name | Type | Description |
|---|---|---|
gdf |
GeoDataFrame
|
A |
kind |
CatalogKind
|
One of |
crs |
CRS
|
The catalog CRS as a |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
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 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 | |
temporal_extent
property
¶
Tightest interval that contains every row's time window.
Returns:
| Type | Description |
|---|---|
Interval | None
|
A |
Interval | None
|
to |
total_bounds
property
¶
Union bbox over all rows.
Returns:
| Type | Description |
|---|---|
float
|
|
float
|
NaNs if the catalog is empty. |
__len__()
¶
get_config()
¶
Return a JSON-serialisable summary — for logging / reproducibility audits.
The exact shape is backend-specific but always includes the backend tag, the row count, and the catalog CRS so two catalogs can be compared at a glance.
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
intersect(other, *, spatial_only=False)
¶
Cross-catalog AND — pair rows by spatial (+ temporal) overlap.
For each pair of rows whose footprints intersect, the result
contains one row with the clipped intersection footprint and the
intersected time interval. Pairs with disjoint intervals are
dropped unless spatial_only=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
GeoCatalog
|
The catalog to pair against. May use a different
backend; reprojection to |
required |
spatial_only
|
bool
|
If True, ignore the temporal axis. The right tool for pairing imagery with static labels (DEMs, land-cover maps) that have no meaningful time interval. |
False
|
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A new catalog with |
GeoCatalog
|
indexes the same kind of file as |
GeoCatalog
|
to footprints where |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
iter_rows(*, batch_size=1024)
¶
Yield rows as backend-neutral CatalogRow instances.
Consumed by loaders, the sampler, and the geopatcher
bridge. Backends should stream — for the DuckDB backend this
fetches in batches of batch_size; the in-memory backend
ignores batch_size and iterates the underlying gdf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_size
|
int
|
Rows per fetch for streaming backends. Default 1024. In-memory backends ignore this. |
1024
|
Yields:
| Type | Description |
|---|---|
CatalogRow
|
|
CatalogRow
|
in-memory backends; out-of-core backends should document |
CatalogRow
|
their ordering explicitly. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
iter_slices(*, resolution)
¶
Yield one GeoSlice per catalog row at the given resolution.
Each row's footprint becomes the slice's bbox; the row's
IntervalIndex entry becomes its interval. The slices are the
unit of work consumed by loaders and the CatalogDomain bridge
— emit them lazily so callers can short-circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
tuple[float, float]
|
Target |
required |
Yields:
| Type | Description |
|---|---|
GeoSlice
|
|
GeoSlice
|
in-memory backends; out-of-core backends should document |
GeoSlice
|
their ordering explicitly. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
query(slice_=None, *, bounds=None, crs=None, time=None)
¶
Spatial + temporal filter — return rows overlapping the query.
Two call shapes are supported: pass a GeoSlice (carries bounds,
time, and CRS together), or pass the parts. Bounds in a non-
catalog CRS are reprojected internally so an AOI in the wrong
CRS doesn't silently match zero rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_
|
GeoSlice | None
|
A |
None
|
bounds
|
tuple[float, float, float, float] | None
|
|
None
|
crs
|
Any | None
|
CRS of |
None
|
time
|
tuple[Any, Any] | Interval | None
|
Either a |
None
|
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A new catalog of the same backend tag containing only the |
GeoCatalog
|
matching rows. May be empty. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If both |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
union(other)
¶
Cross-catalog OR — concatenate rows.
Useful when you want to treat two sensors as one virtual dataset
(Landsat 7 + Landsat 8 for a long time series; S2A + S2B for
better revisit). other is reprojected into self.crs if
the CRSs differ; the result's backend tag is self's.
Backend tags are not checked — unioning a raster catalog with
a vector one will not raise, but the downstream loader you
eventually call will reject the mismatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
GeoCatalog
|
Catalog to concatenate. CRS is auto-reprojected. |
required |
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A new catalog containing every row of |
GeoCatalog
|
every (possibly reprojected) row of |
GeoCatalog
|
performed — call |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/base.py
GeoSlice¶
geocatalog.GeoSlice
dataclass
¶
A bounded request for data — produced by samplers, consumed by loaders.
Carries everything a loader needs to fetch a chip without consulting the catalog: bbox in CRS units, time interval, target resolution, CRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
tuple[float, float, float, float]
|
|
required |
interval
|
Interval
|
A |
required |
resolution
|
tuple[float, float]
|
|
required |
crs
|
CRS
|
A |
required |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/geoslice.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 112 113 114 115 116 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 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 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 | |
grid
property
¶
The output pixel grid: transform, crs and shape.
The grid every loader returns its geoarray.GeoArray on, so
load_raster(catalog, s).grid == s.grid.
Example
import pandas as pd s = GeoSlice( ... bounds=(500000.0, 4000000.0, 500640.0, 4000320.0), ... interval=pd.Interval( ... pd.Timestamp("2024-01-01"), pd.Timestamp("2024-01-31"), ... closed="both", ... ), ... resolution=(10.0, 10.0), ... crs="EPSG:32629", ... ) s.grid.shape, s.grid.bounds == s.bounds ((32, 64), True)
shape
property
¶
Output grid shape (height, width) from bounds + resolution.
Each axis is extent / resolution rounded half up, so an
extent of 10.5 pixels gives 11 on either axis. (Python's
built-in round is half-to-even and would give 10 on one
axis and 12 for 11.5 on the other.) Use aligned_shape to
reject non-integer extents instead.
transform
property
¶
North-up affine from bounds + resolution.
aligned_shape()
¶
Strict shape: raises on misalignment regardless of mode.
Use this when you need a guaranteed-exact pixel count without
flipping the constructor's default align mode. .shape
stays rounding-based (half up) for backwards compatibility with
existing loaders.
Raises:
| Type | Description |
|---|---|
ValueError
|
if either axis's extent is not an integer multiple of its resolution (within tolerance). |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/geoslice.py
to_crs(target_crs)
¶
Reproject this slice's bounds into target_crs.
The resolution is conservatively rescaled by the ratio of the
projected-vs-source bbox widths so the output shape stays
roughly stable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The reprojection produces a degenerate
or non-finite box — a pole-wrapping, antimeridian-adjacent,
or out-of-domain transform. Split or clip the slice first.
(Antimeridian-crossing input bounds are already rejected
at construction: |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/geoslice.py
Opening a catalog¶
geocatalog.open_catalog(source, *, kind=None, engine='auto', crs=None, storage_options=None, strict=False)
¶
Open a GeoParquet artifact as a GeoCatalog.
The factory picks an engine. "auto" prefers the DuckDB backend
(lazy, scales) when the [duckdb] extra is installed; otherwise it
falls back to the in-memory backend via from_geoparquet. Pass
engine="memory" to force the eager path even with DuckDB present.
The artifact's stored kind (the _backend column written
by to_geoparquet) is honoured by default — pass kind=...
only to override a wrong tag or to tag an externally produced
artifact that lacks the column. Forcing a default would silently
miscategorise xarray / vector catalogs and break loader dispatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
Path or URI to a GeoParquet file. A directory of shards
( |
required |
kind
|
CatalogKind | None
|
Loader dispatch tag ( |
None
|
engine
|
_ENGINE_T
|
|
'auto'
|
crs
|
Any | None
|
Optional CRS override for either engine. It relabels the footprints (no reprojection) — use it for artifacts whose GeoParquet metadata lacks or misstates the CRS. |
None
|
storage_options
|
dict[str, Any] | None
|
obstore store options for reading cloud URIs
through the in-memory engine ( |
None
|
strict
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A |
GeoCatalog
|
|
GeoCatalog
|
resolved engine. |
"auto" also falls back to the in-memory engine, with a warning,
when DuckDB is installed but its spatial extension cannot be
loaded (e.g. offline), since every spatial query would fail.
Raises:
| Type | Description |
|---|---|
ImportError
|
|
ValueError
|
|
Source code in packages/geotoolz-catalog/src/geocatalog/_src/factory.py
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
Set algebra¶
geocatalog.query(catalog, slice_=None, *, bounds=None, crs=None, time=None)
¶
Filter catalog by space + time and return the matching rows.
Two call shapes: pass a GeoSlice (carries bounds, time, and CRS
together) or pass the parts. Bounds in a non-catalog CRS are
reprojected internally — the canonical anti-footgun path (§10.1 of
the design plan) for AOIs in the wrong projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog
|
GeoCatalog
|
Any |
required |
slice_
|
GeoSlice | None
|
A |
None
|
bounds
|
tuple[float, float, float, float] | None
|
|
None
|
crs
|
Any | None
|
CRS of |
None
|
time
|
tuple[Any, Any] | Interval | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A new catalog of the same backend tag, possibly empty. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If both |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/ops.py
geocatalog.intersect(left, right, *, spatial_only=False)
¶
Cross-catalog AND — rows from left paired with overlapping rows in right.
For each pair of rows whose footprints intersect, the result has
one row with the clipped intersection geometry and the intersected
time interval. Disjoint-time pairs are dropped unless
spatial_only=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
GeoCatalog
|
Catalog whose backend tag the result will carry. The "imagery side" of an imagery / labels pairing. |
required |
right
|
GeoCatalog
|
Catalog to pair against. Auto-reprojected to |
required |
spatial_only
|
bool
|
Skip the temporal filter — the right tool for pairing imagery with static labels (DEMs, land cover) that have no meaningful time interval. |
False
|
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A new catalog with |
GeoCatalog
|
clipped-and-time-aligned rows. May be empty. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/ops.py
geocatalog.union(left, right)
¶
Cross-catalog OR — concatenate left and right into one catalog.
The typical use is treating two sensors as one virtual dataset
(Landsat 7 + Landsat 8, S2A + S2B). right is reprojected into
left.crs if the CRSs differ; the result's backend tag comes
from left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
GeoCatalog
|
Catalog whose backend tag + CRS win. |
required |
right
|
GeoCatalog
|
Catalog to concatenate; auto-reprojected if needed. |
required |
Returns:
| Type | Description |
|---|---|
GeoCatalog
|
A new catalog with every row of |
GeoCatalog
|
(possibly reprojected) row of |
GeoCatalog
|
performed — call |