Skip to content

Commit

Permalink
Merge pull request #66 from kartverket/docstring_update
Browse files Browse the repository at this point in the history
Docstring update
  • Loading branch information
EllingOftedalKV authored Jan 25, 2024
2 parents 191c4da + c9fb894 commit f19366f
Showing 1 changed file with 61 additions and 29 deletions.
90 changes: 61 additions & 29 deletions generalization/n100/building/building_data_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@

def main():
"""
This function prepares data selection of the following features:
- Begrensningskurve water features to be used as a barrier
- Unsplit veg sti to be used as a barrier
- Matrikkel bygningspunkt to add building points removed by urban areas in n50
- Grunnriss selection for generalization and transforming church and hospital grunnriss to points.
Summary:
This is the main function of building data preparation, which aims to prepare the data for future building generalization processing.
Details:
- Function 1: Create Water Feature Buffer
This function creates a buffer for water features using the "begrensningskurve" feature. It prepares the data for future building placement on the water's edge.
- Function 2: Unsplit Road Lines
This function unsplit a line feature of roads to reduce the number of objects in future processing.
- Function 3: Add Building Points from Matrikkel
This function adds building points from the matrikkel dataset for areas that are no longer considered urban after the generalization of "arealdekke." It also adds the required fields and values for future analysis.
- Function 4: Select Building Polygons for Generalization
This function selects building polygons (grunnriss) to be generalized. Smaller polygons and churches or hospitals are excluded, transformed into points, and sent to building point generalization.
"""

preparation_begrensningskurve()
preperation_veg_sti()
adding_matrikkel_as_points()
Expand All @@ -37,11 +48,22 @@ def main():

def preparation_begrensningskurve():
"""
A function that prepares the begrensningskurve by performing the following steps:
1. Defining the SQL selection expression for water features for begrensningskurve and creating a temporary feature layer.
2. Creating a buffer of the water features begrensningskurve to take into account symbology of the water features.
3. Adding hierarchy and invisibility fields to the begrensningskurve_waterfeatures_buffer and setting them to 0.
Summary:
This function creates a buffer for water features using the "begrensningskurve" feature. It prepares the data for future building placement on the water's edge.
Details:
- Define an SQL selection expression to identify water features of interest.
- Create a temporary feature of water features from the "begrensningskurve" using the defined SQL expression.
- Select land features that do not belong to specific categories ('ElvBekk', 'Havflate', 'Innsjø', 'InnsjøRegulert').
- Identify land features near water features by selecting those that boundary-touch with water features.
- Apply a 15-meter buffer to the identified land features to create buffered land features.
- Apply a 45-meter buffer to the selected water features to create buffered water features.
- Erase buffered water features from the buffered land features to create a final set of land features.
Note:
- Additional logic may be required for rivers separately in future development.
"""

# Defining the SQL selection expression for water features for begrensningskurve
sql_expr_begrensningskurve_waterfeatures = "OBJTYPE = 'ElvBekkKant' Or OBJTYPE = 'Innsjøkant' Or OBJTYPE = 'InnsjøkantRegulert' Or OBJTYPE = 'Kystkontur'"

Expand Down Expand Up @@ -123,14 +145,14 @@ def preparation_begrensningskurve():

def preperation_veg_sti():
"""
Unsplit the lines in the specified feature class based on the given fields, to speed up future processing speed
when using this as a barrier.
Summary:
This function unsplit a line feature of roads to reduce the number of objects in future processing.
Parameters:
input_n100 (str): The path to the input feature class containing the lines to be unsplit.
output_feature_class (str): The name of the output feature class to be created.
fields (List[str]): The list of fields to use for unsplitting the lines.
Details:
- It takes the input line feature `input_n100.VegSti` and removes any geometric splits.
- The feature is dissolved based on the fields "subtypekode," "motorvegtype," and "UTTEGNING" to merge segments with the same values in these fields.
"""

arcpy.UnsplitLine_management(
in_features=input_n100.VegSti,
out_feature_class=Building_N100.preperation_veg_sti__unsplit_veg_sti__n100.value,
Expand All @@ -143,14 +165,16 @@ def preperation_veg_sti():

def adding_matrikkel_as_points():
"""
Adds building points from matrikkel for areas which no longer are urban areas.
This function performs the following steps:
1. Selects features and creates a layer from the input_n100.ArealdekkeFlate layer which are urban.
2. Selects features and creates a layer from the input_n50.ArealdekkeFlate layer which are urban.
3. Adds a buffer to the urban selection from n100 as a short hand for symbology.
4. Removes areas from n50 urban areas from the buffer of n|50 urban areas resulting in areas in n100 which no longer are urban.
5. Selects matrikkel bygningspunkter based on this new urban selection layer, and adds NBR values to the created points.
Summary:
This function adds building points from the matrikkel dataset for areas that are no longer considered urban after the generalization of "arealdekke." It also adds the required fields and values for future analysis.
Details:
- Define an SQL expression to select urban areas ('Tettbebyggelse', 'Industriområde', 'BymessigBebyggelse') in the "arealdekke" dataset.
- Select urban areas from "arealdekke" in both n100 and n50 datasets using the defined SQL expression.
- Create a buffer of the selected urban areas from n100 to consider symbology using a 50-meter buffer distance.
- Remove areas from n50 urban areas that intersect with the buffer of n100 urban areas, resulting in areas in n100 that are no longer considered urban.
- Select matrikkel bygningspunkter based on the new urban selection layer.
- Transfer the NBR (building type) value to the matrikkel_bygningspunkt dataset by adding a new field "BYGGTYP_NBR" of type LONG and calculating its values from the "bygningstype" field.
"""

# Defining sql expression to select urban areas
Expand Down Expand Up @@ -213,13 +237,21 @@ def adding_matrikkel_as_points():

def selecting_grunnriss_for_generalization():
"""
Selects grunnriss features for generalization based on a given SQL expression.
Summary:
This function selects building polygons (grunnriss) to be generalized. Smaller polygons and churches or hospitals are excluded, transformed into points, and sent to building point generalization.
Details:
- Reclassify "sykehus" from grunnriss to another NBR value.
- Calculate the new NBR values for "sykehus" using a Python code block.
- Define SQL expressions to select "sykehus" and churches ("kirke") based on their NBR values.
- Select grunnriss that are not churches or hospitals using inverted selection.
- Select grunnriss that are large enough based on a minimum polygon size of 1500 square meters.
- Transform small grunnriss features into points by calculating centroids.
- Select grunnriss features that represent churches and hospitals.
- Transform selected church and hospital grunnriss features into points by calculating centroids.
This function first selects all grunnriss features that are not churches or hospitals based on the NBR values (970, 719, 671).
These selected features are then used for polygon generalization.
Additionally, this function transforms the selected hospitals and churches into points using the 'CENTROID' method.
These points are used for point generalization.
Parameters:
- Minimum polygon size (int): The minimum size of polygons are 1500 square meters.
"""

# Reclassify the sykehus from grunnriss to another NBR value
Expand Down

0 comments on commit f19366f

Please sign in to comment.