Geospatial
geospatial
¶
Functions¶
ensure_projected_CRS(geodata)
¶
Returns a projected geodataframe from the provided geodataframe by converting it to ESPG:4326 (if not already) and determining the projected CRS from the point coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geodata |
GeoDataGrame
|
Original geodataframe that is potentially unprojected |
required |
Returns: gpd.GeoDataGrame: projected geodataframe
Source code in geograypher/utils/geospatial.py
get_overlap_raster(unlabeled_df, classes_raster, num_classes=None, normalize=False)
¶
Get the overlap for each polygon in the unlabeled DF with each class in the raster
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unlabeled_df |
Union[PATH_TYPE, GeoDataFrame]
|
Dataframe or path to dataframe containing geometries per object |
required |
classes_raster |
PATH_TYPE
|
Path to a categorical raster |
required |
num_classes |
Union[None, int]
|
Number of classes, if None defaults to the highest overlapping class. Defaults to None. |
None
|
normalize |
bool
|
Normalize counts matrix from pixels to fraction. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
(ndarray, ndarray)
|
np.ndarray: (n_valid, n_classes) counts per polygon per class |
(ndarray, ndarray)
|
np.ndarray: (n_valid,) indices into the original array for polygons with non-null predictions |
Source code in geograypher/utils/geospatial.py
get_overlap_vector(unlabeled_df, classes_df, class_column, normalize=False)
¶
For each element in unlabeled df, return the fractional overlap with each class in classes_df
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unlabeled_df |
GeoDataFrame
|
A dataframe of geometries |
required |
classes_df |
GeoDataFrame
|
A dataframe of classes |
required |
class_column |
str
|
Which column in the classes_df to use. Defaults to "names". |
required |
normalize |
bool
|
Normalize counts matrix from area to fraction. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
(ndarray, ndarray)
|
np.ndarray: (n_valid, n_classes) counts per polygon per class |
(ndarray, ndarray)
|
np.ndarray: (n_valid,) indices into the original array for polygons with non-null predictions |
Source code in geograypher/utils/geospatial.py
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 |
|
load_downsampled_raster_data(dataset_filename, downsample_factor)
¶
Load a raster file spatially downsampled
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
PATH_TYPE
|
Path to the raster |
required |
downsample_factor |
float
|
Downsample factor of 10 means that pixels are 10 times larger |
required |
Returns:
Type | Description |
---|---|
np.array: The downsampled array in the rasterio (c, h, w) convention |
|
rio.DatasetReader: The reader with the transform updated |
|
rio.Transform: The updated transform |