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

Fix: topology for data without junctions and shared_coords=False, prequantize=False gives error #182

Merged
merged 3 commits into from
Sep 1, 2022
Merged
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
34 changes: 31 additions & 3 deletions tests/test_topology.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import json
from shapely import geometry, wkt
import geopandas
import geojson
import pytest

import fiona
import geojson
import geopandas
from shapely import geometry, wkt

import topojson


Expand Down Expand Up @@ -633,3 +636,28 @@ def test_topology_write_multiple_object_json_dict():
topo_dict = topo.to_dict()

assert len(topo_dict["objects"]) == 2


@pytest.mark.parametrize(
"shared_coords, prequantize",
[(True, True), (True, False), (False, True), (False, False)]
)
def test_topology_polygon_filled_island_no_junctions(shared_coords, prequantize):
data = geopandas.GeoDataFrame(
{
"name": ["abcde_fghij", "jihgf"],
"geometry": [
geometry.Polygon(
shell=[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]],
holes=[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]],
),
geometry.Polygon([[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]),
]
}
)
topo = topojson.Topology(data, prequantize=prequantize, shared_coords=shared_coords)
topo_gdf = topo.to_gdf()

assert len(topo.output["arcs"]) == 2
assert topo_gdf.geometry[0] == data["geometry"][0]
assert topo_gdf.geometry[1] == data["geometry"][1]
4 changes: 2 additions & 2 deletions topojson/core/cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ def _cutter(self, data):
bk_array = np.expand_dims(
bk_array[~np.isnan(bk_array)].astype(np.int64), axis=1
)
self._segments_list = data["linestrings"]
self._segments_list = [np.array(ls.coords) for ls in data["linestrings"]]
self._duplicates = find_duplicates(data["linestrings"], type="linestring")
self._bookkeeping_linestrings = bk_array

else:
self._segments_list = data["linestrings"]
self._segments_list = [np.array(ls.coords) for ls in data["linestrings"]]

# prepare to return object
data["linestrings"] = self._segments_list
Expand Down
3 changes: 0 additions & 3 deletions topojson/core/dedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def _deduper(self, data):

# deduplicate equal geometries
# create numpy array from bookkeeping_geoms variable for numerical computation
if not self.options.topology and data["linestrings"]:
data["linestrings"] = [np.array(d.coords) for d in data["linestrings"]]

if len(data["bookkeeping_linestrings"]):
array_bk = np.vstack(data["bookkeeping_linestrings"])
else:
Expand Down