Client
DB_Client
A dialect-agnostic Data Access Layer managing connections, schema deployments, and routing data to high-performance bulk loaders without external ORM spatial dependencies.
Attributes:
| Name | Type | Description |
|---|---|---|
engine |
Engine
|
The active database engine. |
SessionLocal |
sessionmaker
|
The session factory for transactions. |
Source code in src/phytospatial/db/client.py
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 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 | |
__init__(connection_string='sqlite:///phytospatial_local.gpkg')
Initializes the database client and configures spatial extensions if necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_string
|
str
|
The database connection URI. |
'sqlite:///phytospatial_local.gpkg'
|
Source code in src/phytospatial/db/client.py
deploy_schema()
Deploys the complete relational schema to the connected database target.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the schema deployment was successful, False otherwise. |
Source code in src/phytospatial/db/client.py
fetch_trees(crs='EPSG:32619')
Retrieves all master anchor trees from the database into a unified Vector object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
str
|
The coordinate reference system string to enforce on the output geometry. |
'EPSG:32619'
|
Returns:
| Name | Type | Description |
|---|---|---|
Vector |
Vector
|
A Phytospatial Vector object encapsulating the retrieved spatial records. |
Source code in src/phytospatial/db/client.py
from_env(db_type='postgres', env_path=None, sqlite_path='phytospatial_local.gpkg')
classmethod
Constructs a DB_Client instance using environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_type
|
str
|
The target database dialect ('postgres' or 'sqlite'). |
'postgres'
|
env_path
|
Optional[Union[str, Path]]
|
Filepath to a specific .env file. |
None
|
sqlite_path
|
str
|
Filepath for local SQLite/GeoPackage databases. |
'phytospatial_local.gpkg'
|
Returns:
| Name | Type | Description |
|---|---|---|
DB_Client |
DB_Client
|
A fully configured database client instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If PostgreSQL credentials are required but missing from the environment. |
Source code in src/phytospatial/db/client.py
register_image_acquisition(sensor_type, acquisition_time, gsd_cm=None, bands=None)
Persists a new Image acquisition record, including sequential spectral band specifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_type
|
str
|
The nomenclature identifier of the sensor. |
required |
acquisition_time
|
datetime
|
The timestamp the data was captured. |
required |
gsd_cm
|
Optional[float]
|
Ground Sample Distance resolution in centimeters. |
None
|
bands
|
Optional[List[Dict[str, Any]]]
|
List of dictionaries specifying band metadata parameters. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The primary key ID of the newly generated Image record. |
Source code in src/phytospatial/db/client.py
register_lidar_acquisition(sensor_type, acquisition_time, point_density=None, returns=None)
Persists a new LiDAR acquisition record into the acquisition registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor_type
|
str
|
The nomenclature identifier of the sensor. |
required |
acquisition_time
|
datetime
|
The timestamp the data was captured. |
required |
point_density
|
Optional[float]
|
Points per square meter metric. |
None
|
returns
|
Optional[int]
|
Total discrete return capacity of the sensor. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The primary key ID of the newly generated LiDAR record. |
Source code in src/phytospatial/db/client.py
stream_spectral_extraction(raster_input, vector_input, image_id, batch_size=5000, **kwargs)
Orchestrates an extraction pipeline, routing generated scalar JSON payloads directly into SQL storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raster_input
|
Union[str, Path, Any]
|
Dimensional imagery source targeting metrics compilation. |
required |
vector_input
|
Vector
|
Extraction mask topologies dictating operational boundaries. |
required |
image_id
|
int
|
Primary key reference pointing backward to a validated catalog acquisition. |
required |
batch_size
|
int
|
Numerical constraint dictating maximum pending records prior to transactional commit. |
5000
|
**kwargs
|
Any
|
Auxiliary configuration flags relayed securely to the underlying extraction matrix. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Comprehensive integer representing total rows effectively inserted into the relational schema. |
Source code in src/phytospatial/db/client.py
upload_crowns(crowns_input, crown_category='Automated', generation_method=None, trees_reference=None, lidar_id=None, image_id=None, srid=32619, batch_size=5000)
Routes the vector input to the PolarsLoader for high-performance insertion of delineated crown polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crowns_input
|
Union[str, Path, Vector]
|
The input vector data or filepath. |
required |
crown_category
|
str
|
Defines the delineation source. |
'Automated'
|
generation_method
|
Optional[str]
|
Defines the algorithmic generation method. |
None
|
trees_reference
|
Optional[Vector]
|
A reference Vector of tree points for spatial reconciliation. |
None
|
lidar_id
|
Optional[int]
|
Source LiDAR record ID. |
None
|
image_id
|
Optional[int]
|
Source Image record ID. |
None
|
srid
|
int
|
The target spatial reference identifier. |
32619
|
batch_size
|
int
|
Transaction block size for bulk insertions. |
5000
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The total number of crowns successfully inserted. |
Source code in src/phytospatial/db/client.py
upload_trees(trees_input, column_mapping=None, target_srid=32619, batch_size=15000)
Routes the vector input to the PolarsLoader for high-performance insertion of tree geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trees_input
|
Union[str, Path, Vector]
|
The input vector data or filepath. |
required |
column_mapping
|
Optional[Dict[str, str]]
|
Schema alignment dictionary. |
None
|
target_srid
|
int
|
The target spatial reference identifier. |
32619
|
batch_size
|
int
|
Transaction block size for bulk insertions. |
15000
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The total number of trees successfully inserted. |