kartograph未知形状类型(25)

时间:2015-01-06 00:13:08

标签: python-2.7 svg shapefile kartograph

我正在尝试使用kartograph py生成一个svg地图,如下所示:

from kartograph import Kartograph
K = Kartograph()
config ={"layers": {"mylayer": {"src": "42MEE250GC_SIR.shp"}} }
K.generate(config, outfile='mymap.svg')

我收到了这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\k
artograph.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\m
ap.py", line 48, in __init__
    me.proj = me._init_projection()
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\m
ap.py", line 88, in _init_projection
    map_center = self.__get_map_center()
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\m
ap.py", line 140, in __get_map_center
    features = self._get_bounding_geometry()
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\m
ap.py", line 257, in _get_bounding_geometry
    charset=layer.options['charset']
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\l
ayersource\shplayer.py", line 121, in get_features
    geom = shape2geometry(shp, ignore_holes=ignore_holes, min_area=min_area, bbo
x=bbox, proj=self.proj)
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\l
ayersource\shplayer.py", line 159, in shape2geometry
    raise KartographError('unknown shape type (%d)' % shp.shapeType)
kartograph.errors.KartographError: ←[0;31;40mKartograph-Error:←[0m unknown shape
 type (25)

查看kartograph的源代码,我们有:

    if shp.shapeType in (5, 15):  # multi-polygon
        geom = shape2polygon(shp, ignore_holes=ignore_holes, min_area=min_area)
    elif shp.shapeType == 3:  # line
        geom = points2line(shp)
    else:
        raise KartographError('unknown shape type (%d) in shapefile %s' % (shp.shapeType, self.shpSrc))
    return geom

有人可以帮我这个吗?

我在下面尝试了这个,但是我又收到了另一个错误。

if shp.shapeType == 25:
  return None

错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\k
artograph.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\m
ap.py", line 50, in __init__
    me.bounds_poly = me._init_bounds()
  File "c:\python27\lib\site-packages\kartograph.py-0.6.8-py2.7.egg\kartograph\m
ap.py", line 205, in _init_bounds
    raise KartographError('no features found for calculating the map bounds')
kartograph.errors.KartographError: ←[0;31;40mKartograph-Error:←[0m no features f
ound for calculating the map bounds

1 个答案:

答案 0 :(得分:0)

我找到的解决方案是更改源代码,添加:

if shp.shapeType == 25:
  geom = points2line(shp)

我确信这不是最佳解决方案,但它解决了我的问题