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

datasets including Points breaks computing the topology #61

Closed
theluxaz opened this issue Sep 25, 2019 · 5 comments
Closed

datasets including Points breaks computing the topology #61

theluxaz opened this issue Sep 25, 2019 · 5 comments

Comments

@theluxaz
Copy link

Tried various different ways to turn features and feature collections into a Topology object by feeding geoJson object, or Feature and FeatureCollection objects as shows in the docs, but did not manage. Keep getting errors:
Mostly:

  • not enough values to unpack (expected 4, got 0)
  • list indices must be integers or slices, not float

Sometimes:

  • simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

any ideas how to fix this?

@mattijn
Copy link
Owner

mattijn commented Sep 25, 2019

Thanks for filling this issue. Could you also share the GeoJSON that gives the errors?
Than I can have look

@theluxaz
Copy link
Author

This is an example json feature collection with 4 features which i could not convert to any way to topojson. It is quite a complex polygon so sorry for hard to read file. Couldn't even convert each feature separately in any way.

I would be really grateful if you could show me a way how it could be acomplished, i'm sure it would be really useful for a lot of people in the future with similar problems :)

geojson show.zip

@mattijn
Copy link
Owner

mattijn commented Sep 26, 2019

Thanks for sharing the file. There is nothing wrong with your data. Temporary solution: if you remove the Points from your geojson file it will be parsed correctly.

Bugs that I've to solve:
Multiple things are going wrong here regarding data collections containing Points.

  1. If there is a data collection that has a combination of Points and Polygons as such:
polygon_point = [
    {
        "type": "Polygon",
        "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]
    },
    {
        "type": "Point",
        "coordinates": [0.5, 0.5]
    }
]

Than the Extract class parses the Point type incorrectly into an arcs object containing the coordinate.

import topojson as tp
from topojson.core.extract import Extract

Extract(polygon_point)
Extract(
{'bookkeeping_geoms': [[0]],
 'linestrings': [<shapely.geometry.linestring.LineString object at 0x0000000008B5B588>],
 'objects': {0: {'arcs': [0], 'type': 'Polygon'},
             1: {'arcs': [0.5, 0.5], 'type': 'Point'}},
 'options': TopoOptions(
  {'prequantize': False,
 'presimplify': False,
 'simplify_algorithm': 'dp',
 'simplify_with': 'shapely',
 'topology': True,
 'topoquantize': False,
 'toposimplify': False,
 'winding_order': None}
),
 'type': 'Topology'}
)

The coordinates of type Point or Multipoint should remain as coordinates.

Otherwise you will hit indeed the following error:

tp.Topology(polygon_point)
c:\programdata\miniconda3\lib\site-packages\topojson\core\hashmap.py in resolve_bookkeeping(self, geoms)
    311         arcs = []
    312         for geom in geoms:
--> 313             arcs_in_geom = self.data["bookkeeping_geoms"][geom]
    314             for idx_arc, arc_ref in enumerate(arcs_in_geom):
    315                 arc_ids = self.data["bookkeeping_arcs"][arc_ref]

TypeError: list indices must be integers or slices, not float
  1. Moreover, if there is a data object containing only a Point as such:
point = [
    {
        "type": "Point",
        "coordinates": [0.5, 0.5]
    }
]

tp.Topology(point)

It cannot compute a bounding box since topojson currently only considers parsed linestrings:

c:\programdata\miniconda3\lib\site-packages\topojson\core\join.py in joiner(self, data)
    136 
    137             data["linestrings"], data["transform"] = quantize(
--> 138                 data["linestrings"], data["bbox"], quant_factor
    139             )
    140 

c:\programdata\miniconda3\lib\site-packages\topojson\ops.py in quantize(linestrings, bbox, quant_factor)
    403     """
    404 
--> 405     x0, y0, x1, y1 = bbox
    406 
    407     kx = 1 / ((quant_factor - 1) / (x1 - x0))

ValueError: not enough values to unpack (expected 4, got 0)
  1. This also means there is currently no delta-encoding of Points within topojson.

@theluxaz
Copy link
Author

theluxaz commented Oct 1, 2019

I see, Thank you very much for your detailed answer!!!
I will find a workaround for Points.

Wish you all the best.

@mattijn
Copy link
Owner

mattijn commented Nov 3, 2019

Fixed by #62

@mattijn mattijn closed this as completed Nov 3, 2019
@mattijn mattijn changed the title Can't get GeoJson to TopoJson to work datasets including Points breaks computing the topology Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants