Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test to show property preservation #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions supermercado/super_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,40 @@ def filter_features(features):
elif f["geometry"]["type"] == "LineString":
yield f
elif f["geometry"]["type"] == "MultiPolygon":
base_feature = {}
if "properties" in f:
base_feature.update(properties=f["properties"])
for part in f["geometry"]["coordinates"]:
yield {
"type": "Feature",
"geometry": {"type": "Polygon", "coordinates": part},
**{
"type": "Feature",
"geometry": {"type": "Polygon", "coordinates": part},
},
**base_feature,
}
elif f["geometry"]["type"] == "MultiPoint":
base_feature = {}
if "properties" in f:
base_feature.update(properties=f["properties"])
for part in f["geometry"]["coordinates"]:
yield {
"type": "Feature",
"geometry": {"type": "Point", "coordinates": part},
**{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": part},
},
**base_feature,
}
elif f["geometry"]["type"] == "MultiLineString":
base_feature = {}
if "properties" in f:
base_feature.update(properties=f["properties"])
for part in f["geometry"]["coordinates"]:
yield {
"type": "Feature",
"geometry": {"type": "LineString", "coordinates": part},
**{
"type": "Feature",
"geometry": {"type": "LineString", "coordinates": part},
},
**base_feature,
}


Expand Down
96 changes: 96 additions & 0 deletions tests/test_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,42 @@ def test_filter_features_multi_polygon():
assert list(sutils.filter_features(features)) == expected


def test_filter_features_multi_polygon_preserve_properties():
"""MultiPolygons should be turned into multiple Polygons"""
features = [
{
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
],
},
"properties": {"a": "property"},
}
]
expected = [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
},
"properties": {"a": "property"},
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]]],
},
"properties": {"a": "property"},
},
]
assert list(sutils.filter_features(features)) == expected


def test_filter_features_multi_point():
"""MultiPoints should be turned into multiple Points"""
features = [
Expand All @@ -152,6 +188,30 @@ def test_filter_features_multi_point():
assert list(sutils.filter_features(features)) == expected


def test_filter_features_multi_point_properties():
"""MultiPoints should be turned into multiple Points"""
features = [
{
"type": "Feature",
"geometry": {"type": "MultiPoint", "coordinates": [[0, 0], [1, 0]]},
"properties": {"a": "property"},
}
]
expected = [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [0, 0]},
"properties": {"a": "property"},
},
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [1, 0]},
"properties": {"a": "property"},
},
]
assert list(sutils.filter_features(features)) == expected


def test_filter_features_multi_linstrings():
"""MultiLineStrings should be turned into multiple LineStrings"""
features = [
Expand Down Expand Up @@ -185,6 +245,42 @@ def test_filter_features_multi_linstrings():
assert list(sutils.filter_features(features)) == expected


def test_filter_features_multi_linstrings_properties():
"""MultiLineStrings should be turned into multiple LineStrings"""
features = [
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
[[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
],
},
"properties": {"a": "property"},
}
]
expected = [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
},
"properties": {"a": "property"},
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[0, 0], [1, 0], [1, 1], [0, 1], [0, 1]],
},
"properties": {"a": "property"},
},
]
assert list(sutils.filter_features(features)) == expected


def test_find_extrema():
"""Extrema should be calculated correctly"""
features = [
Expand Down