I am new to GIS and open source tools so bear with me.

I am attempting to convert a shapefile to svg by running kartograph as a python module. My source file (provided by the local GIS Administration) contains nearly 50,000 parcels of land and I only want to carry over a single attribute for each parcel (which I will use for colorizing later). Here is my code:

from kartograph import Kartograph
K = Kartograph()

config = {
    "layers": {
        "county": { 
            "src": "parcels.shp",
            "attributes": {
                    "id": "XXDSDS"

K.generate(config, outfile='test-file.svg')  

The following error results:

Traceback (most recent call last): File "test.py", line 19, in K.generate(config, outfile='test-file.svg') File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/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 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/map.py", line 48, in init me.proj = me._init_projection() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/map.py", line 88, in _init_projection map_center = self.__get_map_center() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/map.py", line 140, in __get_map_center features = self._get_bounding_geometry() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/map.py", line 257, in _get_bounding_geometry charset=layer.options['charset'] File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/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 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/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 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/layersource/shplayer.py", line 170, in shape2polygon parts = shp.parts[:] AttributeError: _Shape instance has no attribute 'parts'

I have run the code using a different source file (U.S. county map) and the conversion worked, so I don't think there are any code or version problems. I assume kartograph is looking for something in my source file that it can't find or doesn't exist.

Can anyone help me troubleshoot the AttributeError?

If it matters, I'm working on a Mac 10.9.5

UPDATE: following gene's guidance in the comments, I attempted to read my shapefile using pyshp (shapefile). shapefile appears to read the source file just fine and appears to recognize the 'parts' attribute. Here is an example of my work:

>>> import shapefile
>>> sf = shapefile.Reader("TaxParcels.shp")
>>> shapes = sf.shapes()
>>> len(shapes)
>>> for name in dir(shapes[45873]):
...     if not name.startswith('__'):
...             name
>>> shapes[876].shapeType
>>> shapes[876].parts
>>> fields = sf.fields
>>> len(fields)
>>> len(sf.records())

I don't have enough experience yet to know what the next step is in troubleshooting. I even tried stripping the "attributes" parameter from my script and I came up with the same error. Could the problem be with how Kartograph is handling the shapefile?

  • Why you don't use the Apple Python ? – gene Oct 13 '14 at 17:56
  • 1
    The error is _Shape instance has no attribute 'parts' and it comes from Pyshp and not kartograph. Try to open your shapefile with Pyshp (shapefile) – gene Oct 13 '14 at 18:50
  • @gene thank you for pointing me in the right direction. I am in the process of trying to open my shp file in pyshp (currently iterating shapes). I will try to reproduce the attributeerror and follow-up. My shp has 70073 shapes so it could take a while. and btw, I am using the native python on my mac. – nfs_jd Oct 14 '14 at 13:52
  • updated original post – nfs_jd Oct 14 '14 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.