Skip to content

Commit

Permalink
681 enh add client docs for multipolygon (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekorman authored Jul 29, 2024
1 parent 5c64c17 commit 8d52ca4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client/unit-tests/symbolic/types/test_symbolic_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,18 @@ def test_multipolygon():
with pytest.raises(ValueError):
objcls(permutations[0][0]).area

# test `from_polygons` class method

poly1_boundary = [(0, 0), (1, 1), (0, 1), (0, 0)]
poly2_boundary = [(0, 10), (5, 5), (0, 5), (0, 10)]
poly2_hole = [(0.1, 0.1), (0.9, 0.9), (0.1, 0.9), (0.1, 0.1)]
polys = [Polygon([poly1_boundary]), Polygon([poly2_boundary, poly2_hole])]
multi_poly = MultiPolygon.from_polygons(polys)
assert multi_poly.get_value() == [
[poly1_boundary],
[poly2_boundary, poly2_hole],
]


def test_nullable():

Expand Down
17 changes: 17 additions & 0 deletions client/valor/schemas/symbolic/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,23 @@ def to_polygons(self) -> typing.List[Polygon]:
"""
return [Polygon(poly) for poly in self.get_value()]

@classmethod
def from_polygons(self, polygons: typing.List[Polygon]) -> "MultiPolygon":
"""
Converts a list of Polygon instances to a MultiPolygon.
Parameters
----------
polygons : List[Polygon]
A list of Polygon instances.
Returns
-------
MultiPolygon
A MultiPolygon instance.
"""
return MultiPolygon([poly.get_value() for poly in polygons])


T = typing.TypeVar("T", bound=Variable)

Expand Down
16 changes: 16 additions & 0 deletions docs/client_api/Schemas/Spatial/MultiPolygon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
::: valor.schemas.MultiPolygon
handler: python
options:
show_root_heading: false
show_root_toc_entry: false
show_root_full_path: true
show_root_members_full_path: false
show_object_full_path: true
show_category_heading: True
show_if_no_docstring: false
show_signature: true
show_signature_annotations: false
show_bases: true
group_by_category: true
heading_level: 2
members_order: alphabetical

0 comments on commit 8d52ca4

Please sign in to comment.