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: handling of a single point coordinate in a MultiPoint geometry #210

Merged
merged 2 commits into from
Oct 19, 2023
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
8 changes: 8 additions & 0 deletions tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ def test_topology_to_geojson_polygon_point():
assert "]}}]}" in topo # feat 2


# test for https://github.com/mattijn/topojson/issues/209
def test_topology_to_geojson_singepoint_in_multipoint():
data = [{"type": "MultiPoint", "coordinates": [[0.5, 0.5]]}]
geo = topojson.Topology(data).to_geojson()

assert "]]}}]}" in geo


def test_topology_to_geojson_quantized_points_only():
data = [{"type": "MultiPoint", "coordinates": [[0.5, 0.5], [1.0, 1.0]]}]
geo = topojson.Topology(data, prequantize=False).to_geojson()
Expand Down
8 changes: 2 additions & 6 deletions topojson/core/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def __init__(
winding_order="CW_CCW",
object_name="data",
):

options = TopoOptions(locals())

# shortcut when dealing with topojson data
Expand Down Expand Up @@ -496,7 +495,7 @@ def toposimplify(
# dequantize if transform exist
if transform is not None:
power_estimate = len(str(int(np_arcs[:, 0].max())))
quant_factor_estimate = 10 ** power_estimate
quant_factor_estimate = 10**power_estimate
np_arcs = dequantize(np_arcs, scale, translate)

# apply simplify
Expand Down Expand Up @@ -547,17 +546,14 @@ def toposimplify(
return result

def _resolve_coords(self, data):

for objectname in self.options.object_name:

if objectname not in data["objects"]:
raise SystemExit(
f"'{objectname}' is not an object name in your topojson file"
)
geoms = data["objects"][objectname]["geometries"]
for idx, feat in enumerate(geoms):
if feat["type"] in ["Point", "MultiPoint"]:

lofl = feat["coordinates"]
repeat = 1 if feat["type"] == "Point" else 2

Expand All @@ -568,7 +564,7 @@ def _resolve_coords(self, data):
coord = data["coordinates"][val][0]
lofl[idx] = np.asarray(coord).tolist()

feat["coordinates"] = lofl[0] if len(lofl) == 1 else lofl
feat["coordinates"] = lofl[0] if feat["type"] == "Point" else lofl
feat.pop("reset_coords", None)
data.pop("coordinates", None)
return data
Expand Down
Loading