Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
xrotwang committed May 17, 2024
1 parent 5e815ba commit 50aa5ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changes

## Unreleased

- Subtract buffer from merged geometries after merging.


## [0.2.0] - 2024-04-26

- Allow specifying buffer when aggregating shapes.
Expand Down
14 changes: 9 additions & 5 deletions src/cldfgeojson/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,26 @@ def merged_geometry(features: typing.Iterable[typing.Union[geojson.Feature, geoj
:param features: An iterable of geographic structures.
:param buffer: A buffer to be added to the shapes in order to make them overlap, thereby \
removing internal boundaries when merging. Specify `None` to add no buffer.
removing internal boundaries when merging. Will be subtracted from the merged geometry. \
Specify `None` to add no buffer.
:return: The resulting Geometry object representing the merged shapes.
"""
def get_shape(f):
s = shape(f.get('geometry', f))
if buffer:
s = s.buffer(buffer)
return s
return union_all([get_shape(f) for f in features])
res = union_all([get_shape(f) for f in features])
if buffer:
res = res.buffer(-buffer)
return res.__geo_interface__


def aggregate(shapes: typing.Iterable[typing.Tuple[str, geojson.Feature, str]],
glottolog: typing.Union[Glottolog, Dataset],
level: str = 'language',
buffer: typing.Union[float, None] = 0.001,
opacity: float = 0.8,
) -> typing.Tuple[
typing.List[geojson.Feature],
typing.List[typing.Tuple[Languoid, list, str]]]:
Expand Down Expand Up @@ -154,7 +159,6 @@ def is_language(glang):
'fill': colors[lang2fam[gc]],
'family': glangs[lang2fam[gc]].name if lang2fam[gc] != gc else None,
'cldf:languageReference': gc,
'fill-opacity': 0.8},
geometry=merged_geometry(
[p[1] for p in polys_by_code[gc]], buffer=buffer).__geo_interface__))
'fill-opacity': opacity},
geometry=merged_geometry([p[1] for p in polys_by_code[gc]], buffer=buffer)))
return features, languoids

0 comments on commit 50aa5ea

Please sign in to comment.