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

MultiLineString cannot be created from a LineString + MultiLineString #63

Closed
mattijn opened this issue Nov 30, 2019 · 0 comments · Fixed by #64
Closed

MultiLineString cannot be created from a LineString + MultiLineString #63

mattijn opened this issue Nov 30, 2019 · 0 comments · Fixed by #64

Comments

@mattijn
Copy link
Owner

mattijn commented Nov 30, 2019

from IPython.display import SVG, display
from topojson.core.extract import Extract
from shapely import geometry
from shapely.ops import linemerge
from shapely.ops import shared_paths
data = [
    {
        "type": "LineString",
        "coordinates": [(0, 0), (10, 0), (10, 5), (20, 5)],
    },
    {
        "type": "LineString",
        "coordinates": [(5, 0), (25, 0), (25, 5), (16, 5), (16, 10), (14, 10), (14, 5), (0, 5)],
    }
]
ex = Extract(data).output
lines = geometry.MultiLineString(ex['linestrings'])
svg_lines = lines._repr_svg_()
svg_lines = svg_lines.replace('stroke="#66cc99"', 'stroke="orange"', 1)
svg_lines = svg_lines.replace('stroke-width="0.54"', 'stroke-width="1.5"', 1)
svg_lines = svg_lines.replace('opacity="0.8"', 'opacity="0.4"', 1)

display(SVG(svg_lines))

image

g1 = ex['linestrings'][0]
g2 = ex['linestrings'][1]
fw, bw = shared_paths(g1, g2)
linemerge(fw)

image

linemerge(bw)

image

geometry.MultiLineString([linemerge(fw), linemerge(bw)])
---------------------------------------------------------------------------

NotImplementedError                       Traceback (most recent call last)

<ipython-input-8-7691d6f56d9d> in <module>
----> 1 geometry.MultiLineString([linemerge(fw), linemerge(bw)])


~/miniconda3/lib/python3.7/site-packages/shapely/geometry/multilinestring.py in __init__(self, lines)
     50             pass
     51         else:
---> 52             self._geom, self._ndim = geos_multilinestring_from_py(lines)
     53 
     54     def shape_factory(self, *args):


~/miniconda3/lib/python3.7/site-packages/shapely/geometry/multilinestring.py in geos_multilinestring_from_py(ob)
    132     # add to coordinate sequence
    133     for l in range(L):
--> 134         geom, ndims = linestring.geos_linestring_from_py(obs[l])
    135         subs[l] = cast(geom, c_void_p)
    136 


~/miniconda3/lib/python3.7/site-packages/shapely/speedups/_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()


~/miniconda3/lib/python3.7/site-packages/shapely/geometry/base.py in __array_interface__(self)
    792     def __array_interface__(self):
    793         """Provide the Numpy array protocol."""
--> 794         raise NotImplementedError("Multi-part geometries do not themselves "
    795                                   "provide the array interface")
    796 


NotImplementedError: Multi-part geometries do not themselves provide the array interface
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

Successfully merging a pull request may close this issue.

1 participant