Pregunta

I am trying to render an SVG map using Kartograph.py. It throws me the TypeError. Here is the python code:

import kartograph
from kartograph import Kartograph
import sys
from kartograph.options import read_map_config
css = open("stylesheet.css").read()
K = Kartograph()
cfg = read_map_config(open("config.json"))
K.generate(cfg, outfile='dd.svg', format='svg', stylesheet=css)

Here is the error it throws

Traceback (most recent call last):
  File "<pyshell#33>", line 1, in <module>
    K.generate(cfg, outfile='dd.svg', format='svg', stylesheet=css)
  File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\kartograph.py", line 46, in generate
    _map = Map(opts, self.layerCache, format=format)
  File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\map.py", line 61, in __init__
    layer.get_features()
  File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\maplayer.py", line 81, in get_features
    charset=layer.options['charset']
  File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 121, in get_features
    geom = shape2geometry(shp, ignore_holes=ignore_holes, min_area=min_area, bbox=bbox, proj=self.proj)
  File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 153, in shape2geometry
    geom = shape2polygon(shp, ignore_holes=ignore_holes, min_area=min_area, proj=proj)
  File "C:\Python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\layersource\shplayer.py", line 217, in shape2polygon
    poly = MultiPolygon(polygons)
  File "C:\Python27\lib\site-packages\shapely\geometry\multipolygon.py", line 74, in __init__
    self._geom, self._ndim = geos_multipolygon_from_polygons(polygons)
  File "C:\Python27\lib\site-packages\shapely\geometry\multipolygon.py", line 30, in geos_multipolygon_from_polygons
    N = len(ob[0][0][0])
TypeError: 'Polygon' object does not support indexing
¿Fue útil?

Solución

I had a look at shapely and it seems like you are using an outdated version. Update your current install:

pip install -U shapely
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top