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

Type GeometryCollection from package shapely cannot be parsed directly #13

Closed
mattijn opened this issue Mar 24, 2019 · 2 comments
Closed

Comments

@mattijn
Copy link
Owner

mattijn commented Mar 24, 2019

See following code:

from shapely import geometry

geom_collection = geometry.GeometryCollection([
    geometry.Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]), 
    geometry.Polygon([[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]])
])
geom_collection

Screenshot 2019-03-24 at 22 38 18

topojson.topology(geom_collection)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-2442f763691d> in <module>()
----> 1 topojson.topology(geom_collection)

~/topojson/topojson/topology.py in topology(data, snap_vertices, gridsize_to_snap, simplify, simplify_factor)
     24 
     25     # apply topology to data
---> 26     data = extractor.main(data)
     27 
     28     if snap_vertices:

~/topojson/topojson/extract.py in main(self, data)
    367 
    368         self.data = data
--> 369         self.serialize_geom_type(data)
    370 
    371         # prepare to return object

~/topojson/topojson/utils/dispatcher.py in wrapper(*args, **kw)
     16 
     17     def wrapper(*args, **kw):
---> 18         return dispatcher.dispatch(args[1].__class__)(*args, **kw)
     19 
     20     wrapper.register = dispatcher.register

~/topojson/topojson/extract.py in extract_geometrycollection(self, geom)
    177         """
    178 
--> 179         obj = self.data[self.key]
    180         self.geomcollection_counter += 1
    181         self.records_collection = len(geom)

AttributeError: 'Extract' object has no attribute 'key'
@perrette
Copy link

perrette commented Mar 4, 2020

May I ask why the geometry collection works, but

> geom = geometry.Polygon([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
> topojson.Topology(geom)
...
AttributeError: 'Topology' object has no attribute 'obj'

does not?

After all, the topojson formal should also work for a single piece of geometry, shouldn't it?

@mattijn
Copy link
Owner Author

mattijn commented Mar 4, 2020

Sounds like a bug. Yes the topojson format should be able to support a single geometry. Never came up before as the computation of the topology cannot be done with a single geometry. I'll open a new issue to track this.

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