src.j_dataprep¶
Directories¶
Submodules¶
src.j_dataprep.DEMs¶
- class src.j_dataprep.DEMs.Buildings(bbox, wfs_url='https://data.3dbag.nl/api/BAG3D/wfs', layer_name='BAG3D:lod13', gpkg_name='buildings', output_folder='output', output_layer_name='buildings')[source]¶
Bases:
objectManage 3D building data within a bounding box by downloading, loading, and modifying building geometries from a WFS service.
- bbox¶
Bounding box (min_x, min_y, max_x, max_y) for the area of interest.
- Type:
tuple
- bufferbbox¶
Buffered bounding box expanded by 2 units.
- Type:
tuple
- wfs_url¶
URL of the WFS service to download building data.
- Type:
str
- layer_name¶
WFS layer name to query.
- Type:
str
- data¶
Downloaded building data.
- Type:
GeoDataFrame
- building_geometries¶
List of building geometries with parcel IDs.
- Type:
list
- removed_buildings¶
List of parcel IDs of removed buildings.
- Type:
list
- user_buildings¶
List of user-inserted building geometries.
- Type:
list
- user_buildings_higher¶
List of user buildings with height info.
- Type:
list
- removed_user_buildings¶
List of user building IDs that are removed.
- Type:
list
- is3D¶
Flag indicating if 3D building data is used.
- Type:
bool
- download_wfs_data(gpkg_name, output_folder, layer_name)[source]¶
Download building features from the WFS service within the buffered bounding box. Saves the data as a GeoPackage file.
- Parameters:
gpkg_name (str) – Filename for the GeoPackage (without extension).
output_folder (str) – Folder to save the GeoPackage.
layer_name (str) – Layer name to use inside the GeoPackage.
- Returns:
Downloaded building features concatenated, or None if no features were downloaded.
- Return type:
GeoDataFrame
- insert_user_buildings(highest_array, transform, footprint_array=None)[source]¶
Insert user-defined buildings based on arrays of building heights and optional footprints. Assigns unique parcel IDs and matches footprint buildings with highest buildings.
- Parameters:
highest_array (np.ndarray) – Array representing the highest building heights.
transform (Affine) – Rasterio affine transform for spatial referencing.
footprint_array (np.ndarray or None) – Optional array representing building footprints.
- Effects:
Updates self.user_buildings, self.user_buildings_higher, and self.is3D.
- static load_buildings(buildings_gdf, buildings_path=None, layer=None)[source]¶
Load building geometries from a GeoDataFrame or from a file.
- Parameters:
buildings_gdf (GeoDataFrame or None) – Building data GeoDataFrame.
buildings_path (str or None) – Path to building file to load if GeoDataFrame is None.
layer (str or None) – Layer name to read from file if applicable.
- Returns:
List of dicts with ‘geometry’ (GeoJSON mapping) and ‘parcel_id’. None if no data could be loaded.
- Return type:
list
- remove_buildings(identification)[source]¶
Mark a building as removed by adding its parcel ID to the removed list.
- Parameters:
identification (str) – Parcel ID of the building to remove.
- remove_user_buildings(identification)[source]¶
Mark a user building as removed by adding its parcel ID to the removed list.
- Parameters:
identification (str) – Parcel ID of the user building to remove.
- class src.j_dataprep.DEMs.CHM(bbox, dtm, dsm, trunk_height, output_folder_chm='output', output_folder_las='temp', resolution=0.5, merged_output='pointcloud.las', ndvi_threshold=0.05)[source]¶
Bases:
objectClass for creating and managing Canopy Height Models (CHMs) from LiDAR data. This class handles downloading and merging LAS/LAZ tiles, filtering vegetation points based on classification and NDVI, rasterizing vegetation using interpolation, applying smoothing filters, and generating final CHM raster outputs.
- bbox¶
Bounding box coordinates (min_x, min_y, max_x, max_y) defining the area of interest.
- Type:
tuple
- bufferedbbox¶
Buffered bounding box extended by a fixed margin.
- Type:
tuple
- crs¶
Coordinate reference system used (default EPSG:28992).
- Type:
rasterio.crs.CRS
- dtm¶
Digital Terrain Model raster data.
- Type:
numpy.ndarray or rasterio object
- dsm¶
Digital Surface Model raster data.
- Type:
numpy.ndarray or rasterio object
- output_folder_chm¶
Folder path where CHM outputs are saved.
- Type:
str
- gdf¶
GeoDataFrame containing tile lookup information.
- Type:
geopandas.GeoDataFrame
- chm¶
Initial Canopy Height Model raster array.
- Type:
numpy.ndarray
- tree_polygons¶
Polygons representing tree footprints.
- Type:
geopandas.GeoDataFrame
- transform¶
Affine transform for raster coordinates.
- Type:
affine.Affine
- trunk_array¶
Array representing estimated trunk heights.
- Type:
numpy.ndarray
- original_chm¶
Copy of the original CHM before processing.
- Type:
numpy.ndarray
- og_polygons¶
Copy of original tree polygons.
- Type:
geopandas.GeoDataFrame
- original_trunk¶
Copy of original trunk array.
- Type:
numpy.ndarray
- chm_creation(LasData, vegetation_data, output_filename, resolution=0.5, smooth=False, nodata_value=-9999, filter_size=3)[source]¶
Create and optionally smooth a CHM from vegetation data, then save it as a GeoTIFF and extract tree polygons.
- Parameters:
LasData (laspy.LasData) – LAS metadata for writing the output raster.
vegetation_data (tuple) – Tuple of (veg_raster, grid_centers) for CHM generation.
output_filename (str) – Path to save the output CHM raster.
resolution (float) – Spatial resolution of the raster (default = 0.5).
smooth (bool) – Whether to apply a median filter to the CHM (default = False).
nodata_value (float) – Value to assign to NoData cells in the raster (default = -9999).
filter_size (int) – Size of median filter kernel (default = 3).
- Returns:
(chm_array, polygons, transform) where polygons are tree regions as GeoJSON-like dicts.
- Return type:
tuple
- static chm_finish(chm_array, dtm_array, dsm_array, min_height=2, max_height=40)[source]¶
Finalize CHM by removing terrain and filtering by vegetation height.
- Parameters:
chm_array (np.ndarray) – Initial canopy height model array.
dtm_array (np.ndarray) – Digital terrain model array.
dsm_array (np.ndarray) – Digital surface model array.
min_height (float) – Minimum height threshold to keep vegetation (default = 2).
max_height (float) – Maximum height threshold to keep vegetation (default = 40).
- Returns:
Processed CHM with invalid or noisy values removed.
- Return type:
np.ndarray
- download_las_tiles(matching_tiles, output_folder)[source]¶
Download AHN5 or AHN4 LAZ tiles based on a list of matching tile names.
- Parameters:
matching_tiles (list of str) – List of tile identifiers (e.g., ‘31FN2_01’) to be downloaded.
output_folder (str) – Directory where downloaded LAZ files will be saved.
- Returns:
None
- extract_vegetation_points(LasData, ndvi_threshold=0.1, pre_filter=False)[source]¶
Extract vegetation points based on classification and NDVI threshold.
Parameters: - LasData (laspy.LasData): Input LAS point cloud data. - ndvi_threshold (float, optional): NDVI cutoff for vegetation points. Defaults to 0.1. - pre_filter (bool, optional): If True, filter out vegetation points below 1.5m above lowest vegetation point. Defaults to False.
Returns: - veg_points (laspy.LasData): LAS data filtered to vegetation points based on NDVI and optional height filtering.
- static filter_points_within_bounds(las_data, bounds)[source]¶
Filter LAS points that lie within the given bounding box.
- Parameters:
las_data (laspy.LasData) – Input LAS point cloud.
bounds (tuple) – Bounding box as (x_min, y_min, x_max, y_max).
- Returns:
Filtered LAS data containing only points within bounds.
- Return type:
laspy.LasData
- find_tiles(x_min, y_min, x_max, y_max)[source]¶
Find geotile names overlapping the specified bounding box.
- Parameters:
x_min (float) – Coordinates defining the bounding box.
y_min (float) – Coordinates defining the bounding box.
x_max (float) – Coordinates defining the bounding box.
y_max (float) – Coordinates defining the bounding box.
- Returns:
List of geotile names that intersect with the bounding box.
- Return type:
List[str]
- init_chm(bbox, output_folder='output', input_folder='temp', merged_output='output/pointcloud.las', smooth_chm=True, resolution=0.5, ndvi_threshold=0.05, filter_size=3)[source]¶
Initialize and generate a CHM by downloading, merging, filtering, and interpolating LiDAR data.
- Parameters:
bbox (tuple) – Bounding box (xmin, ymin, xmax, ymax) for the area of interest.
output_folder (str) – Directory for saving output files (default = ‘output’).
input_folder (str) – Directory where LAZ files are stored or downloaded (default = ‘temp’).
merged_output (str) – Path to save the merged LAS point cloud (default = ‘output/pointcloud.las’).
smooth_chm (bool) – Whether to smooth the CHM using a median filter (default = True).
resolution (float) – Output raster resolution (default = 0.5).
ndvi_threshold (float) – NDVI threshold for filtering vegetation points (default = 0.05).
filter_size (int) – Size of median filter kernel (default = 3).
- Returns:
(chm_array, polygons, transform) or (None, None, None) if process fails.
- Return type:
tuple
- insert_random_tree(position, height_range=(12.0, 18.0), crown_radius_range=(2.0, 5.0), trunk_height_range=(4.0, 12.0), canopy_base_range=(0.0, 0.8), resolution=0.5, min_canopy_height=3.0, tree_shape='parabolic', randomness=0.8)[source]¶
Insert a tree with randomized dimensions and properties at a specified position. Random values are drawn from The specified ranges for height, crown radius, trunk height, and canopy base height. Ensures that the canopy height meets a minimum value.
- Parameters:
position (tuple) – (row, col) position where the tree will be placed.
height_range (tuple) – Range of tree height in meters.
crown_radius_range (tuple) – Range of crown radius in meters.
trunk_height_range (tuple) – Range of trunk height in meters.
canopy_base_range (tuple) – Range of canopy base height in meters.
resolution (float) – Spatial resolution of the map.
min_canopy_height (float) – Minimum allowable canopy height (tree - trunk).
shape (str) – Shape type of the canopy (e.g., ‘parabolic’).
randomness (float) – Amount of shape noise to apply.
- Returns:
None
- insert_tree(position, height, crown_radius, resolution=0.5, trunk_height=5.0, tree_shape='parabolic', randomness=0.8, canopy_base_height=0.0)[source]¶
Insert a parametric tree model into the CHM and trunk height array at the specified location.
- Parameters:
position (tuple) – (row, col) indices for tree center insertion.
height (float) – Total height of the tree.
crown_radius (float) – Radius of the crown in real-world units.
resolution (float) – Real-world size of each pixel (default = 0.5).
trunk_height (float) – Height of the trunk (default = 0.0).
tree_shape (str) – Canopy shape type (‘gaussian’, ‘cone’, ‘parabolic’, ‘hemisphere’).
randomness (float) – Standard deviation for random noise applied to canopy (default = 0.8).
canopy_base_height (float) – Height at which the canopy starts above the trunk (default = 0.0).
- Returns:
Updates CHM and trunk arrays in-place.
- Return type:
None
- insert_type_tree(age, position, tree_type='fraxinus', resolution=0.5, canopy_base=0.0)[source]¶
Insert a tree of a specific type and age using pre-defined growth parameters.
Parameters are loaded from a JSON database and used to compute the trunk height and crown radius. The canopy type is fixed.
- Parameters:
age (int, str) – Age of the tree in years or life stage (young, early_mature, mature, late_mature, semi_mature).
position (tuple) – (row, col) position where the tree will be placed.
tree_type (str) – Tree species (default is ‘fraxinus’).
resolution (float) – Spatial resolution of the map.
canopy_base (float) – Height of the base of the canopy in meters.
- Returns:
None
Raises: - ValueError: If no data exists for the specified tree age.
- interpolation_vegetation(veg_points, resolution, no_data_value=-9999)[source]¶
Create a vegetation raster by interpolating vegetation points using Laplace interpolation.
- Parameters:
veg_points (laspy.LasData) – Vegetation points to interpolate.
resolution (float) – Desired raster resolution.
no_data_value (int, optional) – Value to assign NoData cells. Defaults to -9999.
- Returns:
interpolated_grid (np.ndarray) – Raster grid with interpolated vegetation heights.
grid_center_xy (tuple of np.ndarray) – Grid center coordinates (x, y).
- static median_filter_chm(chm_array, nodata_value=-9999, size=3)[source]¶
Apply a median filter to smooth the CHM, preserving NoData areas.
- Parameters:
chm_array (np.ndarray) – CHM raster array.
nodata_value (float, optional) – NoData value in the array. Defaults to -9999.
size (int, optional) – Median filter size (window). Defaults to 3.
- Returns:
Smoothed CHM array with NoData preserved.
- Return type:
smoothed_chm (np.ndarray)
- merge_las_files(laz_files, bounds, merged_output)[source]¶
Merge and crop multiple LAZ files into a single LAS file within the specified bounds.
- Parameters:
laz_files (list of str) – Paths to the input LAZ files.
bounds (tuple) – Bounding box (xmin, ymin, xmax, ymax) to crop point clouds.
merged_output (str or Path) – File path to write the merged output LAS file.
- Returns:
Merged and cropped point cloud data.
- Return type:
laspy.LasData
- static raster_center_coords(min_x, max_x, min_y, max_y, resolution)[source]¶
Compute center coordinates of each cell in a raster grid.
- Parameters:
min_x (float) – Bounding box coordinates.
max_x (float) – Bounding box coordinates.
min_y (float) – Bounding box coordinates.
max_y (float) – Bounding box coordinates.
resolution (float) – Cell size; assumed square cells.
- Returns:
grid_center_x (np.ndarray) – X cell center coordinates.
grid_center_y (np.ndarray) – Y cell center coordinates.
- remove_trees(tree_id)[source]¶
Remove a tree (or cluster of trees) from the CHM and trunk arrays by polygon ID.
- Parameters:
tree_id (int) – Identifier of the tree polygon to remove.
- Returns:
None
- save_las(merged_las, veg_points, output_name='veg_points.las')[source]¶
Save filtered vegetation points as a LAS file.
- Parameters:
merged_las (laspy.LasData) – Original merged LAS data with header info.
veg_points (laspy.LasData) – Filtered LAS points representing vegetation.
output_name (str, optional) – Output filename. Defaults to “veg_points.las”.
Creates the output folder if it does not exist and writes the LAS file.
- class src.j_dataprep.DEMs.DEMS(bbox, building_data, resolution=0.5, bridge=False, resampling=Resampling.cubic_spline, output_dir='output')[source]¶
Bases:
objectClass for handling Digital Elevation Models (DEM) including DTM and DSM, fetching AHN data via WCS, filling missing data, resampling, cropping, and integrating building footprints for urban terrain modeling.
- buffer¶
Buffer size in meters for bbox expansion.
- Type:
float
- bbox¶
Bounding box coordinates (xmin, ymin, xmax, ymax).
- Type:
tuple
- bufferbbox¶
Buffered bounding box expanded by buffer.
- Type:
tuple
- building_data¶
List of building geometries and attributes.
- Type:
list
- resolution¶
Desired output raster resolution in meters.
- Type:
float
- user_building_data¶
User-provided building data.
- Type:
list
- output_dir¶
Directory to save output files.
- Type:
str
- bridge¶
Whether to include ‘overbruggingsdeel’ data in the DSM.
- Type:
bool
- resampling¶
Resampling method for raster operations.
- Type:
rasterio.enums.Resampling
- crs¶
Coordinate reference system, default EPSG:28992.
- Type:
CRS
- dtm¶
Digital Terrain Model raster data.
- Type:
np.ndarray
- dsm¶
Digital Surface Model raster data.
- Type:
np.ndarray
- transform¶
Affine transform for the rasters.
- Type:
Affine
- og_dtm¶
Original DTM before modifications.
- Type:
np.ndarray
- og_dsm¶
Original DSM before modifications.
- Type:
np.ndarray
- is3D¶
Flag indicating if DSM is 3D.
- Type:
bool
- create_dem(bbox)[source]¶
Create Digital Elevation Model (DEM) from AHN data with optional building and overbrugginsdeel data.
- Parameters:
bbox (tuple) – Bounding box coordinates (xmin, ymin, xmax, ymax).
- Returns:
cropped_dtm (np.ndarray) – Filled, cropped DTM array.
cropped_dsm (np.ndarray) – Cropped DSM array with buildings and building heights, optional output.
transform (Affine) – Affine transform matrix of the rasters.
- crop_to_bbox(array, transform)[source]¶
Crop a buffered raster array to the original bounding box.
- Parameters:
array (np.ndarray) – Raster data array with buffer.
transform (Affine) – Affine transform matrix of input array.
- Returns:
cropped_array (np.ndarray) – Cropped raster array.
new_transform (Affine) – New Affine transform matrix for cropped raster.
- export_context(file_name, export_format='dxf')[source]¶
Export buildings and DSM bounding box to a CAD-compatible file format.
- Parameters:
file_name (str) – Path and name of the file to export.
export_format (str, optional) – Export format. Options: ‘json’, ‘csv’, or ‘dxf’. Defaults to ‘dxf’.
- Returns:
None
- static extract_center_cells(geo_array, no_data=-9999)[source]¶
Extract the values of each cell in the input data and save these with the x and y (row and col) indices. Thereby, make sure that the corners of the dataset are filled for a full coverage triangulation in the next step.
- Parameters:
geo_array (np.ndarray) – Raster data array.
no_data (int) – No data value to identify invalid cells (default -9999).
- Returns:
List of [x, y, z] cell values with corners interpolated if no data.
- Return type:
list
- static fetch_ahn_wcs(bufferbbox, output_file, coverage='dtm_05m', wcs_resolution=0.5)[source]¶
Fetch AHN WCS data for a given buffered bounding box and save as GeoTIFF.
- Parameters:
bufferbbox (tuple) – Buffered bounding box (xmin, ymin, xmax, ymax).
output_file (str) – Output filepath for the GeoTIFF (default “output/dtm.tif”).
coverage (str) – Coverage layer name, e.g. “dtm_05m” or “dsm_05m” (default “dtm_05m”).
wcs_resolution (float) – Resolution of WCS data in meters (default 0.5).
- Returns:
(rasterio dataset object, numpy array of raster data) if successful, else None.
- Return type:
tuple or None
- fill_raster(geo_array, nodata_value, transform)[source]¶
Fill no-data values in a raster using Laplace interpolation.
- Parameters:
geo_array (np.ndarray) – Cropped raster data array.
nodata_value (int) – No-data value to replace NaNs after interpolation.
transform (Affine) – Affine transform matrix of the raster.
- Returns:
Filled raster array with no-data values replaced.
- Return type:
new_data(np.ndarray)
- remove_buildings(remove_list, remove_user_list, building_data, user_building_data, user_buildings_higher=None)[source]¶
Remove specified buildings from DSM by replacing their areas with DTM values.
- Parameters:
remove_list (list) – List of parcel IDs to remove from the main building dataset.
remove_user_list (list) – List of parcel IDs to remove from the user building dataset.
building_data (list) – List of main building data dictionaries.
user_building_data (list) – List of user building data dictionaries.
user_buildings_higher (list, optional) – List of user buildings with higher layers to be removed as well.
- Returns:
None
- replace_buildings(filled_dtm, dsm_buildings, buildings_geometries, transform, bridge)[source]¶
Replace filled DTM values with DSM building heights where buildings exist.
- Parameters:
filled_dtm (np.ndarray) – Filled, cropped DTM array.
dsm_buildings (np.ndarray) – Filled, cropped DSM array with buildings.
buildings_geometries (list) – List of building geometries (dict or GeoJSON features).
transform (Affine) – Affine transform matrix of the rasters.
bridge (bool) – Whether to include ‘overbrugginsdeel’ geometries.
- Returns:
Final DSM array combining ground and building heights.
- Return type:
final_dsm (np.ndarray)
- resample_raster(input_array, input_transform, input_crs, output_resolution)[source]¶
Resample a raster to a different resolution.
- Parameters:
input_array (np.ndarray) – Input raster data.
input_transform (Affine) – Affine transform of input raster.
input_crs (CRS) – Coordinate Reference System of input raster.
output_resolution (float) – Desired output resolution in meters.
- Returns:
resampled_array (np.ndarray) – Resampled raster array.
new_transform (Affine) – New Affine transform matrix for resampled raster.
- update_building_height(raise_height, user_buildings, building_id=None, user_array=None, user_arrays=None, higher_buildings=None)[source]¶
Raise the height of specified user building(s) in the DSM by a given amount.
- Parameters:
raise_height (float) – Amount to raise the building height.
user_buildings (list) – List of user building data dictionaries.
building_id (str, optional) – ID of the building to raise. If None, raise_all should be used.
user_array (np.ndarray, optional) – Single 2D array with building height data.
user_arrays (list of np.ndarray, optional) – List of arrays representing multiple DSM layers.
higher_buildings (list, optional) – List of buildings with additional height layers for 3D DSM.
- Returns:
None
- update_dsm(user_buildings, user_array=None, user_arrays=None, higher_buildings=None)[source]¶
Update the DSM with new user building heights, supporting both 2D and 3D DSM arrays.
- Parameters:
user_buildings (list) – List of user building data dictionaries with geometries.
user_array (np.ndarray, optional) – Single 2D array with building height data.
user_arrays (list of np.ndarray, optional) – List of arrays representing multiple DSM layers.
higher_buildings (list, optional) – List of user buildings with additional height layers.
- Returns:
None
- src.j_dataprep.DEMs.edit_bounds(bounds, buffer, shrink=False)[source]¶
Expands or shrinks bounding box coordinates by a buffer amount.
- Parameters:
bounds (tuple) – Bounding box as (min_x, min_y, max_x, max_y).
buffer (float) – Amount to expand or shrink the bounding box.
shrink (bool) – If True, shrink the bounds by buffer; else expand (default False).
- Returns:
Modified bounding box as (min_x, min_y, max_x, max_y).
- Return type:
tuple
- src.j_dataprep.DEMs.write_output(dataset, crs, output, transform, name, change_nodata=False)[source]¶
Writes a numpy array to a GeoTIFF file using rasterio.
- Parameters:
dataset – Rasterio or laspy dataset (for metadata).
crs – Coordinate Reference System for the output raster.
output (np.ndarray) – Output numpy array grid to write.
transform – Affine transform mapping pixel to spatial coordinates.
name (str) – Output filename (including path).
change_nodata (bool) – If True, use nodata value -9999; else use dataset’s nodata.
- Returns:
None
src.j_dataprep.landcover¶
- class src.j_dataprep.landcover.LandCover(bbox, crs='http://www.opengis.net/def/crs/EPSG/0/28992', use_bgt=True, main_roadtype=0, resolution=0.5, building_data=None, dataset=None, dataset_path=None, buildings_path=None, layer=None, nodata_fill=0, roads_on_top=True, landcover_path_bgt='src/databases/landcover_bgt.json', landcover_top='src/databases/landcover_top.json')[source]¶
Bases:
object- A class to process and rasterize land cover data from the PDOK Top10NL API, building geometries, and a DTM raster,
producing a land cover classification raster.
- bbox¶
Bounding box (xmin, ymin, xmax, ymax) in EPSG:28992.
- Type:
tuple
- crs¶
CRS for requests and raster alignment, default is EPSG:28992.
- Type:
str
- resolution¶
Output raster resolution in meters.
- Type:
float
- main_road¶
Default landcover code for hardened roads if TOP10NL is chosen as source.
- Type:
int
- dtm_dataset¶
DTM as rasterio dataset for alignment and dimensions.
- Type:
rasterio.open
- base_url_top¶
Base URL for the PDOK Top10NL API.
- Type:
str
- base_url_bgt¶
Base URL for the PDOK Top10NL API.
- Type:
str
- water_mask, building_mask
Optional binary masks.
- Type:
ndarray
- buildings_path¶
Optional path to building vector data.
- Type:
str
- layer¶
Layer name if using GPKG for building data.
- Type:
str
- building_data¶
Optional preloaded building geometries.
- Type:
list
- landcover_path¶
Path to JSON file mapping landcover codes.
- Type:
str
- landcover_mapping¶
Mapping of landcover types to codes.
- Type:
dict
- buildings, water, roads, terrains
Extracted vector features.
- Type:
list
- array¶
Output raster array of landcover values.
- Type:
ndarray
- og_landcover¶
Original unmodified landcover array.
- Type:
ndarray
- landcover_withoutbuild¶
Landcover array before building insertion.
- Type:
ndarray
- transform¶
Raster transform from DTM dataset.
- convert_to_raster_bgt()[source]¶
Rasterize terrain, road, water, building, and overbrugging features from BGT onto the DTM sized grid.
- Returns:
2D array with land cover codes assigned per grid cell.
- Return type:
np.ndarray
- convert_to_raster_top()[source]¶
Rasterize the TOP10NL terrain, road, water, and building features onto the DTM-sized grid. Applies land cover codes to a numpy array according to feature geometries.
- Returns:
- A 2D numpy array with land cover codes assigned per grid cell.
The array uses -9999 for nodata values where no features are present.
- Return type:
np.ndarray
- dtm_dataset_prep(dataset_path, dataset)[source]¶
Prepare and return a DTM rasterio dataset object.
- Parameters:
dataset_path (str or Path, optional) – File path to the DTM raster.
existing_dataset (rasterio.io.DatasetReader, optional) – An already-open rasterio dataset.
- Returns:
The prepared DTM dataset.
- Return type:
rasterio.io.DatasetReader
- export_context(file_name, export_format='dxf')[source]¶
Export the current land cover and building context.dxf to a file in specified format.
- Parameters:
file_name (str) – The output file path.
export_format (str, optional) – Format of the export. Options are “json”, “csv”, or “dxf”. Defaults to “dxf”.
- Returns:
None
- export_features_to_gpkg(features, output_path, layer_name='features')[source]¶
Export a list of GeoJSON-like features to a GeoPackage.
- Parameters:
features (list) – List of features with “geometry” and “properties”.
output_path (str) – File path to save the .gpkg.
layer_name (str) – Name of the layer inside the GeoPackage.
- static filter_active_bgt_features(features)[source]¶
Filters BGT features where property “eind_registratie” is None (null).
- Parameters:
features (list) – List of GeoJSON feature dicts.
- Returns:
Filtered features with “eind_registratie” == None.
- Return type:
list
- get_bgt_features(item_type)[source]¶
Retrieve features from the BGT API for the specified item type within the bounding box.
- Parameters:
item_type (str) – The name of the BGT collection to query (e.g., “waterdeel_vlak”, “wegdeel_vlak”, “terrein_vlak”).
- Returns:
A GeoJSON-like dictionary with key “features” containing a list of feature dictionaries as returned by the API.
- Return type:
dict
- get_landcover_code(land_type, isroad=False)[source]¶
Retrieve the numeric land cover code for a given land type.
- Parameters:
land_type (str) – The land type string to look up .
isroad (bool, optional) – Whether to look up in the “road” category (True) or “terrain” category (False). Defaults to False.
- Returns:
- The land cover code for the given land type.
Returns -1 if the land type is not found in the specified category.
- Return type:
int
- get_top10nl(item_type)[source]¶
Retrieve features from the TOP10NL API for the specified item type within the bounding box.
- Parameters:
item_type (str) – The name of the TOP10NL collection to query (e.g., “waterdeel_vlak”, “wegdeel_vlak”, “terrein_vlak”).
- Returns:
A GeoJSON-like dictionary with key “features” containing a list of feature dictionaries as returned by the API.
- Return type:
dict
- load_buildings()[source]¶
Load building features from a GeoPackage or use preloaded data if available.
- Returns:
- A list of dictionaries with keys:
”geometry”: GeoJSON-like geometry dictionary of the building footprint
”parcel_id”: The building parcel identifier string
Returns an empty list if no building data or path is provided.
- Return type:
list
- load_landcover_mapping()[source]¶
Load land cover mappings from a JSON file with explicit UTF-8 encoding.
- Returns:
A dictionary representing land cover categories and their corresponding code mappings. For example: {
”terrain”: {“grasland”: 5, “akker”: 6, …}, “road”: {“onverhard”: 3, “halfverhard”: 4, …}
}
- Return type:
dict
- process_road_features_bgt()[source]¶
Loads and classifies BGT road features with landuse.
- Returns:
A list of GeoJSON-like feature dictionaries representing roads. Each feature contains “geometry” and “properties” with a “landuse” code.
- Return type:
list
- process_road_features_top()[source]¶
Process road features from TOP10NL data and map road surface types to codes.
- Returns:
A list of GeoJSON-like feature dictionaries representing roads. Each feature contains “geometry” and “properties” with a “landuse” code.
- Return type:
list
- process_terrain_features_bgt()[source]¶
Process terrain features from BGT and assign land use codes from the terrain mapping. Keeps full original properties and adds “landuse”.
- process_terrain_features_top()[source]¶
Process terrain features from TOP10NL data and map land use types to codes.
- Returns:
A list of GeoJSON-like feature dictionaries representing terrain areas. Each feature contains “geometry” and “properties” with a “landuse” code.
- Return type:
list
- process_water_features_bgt()[source]¶
Process water features from BGT. Keeps all original properties.
- process_water_features_top()[source]¶
Process and filter water features from TOP10NL data. Filters out features with ‘hoogteniveau’ == -1 and keeps only Polygon or MultiPolygon geometries (line geometries are buffered).
- Returns:
A list of GeoJSON-like feature dictionaries representing water areas. Each feature has keys “type”, “geometry”, and “properties”.
- Return type:
list
- save_raster(name, change_nodata=True)[source]¶
Save the current raster array to a GeoTIFF file.
- Parameters:
name (str) – The output file path.
change_nodata (bool) – If True, nodata value is forced to -9999. Otherwise, uses the nodata value from the original dataset if present.
- Returns:
None
- update_build_landcover(new_building_data)[source]¶
Update the raster array by rasterizing new building geometries with landcover code 2.
- Parameters:
new_building_data (list) – List of building feature dictionaries with “geometry”.
- Returns:
None
- update_landcover(land_type, input_array)[source]¶
Update the raster array for cells where input_array > -1 with the given land type code.
- Parameters:
land_type (int) – The land cover code to set.
input_array (np.ndarray) – Boolean or integer mask array indicating which cells to update.
- Returns:
None
src.j_dataprep.user_input¶
- class src.j_dataprep.user_input.Building3d_input(ncols, nrows, resolution)[source]¶
Bases:
objectClass to handle 3D building input rasterization and create DSM layers with gaps.
- cols¶
Number of columns in the raster grid.
- Type:
int
- rows¶
Number of rows in the raster grid.
- Type:
int
- res¶
Spatial resolution of each cell in the raster grid.
- Type:
float
- static buildings_input(arrays, num_gaps)[source]¶
Generate 3D-layered DSM representing building heights with gaps.
- Parameters:
arrays (list of np.ndarray) – List of input 2D arrays representing building heights and gap layers, output from Rusterizer.
num_gaps (int) – Number of gaps to include in the DSM layering.
- Returns:
dsms (np.ndarray) – 3D array with shape (layers, rows, cols) of DSM layers with gaps.
base_array (np.ndarray) – The base building height array from input for reference.
- rasterize_3dbuilding(obj_path, num_gaps)[source]¶
Rasterize a 3D building OBJ file into DSM layers with gaps.
- Parameters:
obj_path (str) – File path to the 3D building OBJ file.
num_gaps (int) – Number of gaps to consider when layering DSMs.
- Returns:
dsms (np.ndarray) – 3D array of DSM layers with gaps.
highest_array (np.ndarray) – The highest building height layer from input.
input_arrays (list of np.ndarray) – Raw input rasterized arrays from the OBJ.
- class src.j_dataprep.user_input.Surface_input(ncols, nrows, resolution)[source]¶
Bases:
objectClass to create a new land cover input from user input for the Landcover class.
- Parameters:
ncols (int) – Number of columns in the raster grid.
nrows (int) – Number of rows in the raster grid.
resolution (float) – Resolution of the raster grid cells.
- dictionary¶
Loaded landcover category dictionary from ‘landcover_bgt.json’.
- Type:
dict
- res¶
Resolution of the raster grid cells.
- Type:
float
- ncols¶
Number of columns in the raster grid.
- Type:
int
- nrows¶
Number of rows in the raster grid.
- Type:
int
- get_value(category, key)[source]¶
Retrieves the integer value for a given category and key from the landcover dictionary.
- Parameters:
category (str) – The category name in the landcover dictionary.
key (str) – The key within the category to look up.
- Returns:
The integer value corresponding to the category and key, or None if not found.
- Return type:
int or None
- user_input_array(obj_path, type)[source]¶
Rasterizes a given input object path and retrieves a type number based on provided type info.
- Parameters:
obj_path (str) – Path to the input object to rasterize.
type (list) – List containing two elements [category, key] to fetch a type number.
- Returns:
- Tuple containing:
np.ndarray: Rasterized array from the input object.
int or None: Type number corresponding to the category and key.
- Return type:
tuple