NSI (US flood exposure & loss) — API reference#
US object-level flood exposure and loss subpackage — earthlens.nsi.
Background and usage are covered under the other pages in this section
(Introduction, Usage); this page is the
rendered API. All three sources are public, so there is no auth module.
earthlens.nsi
#
US object-level flood exposure & loss backend (earthlens.nsi).
One backend over three keyless US-federal REST sources, selected by a source=
discriminator:
structures(default) — USACE National Structure Inventory (NSI): building points with occupancy, replacement value, foundation type/height, and area;vector.nfhl— FEMA National Flood Hazard Layer: regulatory flood zones (FLD_ZONE,SFHA_TF) from the ArcGISS_Fld_Haz_Arlayer;vector.nfip— FEMA NFIP redacted claims (v3): flood-insurance claim records with paid amounts, via the OpenFEMA OData endpoint;tabular.
Output is per instance: the resolved source's output_kind decides whether
:meth:~earthlens.nsi.backend.NSI.download returns a pyramids
:class:~pyramids.feature.collection.FeatureCollection (structures/nfhl) or
a :class:pandas.DataFrame (nfip). All three are public-domain and keyless —
no auth. A spatial/attribute bound is required (no unbounded national pull),
and aggregate= is rejected (these are records, not gridded rasters).
The public surface is the :class:Catalog (source name -> endpoint + output kind
+ field map) and its :class:Source rows, the :class:NSI backend, and the pure
query/geometry helpers.
Catalog
#
Bases: AbstractCatalog[Source]
Source catalog for the NSI backend.
Reads the bundled nsi_data_catalog.yaml (shipped as package data) and
exposes its sources: block as a map of :class:Source rows keyed by
name. Instantiate with no arguments (Catalog()). Resolve one row with
:meth:get and list the shipped keys with :meth:available.
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, Source]
|
Map from source name to its :class: |
Examples:
- Resolve a source and read its output kind:
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
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 | |
available()
#
Return the sorted list of shipped source names.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Every catalog key, sorted. |
get(source_id)
#
Resolve a source name to its :class:Source row.
Thin wrapper over the inherited :meth:get_dataset, which raises a
ValueError with a did-you-mean hint on an unknown key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
A shipped source name ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Source |
Source
|
The matching catalog row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
load(catalog_path=None)
classmethod
#
Read the NSI catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the module-level
:data: |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file has no |
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
NSI
#
Bases: AbstractDataSource
US flood exposure / loss backend (per-instance output).
Resolves source= to its catalog row, issues the one bounded request that
source needs, and returns a
:class:~pyramids.feature.collection.FeatureCollection (structures/nfhl)
or a :class:pandas.DataFrame (nfip). US-only: a non-US box returns an
empty result, not an error (G4).
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
Set per instance in :meth: |
Source code in libs/providers/hazards/src/earthlens/nsi/backend.py
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 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 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
__init__(start=None, end=None, lat_lim=None, lon_lim=None, temporal_resolution='snapshot', path=None, fmt='%Y-%m-%d', source='structures', fips=None, filters=None, max_records=None, output_format='csv', session=None)
#
Initialise an NSI backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str | None
|
Inclusive start of an optional window, parsed with |
None
|
end
|
str | None
|
Inclusive end of the optional window; |
None
|
lat_lim
|
list[float] | None
|
|
None
|
lon_lim
|
list[float] | None
|
|
None
|
temporal_resolution
|
str
|
Recorded as the resolution label only. |
'snapshot'
|
path
|
Path | str | None
|
Output directory for a written tabular ( |
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
source
|
str
|
Which source to query — |
'structures'
|
fips
|
str | None
|
A 2/5/11/15-digit FIPS code selecting |
None
|
filters
|
dict[str, str | int] | None
|
NFIP attribute filter mapping — recognised keys are
|
None
|
max_records
|
int | None
|
Optional cap on the number of |
None
|
output_format
|
OutputFormat
|
On-disk format for the |
'csv'
|
session
|
Session | None
|
An existing |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/hazards/src/earthlens/nsi/backend.py
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 | |
download(progress_bar=True)
#
Fetch the selected source and return its per-instance shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Accepted for signature parity; one logical request is
issued (paged for |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DataFrame | FeatureCollection
|
class: |
DataFrame | FeatureCollection
|
|
|
DataFrame | FeatureCollection
|
|
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the upstream source returns a non-2xx status. |
Source code in libs/providers/hazards/src/earthlens/nsi/backend.py
Source
#
Bases: SummarisedLeaf
One NSI catalog row (one of the three flood sources).
The source name is the parent key in :attr:Catalog.datasets and is stored
on the row as :attr:id so a resolved :class:Source is self-describing.
Which fields matter depends on :attr:provider; a cross-field validator
enforces the source-specific ones (nfhl needs a layer, nfip a records
key).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The source name ( |
provider |
str
|
The upstream service — |
endpoint |
str
|
The base REST URL. |
output_kind |
OutputKind
|
|
long_name |
str
|
Human-readable label. |
citation |
str
|
The source's citation string, logged once on use. |
license |
str
|
The data licence (all three are US public domain). |
fields |
dict[str, str]
|
Friendly -> provider field-name map. For the tabular |
layer_id |
int | None
|
ArcGIS MapServer layer id ( |
layer_name |
str | None
|
ArcGIS layer name ( |
records_key |
str | None
|
JSON envelope key holding the record list ( |
page_size |
int | None
|
OData page size for paged fetches ( |
Examples:
- Build a source row directly:
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
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 | |
arcgis_envelope(lat_lim, lon_lim, out_fields='*')
#
Build the ArcGIS query parameters for the NFHL flood-zone layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
out_fields
|
str
|
Comma-separated attribute list to return ( |
'*'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The |
Examples:
- Build the query params for a box:
Source code in libs/providers/hazards/src/earthlens/nsi/geometry.py
bbox_from_limits(lat_lim, lon_lim)
#
Return (xmin, ymin, xmax, ymax) from lat_lim / lon_lim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, float]
|
tuple[float, float, float, float]: The envelope as
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If either limit is not a two-element |
Examples:
>>> from earthlens.nsi import bbox_from_limits
>>> bbox_from_limits([29.95, 29.96], [-90.07, -90.06])
(-90.07, 29.95, -90.06, 29.96)
Source code in libs/providers/hazards/src/earthlens/nsi/geometry.py
clear_catalog_cache()
#
Empty the module-level catalog parse cache.
Useful in tests that rewrite the catalog on disk and want to force a
re-parse. Production callers do not need this — the cache key includes the
file's st_mtime_ns, so any real edit invalidates the entry on its own.
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
nsi_polygon_body(lat_lim, lon_lim)
#
Build the GeoJSON-polygon body for an NSI structures POST.
The NSI ?bbox= query returns empty; the working AOI selector is a POST of
a GeoJSON FeatureCollection carrying one rectangle polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A GeoJSON |
Examples:
- Build a polygon body for a small box:
Source code in libs/providers/hazards/src/earthlens/nsi/geometry.py
to_feature_collection(geojson)
#
Wrap a GeoJSON FeatureCollection mapping into a pyramids collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geojson
|
dict
|
A GeoJSON mapping carrying a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FeatureCollection |
FeatureCollection
|
The features tagged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Wrap a one-feature GeoJSON and inspect the collection:
>>> from earthlens.nsi import to_feature_collection >>> fc = to_feature_collection( ... { ... "type": "FeatureCollection", ... "features": [ ... { ... "type": "Feature", ... "geometry": {"type": "Point", "coordinates": [-90.0, 29.9]}, ... "properties": {"occtype": "RES1"}, ... } ... ], ... } ... ) >>> len(fc) 1
Source code in libs/providers/hazards/src/earthlens/nsi/geometry.py
earthlens.nsi.backend
#
Backend for US object-level flood exposure & loss (earthlens.nsi).
NSI(AbstractDataSource) serves three keyless US-federal REST sources chosen by
a source= discriminator — structures (USACE National Structure Inventory),
nfhl (FEMA National Flood Hazard Layer), and nfip (FEMA NFIP redacted claims
v3) — and returns the shape that source declares.
Two design points carry this backend:
- Per-instance
OUTPUT_KIND(G1). The resolved source'soutput_kindis copied ontoself.OUTPUT_KINDin__init__:structures/nfhlreturn a pyramids :class:~pyramids.feature.collection.FeatureCollection(vector),nfipreturns a :class:pandas.DataFrame(tabular). The :class:earthlens.earthlens.EarthLensfacade reads the instance attribute to gateaggregate=and to know the return shape. - Bounded requests, required (
G3). No unbounded national pull:structuresneeds afips=or a[lat_lim, lon_lim]box,nfhlneeds the box, andnfipneeds at least one ofstate/county/year/flood_event. NFIP paging logs the total record count so a large pull is visible.
All three are US public-domain, keyless — no auth. aggregate= is rejected
(these are records, not gridded rasters), and the parse uses no gridded-array
dependency.
NSI
#
Bases: AbstractDataSource
US flood exposure / loss backend (per-instance output).
Resolves source= to its catalog row, issues the one bounded request that
source needs, and returns a
:class:~pyramids.feature.collection.FeatureCollection (structures/nfhl)
or a :class:pandas.DataFrame (nfip). US-only: a non-US box returns an
empty result, not an error (G4).
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
Set per instance in :meth: |
Source code in libs/providers/hazards/src/earthlens/nsi/backend.py
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 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 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
__init__(start=None, end=None, lat_lim=None, lon_lim=None, temporal_resolution='snapshot', path=None, fmt='%Y-%m-%d', source='structures', fips=None, filters=None, max_records=None, output_format='csv', session=None)
#
Initialise an NSI backend instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str | None
|
Inclusive start of an optional window, parsed with |
None
|
end
|
str | None
|
Inclusive end of the optional window; |
None
|
lat_lim
|
list[float] | None
|
|
None
|
lon_lim
|
list[float] | None
|
|
None
|
temporal_resolution
|
str
|
Recorded as the resolution label only. |
'snapshot'
|
path
|
Path | str | None
|
Output directory for a written tabular ( |
None
|
fmt
|
str
|
|
'%Y-%m-%d'
|
source
|
str
|
Which source to query — |
'structures'
|
fips
|
str | None
|
A 2/5/11/15-digit FIPS code selecting |
None
|
filters
|
dict[str, str | int] | None
|
NFIP attribute filter mapping — recognised keys are
|
None
|
max_records
|
int | None
|
Optional cap on the number of |
None
|
output_format
|
OutputFormat
|
On-disk format for the |
'csv'
|
session
|
Session | None
|
An existing |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/hazards/src/earthlens/nsi/backend.py
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 | |
download(progress_bar=True)
#
Fetch the selected source and return its per-instance shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_bar
|
bool
|
Accepted for signature parity; one logical request is
issued (paged for |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DataFrame | FeatureCollection
|
class: |
DataFrame | FeatureCollection
|
|
|
DataFrame | FeatureCollection
|
|
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the upstream source returns a non-2xx status. |
Source code in libs/providers/hazards/src/earthlens/nsi/backend.py
earthlens.nsi.catalog
#
Source catalog for the NSI flood-exposure backend.
The nsi backend serves three keyless US-federal REST sources selected by a
source= discriminator: structures (USACE National Structure Inventory),
nfhl (FEMA National Flood Hazard Layer), and nfip (FEMA NFIP redacted
claims v3). This module is the bridge from a source key to its endpoint, the
per-instance output kind, and the friendly -> provider field map used to shape
the response.
:class:Catalog is a thin :class:earthlens.base.AbstractCatalog subclass that
loads the bundled nsi_data_catalog.yaml and exposes each row as a
:class:Source. Resolve one source with :meth:Catalog.get (a did-you-mean
hint on an unknown key); list the shipped keys with :meth:Catalog.available.
:data:CATALOG_PATH is the path to the bundled YAML.
Catalog
#
Bases: AbstractCatalog[Source]
Source catalog for the NSI backend.
Reads the bundled nsi_data_catalog.yaml (shipped as package data) and
exposes its sources: block as a map of :class:Source rows keyed by
name. Instantiate with no arguments (Catalog()). Resolve one row with
:meth:get and list the shipped keys with :meth:available.
Attributes:
| Name | Type | Description |
|---|---|---|
datasets |
dict[str, Source]
|
Map from source name to its :class: |
Examples:
- Resolve a source and read its output kind:
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
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 | |
available()
#
Return the sorted list of shipped source names.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Every catalog key, sorted. |
get(source_id)
#
Resolve a source name to its :class:Source row.
Thin wrapper over the inherited :meth:get_dataset, which raises a
ValueError with a did-you-mean hint on an unknown key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_id
|
str
|
A shipped source name ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Source |
Source
|
The matching catalog row. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
load(catalog_path=None)
classmethod
#
Read the NSI catalog from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_path
|
Path | None
|
Path to the catalog YAML. Defaults to the module-level
:data: |
None
|
Returns:
| Type | Description |
|---|---|
Catalog
|
A fully-populated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file has no |
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
Source
#
Bases: SummarisedLeaf
One NSI catalog row (one of the three flood sources).
The source name is the parent key in :attr:Catalog.datasets and is stored
on the row as :attr:id so a resolved :class:Source is self-describing.
Which fields matter depends on :attr:provider; a cross-field validator
enforces the source-specific ones (nfhl needs a layer, nfip a records
key).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The source name ( |
provider |
str
|
The upstream service — |
endpoint |
str
|
The base REST URL. |
output_kind |
OutputKind
|
|
long_name |
str
|
Human-readable label. |
citation |
str
|
The source's citation string, logged once on use. |
license |
str
|
The data licence (all three are US public domain). |
fields |
dict[str, str]
|
Friendly -> provider field-name map. For the tabular |
layer_id |
int | None
|
ArcGIS MapServer layer id ( |
layer_name |
str | None
|
ArcGIS layer name ( |
records_key |
str | None
|
JSON envelope key holding the record list ( |
page_size |
int | None
|
OData page size for paged fetches ( |
Examples:
- Build a source row directly:
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
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 | |
clear_catalog_cache()
#
Empty the module-level catalog parse cache.
Useful in tests that rewrite the catalog on disk and want to force a
re-parse. Production callers do not need this — the cache key includes the
file's st_mtime_ns, so any real edit invalidates the entry on its own.
Source code in libs/providers/hazards/src/earthlens/nsi/catalog.py
earthlens.nsi.geometry
#
Geometry helpers for the NSI backend.
Pure functions that turn a [lat_lim, lon_lim] bounding box into the two
spatial request shapes the vector sources need — a GeoJSON polygon body for the
NSI structures POST, and an ArcGIS envelope query for the FEMA NFHL layer — and
that wrap a returned GeoJSON FeatureCollection into a pyramids
:class:~pyramids.feature.collection.FeatureCollection. No network, no state.
arcgis_envelope(lat_lim, lon_lim, out_fields='*')
#
Build the ArcGIS query parameters for the NFHL flood-zone layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
out_fields
|
str
|
Comma-separated attribute list to return ( |
'*'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The |
Examples:
- Build the query params for a box:
Source code in libs/providers/hazards/src/earthlens/nsi/geometry.py
bbox_from_limits(lat_lim, lon_lim)
#
Return (xmin, ymin, xmax, ymax) from lat_lim / lon_lim.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, float]
|
tuple[float, float, float, float]: The envelope as
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If either limit is not a two-element |
Examples:
>>> from earthlens.nsi import bbox_from_limits
>>> bbox_from_limits([29.95, 29.96], [-90.07, -90.06])
(-90.07, 29.95, -90.06, 29.96)
Source code in libs/providers/hazards/src/earthlens/nsi/geometry.py
nsi_polygon_body(lat_lim, lon_lim)
#
Build the GeoJSON-polygon body for an NSI structures POST.
The NSI ?bbox= query returns empty; the working AOI selector is a POST of
a GeoJSON FeatureCollection carrying one rectangle polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A GeoJSON |
Examples:
- Build a polygon body for a small box:
Source code in libs/providers/hazards/src/earthlens/nsi/geometry.py
to_feature_collection(geojson)
#
Wrap a GeoJSON FeatureCollection mapping into a pyramids collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geojson
|
dict
|
A GeoJSON mapping carrying a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FeatureCollection |
FeatureCollection
|
The features tagged |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Wrap a one-feature GeoJSON and inspect the collection:
>>> from earthlens.nsi import to_feature_collection >>> fc = to_feature_collection( ... { ... "type": "FeatureCollection", ... "features": [ ... { ... "type": "Feature", ... "geometry": {"type": "Point", "coordinates": [-90.0, 29.9]}, ... "properties": {"occtype": "RES1"}, ... } ... ], ... } ... ) >>> len(fc) 1