Skip to content

Commit

Permalink
docs: simplify docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Dec 18, 2023
1 parent 23ff785 commit eed9eb1
Showing 1 changed file with 12 additions and 37 deletions.
49 changes: 12 additions & 37 deletions sketch_map_tool/upload_processing/post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def clean(fc: FeatureCollection) -> FeatureCollection:


def enrich(fc: FeatureCollection, properties):
"""Enrich GeoJSON properties and map colors."""
"""Enrich GeoJSON properties and add color information to them."""
for feature in fc.features:
feature.properties = feature.properties | properties
if "color" in feature.properties.keys():
Expand All @@ -44,23 +44,17 @@ def enrich(fc: FeatureCollection, properties):


def simplify(fc: FeatureCollection) -> FeatureCollection:
"""
Simplifies the geometries in a GeoJSON FeatureCollection.
This function simplifies the geometries in a given FeatureCollection. It applies a buffer operation
to each geometry based on a percentage of the maximum width, dissolves the geometries based on a
'color' attribute, removes inner rings, and then re-applies a negative buffer to restore the original
size. The function assumes that the 'color' field exists in the properties of the features.
"""Simplifies the geometries in a GeoJSON FeatureCollection.
Parameters:
- fc (geojson.FeatureCollection): The FeatureCollection to be simplified.
Buffers each geometry based on a percentage of the maximum width, dissolves the
geometries based on the 'color' attribute, removes inner rings, and then re-applies
a negative buffer to restore the original size.
Returns:
- geojson.FeatureCollection: The simplified FeatureCollection.
The function assumes that the 'color' field exists in the properties of the
features.
"""
features = fc["features"]
properties = features[0]["properties"]

geometries = [shape(feature["geometry"]) for feature in features]

# Buffer operation
Expand Down Expand Up @@ -104,19 +98,7 @@ def simplify(fc: FeatureCollection) -> FeatureCollection:


def remove_inner_rings(geometry: Polygon | MultiPolygon) -> Polygon | MultiPolygon:
"""
Removes inner rings (holes) from a given Shapely geometry object.
This function checks the type of the geometry object. If it is a Polygon, it creates
a new Polygon with just the exterior ring. If it is a MultiPolygon, it does the same
for each Polygon in it. Other geometry types are not supported and will raise an error.
Parameters:
- geometry (Polygon, MultiPolygon): A Shapely geometry object, either a Polygon or MultiPolygon.
Returns:
- Polygon, MultiPolygon: A Shapely geometry object with inner rings removed.
"""
"""Removes inner rings (holes) from a given Shapely geometry object."""
if geometry.is_empty:
return geometry
elif geometry.type == "Polygon":
Expand All @@ -128,18 +110,11 @@ def remove_inner_rings(geometry: Polygon | MultiPolygon) -> Polygon | MultiPolyg


def smooth(fc: FeatureCollection) -> FeatureCollection:
"""
Smoothens the polygon geometries in a GeoJSON FeatureCollection.
This function applies a Chaikin smoothing algorithm to each polygon geometry in the given
FeatureCollection. Non-polygon geometries are skipped. The function updates the geometries
while retaining the properties of each feature.
Parameters:
- fc (geojson.FeatureCollection): The FeatureCollection to be smoothed.
"""Smoothens the polygon geometries in a GeoJSON FeatureCollection.
Returns:
- geojson.FeatureCollection: The FeatureCollection with smoothed polygon geometries.
This function applies a Chaikin smoothing algorithm to each polygon geometry in the
given FeatureCollection. Non-polygon geometries are skipped. The function updates
the geometries while retaining the properties of each feature.
"""
features = fc["features"]
updated_features = []
Expand Down

0 comments on commit eed9eb1

Please sign in to comment.