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

Error when changing covering area #50

Closed
matdeof opened this issue Aug 23, 2019 · 4 comments
Closed

Error when changing covering area #50

matdeof opened this issue Aug 23, 2019 · 4 comments

Comments

@matdeof
Copy link

matdeof commented Aug 23, 2019

Hello,

I'm using s2 geometry to create a grid over a rectangle. The idea is basically to discretize a given city space, as follows:

image

Once i have the geometry i'm passing it to the topojson method Topology(dictionary, prequantize=False, topology=True).

The problem is that it only works with some geometries and s2 cells levels, for example when it works for the cell level 13 but it returns an error for cell level 12. I'm running python 3.6.6 and windows 10.

Thanks in advance!

I'm getting this error:


TypeError Traceback (most recent call last)
in ()
73 j = j + 1
74
---> 75 tj = topojson.Topology(dictionary)
76 tj.to_json()

c:\users\matheus.ferreira\appdata\local\programs\python\python36\lib\site-packages\topojson\core\topology.py in init(self, data, topology, prequantize, topoquantize, presimplify, toposimplify, simplify_with, simplify_algorithm, winding_order)
94 options = TopoOptions(locals())
95 # execute previous steps
---> 96 super().init(data, options)
97
98 # execute main function of Topology

c:\users\matheus.ferreira\appdata\local\programs\python\python36\lib\site-packages\topojson\core\hashmap.py in init(self, data, options)
20 def init(self, data, options={}):
21 # execute previous step
---> 22 super().init(data, options)
23
24 # initation topology items

c:\users\matheus.ferreira\appdata\local\programs\python\python36\lib\site-packages\topojson\core\dedup.py in init(self, data, options)
26
27 # execute main function of Dedup
---> 28 self.output = self.deduper(self.output)
29
30 def repr(self):

c:\users\matheus.ferreira\appdata\local\programs\python\python36\lib\site-packages\topojson\core\dedup.py in deduper(self, data)
75 # apply linemerge on geoms containing contigious arcs and maintain
76 # bookkeeping
---> 77 self.merge_contigious_arcs(data, sliced_array_bk_ndp)
78
79 # pop the merged contigious arcs and maintain bookkeeping.

c:\users\matheus.ferreira\appdata\local\programs\python\python36\lib\site-packages\topojson\core\dedup.py in merge_contigious_arcs(self, data, sliced_array_bk_ndp)
217
218 # replace linestring of idx_keep with merged linestring
--> 219 data["linestrings"][idx_keep] = ndp_arcs[idx_merg_arc]
220 self.merged_arcs_idx.append(idx_pop)
221

TypeError: list indices must be integers or slices, not NoneType

@mattijn
Copy link
Owner

mattijn commented Aug 23, 2019

Thanks for raising the issue. Could you please provide a small reproducible code snippet of the geometry that gives this error?

@mattijn
Copy link
Owner

mattijn commented Aug 23, 2019

I can reproduce the issue:

import s2sphere as s2
from shapely import geometry
import topojson

region_rect = s2.LatLngRect(
s2.LatLng.from_degrees(-51.264871, -30.241701),
s2.LatLng.from_degrees(-51.04618, -30.000003))
coverer = s2.RegionCoverer()
coverer.min_level=10
coverer.max_level=11
coverer.max_cells=500
covering = coverer.get_covering(region_rect)

geoms = []
for cellid in covering:
    new_cell = s2.Cell(cellid)
    vertices = []
    for i in range(0, 4):
        vertex = new_cell.get_vertex(i)
        latlng = s2.LatLng.from_point(vertex)
        vertices.append((latlng.lat().degrees,latlng.lng().degrees))
    geo = geometry.Polygon(vertices)
    geoms.append(geo)
print("Total Geometries: {}".format(len(geoms)))

geometry.GeometryCollection(geoms)
Total Geometries: 19

image

topojson.Topology(geoms, prequantize=False, topology=True)
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-2-a207dd4fcbb5> in <module>
----> 1 topojson.Topology(geoms, prequantize=False, topology=True)


~/topojson/topojson/core/topology.py in __init__(self, data, topology, prequantize, topoquantize, presimplify, toposimplify, simplify_with, simplify_algorithm, winding_order)
     94         options = TopoOptions(locals())
     95         # execute previous steps
---> 96         super().__init__(data, options)
     97 
     98         # execute main function of Topology


~/topojson/topojson/core/hashmap.py in __init__(self, data, options)
     20     def __init__(self, data, options={}):
     21         # execute previous step
---> 22         super().__init__(data, options)
     23 
     24         # initation topology items


~/topojson/topojson/core/dedup.py in __init__(self, data, options)
     26 
     27         # execute main function of Dedup
---> 28         self.output = self.deduper(self.output)
     29 
     30     def __repr__(self):


~/topojson/topojson/core/dedup.py in deduper(self, data)
     77             # apply linemerge on geoms containing contigious arcs and maintain
     78             # bookkeeping
---> 79             self.merge_contigious_arcs(data, sliced_array_bk_ndp)
     80 
     81             # pop the merged contigious arcs and maintain bookkeeping.


~/topojson/topojson/core/dedup.py in merge_contigious_arcs(self, data, sliced_array_bk_ndp)
    219 
    220                 # replace linestring of idx_keep with merged linestring
--> 221                 data["linestrings"][idx_keep] = ndp_arcs[idx_merg_arc]
    222                 self.merged_arcs_idx.append(idx_pop)
    223 


TypeError: list indices must be integers or slices, not NoneType

@mattijn
Copy link
Owner

mattijn commented Aug 26, 2019

Previously the Dedup class deduplicate identical arcs and tries to apply a line merge on non-duplicate LineStrings. In this line merging section it assumed that this only could happen on 2 arcs. This assumption proved wrong and is fixed by #51.

@mattijn mattijn closed this as completed Aug 26, 2019
@matdeof
Copy link
Author

matdeof commented Aug 29, 2019

Sorry, the late reply.

Got it, thanks a lot @mattijn !!

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