1

I am trying to include a US map at the state detail on top of this maps: http://crimeinmexico.org/

I am using Kartograph for the small map. I have installed kartograph in Mac OS X and I am able to generate the map of the world as shown in the kartograph tutorial.

I have downloaded the ne_10m_admin_1_states_provinces from naturalearthdata. http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-admin-1-states-provinces/

When using this json configuration (mex.json):

    {
"layers":  {
    "mylayer": { 
        "src": "ne_10m_admin_1_states_provinces.shp",
        "filter": { "iso_a3": "MEX" }
        }
    }
}

and running this command in bash: kartograph mex.json -o mex.svg

I get this error:

cli.py, in render_map()
  71: K.generate(cfg, args.output, preview=args.preview, format=format, stylesheet=css)  kartograph.py, in generate()
  46: _map = Map(opts, self.layerCache, format=format)  map.py, in __init__()
  48: me.proj = me._init_projection()  map.py, in _init_projection()
  88: map_center = self.__get_map_center()  map.py, in __get_map_center()
  140: features = self._get_bounding_geometry()  map.py, in _get_bounding_geometry()
  257: charset=layer.options['charset']  layersource/shplayer.py, in get_features()
  96: if filter is None or filter(drec):  map.py, in <lambda>()
  252: filter = lambda rec: layerFilter(rec) and boundsFilter(rec)  map.py, in <lambda>()
  239: layerFilter = lambda rec: filter_record(layer.options['filter'], rec)  filter.py, in filter_record()
  25: res = res and filter_record([key, '=', filt[key]], record)  filter.py, in filter_record()
  27: res = filter_single(filt, record)  filter.py, in filter_single()
  35: prop = record[key]
neto@Ernestos-MacBook-Pro:~/Documents/thesis/datos/naturalearthdata/ne_10m_admin_1_states_provinces$ kartograph mex.json -o mex.svg  cli.py, in render_map()
  71: K.generate(cfg, args.output, preview=args.preview, format=format, stylesheet=css)  kartograph.py, in generate()
  46: _map = Map(opts, self.layerCache, format=format)  map.py, in __init__()
  48: me.proj = me._init_projection()  map.py, in _init_projection()
  88: map_center = self.__get_map_center()  map.py, in __get_map_center()
  140: features = self._get_bounding_geometry()  map.py, in _get_bounding_geometry()
  257: charset=layer.options['charset']  layersource/shplayer.py, in get_features()
  96: if filter is None or filter(drec):  map.py, in <lambda>()
  252: filter = lambda rec: layerFilter(rec) and boundsFilter(rec)  map.py, in <lambda>()
  239: layerFilter = lambda rec: filter_record(layer.options['filter'], rec)  filter.py, in filter_record()
  25: res = res and filter_record([key, '=', filt[key]], record)  filter.py, in filter_record()
  27: res = filter_single(filt, record)  filter.py, in filter_single()
  35: prop = record[key]
u'iso_a3'

I tried using the Python module instead of the command line as suggested here: https://stackoverflow.com/questions/21937077/kartograph-map-creation-fails/22793960#22793960

I still get errors:

Traceback (most recent call last):
  File "makeMap.py", line 18, in <module>
    K.generate(config, outfile='paises.svg')
  File "/Library/Python/2.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/Python/2.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/Python/2.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/Python/2.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/Python/2.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/Python/2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/layersource/shplayer.py", line 96, in get_features
    if filter is None or filter(drec):
  File "/Library/Python/2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/map.py", line 252, in <lambda>
    filter = lambda rec: layerFilter(rec) and boundsFilter(rec)
  File "/Library/Python/2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/map.py", line 239, in <lambda>
    layerFilter = lambda rec: filter_record(layer.options['filter'], rec)
  File "/Library/Python/2.7/site-packages/kartograph.py-0.6.8-py2.7.egg/kartograph/filter.py", line 29, in filter_record
    res = filt(record)
  File "makeMap.py", line 6, in myfilter
    return record['iso_a3'] in ["USA", "MEX"]
KeyError: 'iso_a3'

I have tried changing iso_a3 for iso, ADM0_A3 and ADM1_A3 and I get the same error.

Does anybody know what am I doing wrong or can anyone point me in the right direction?

I even tried concatenating a MEX.svg and an USA.svg file but they are rendered overlapping each other.

2

I don't know how you got the column name but downloading from your link

Natural Earth Download image

Then opening in QGIS and clicking on a Mexico state, I never see an iso_a3 column but I do see adm0_a3 or gu_a3 or sov_a3 all with the same value MEX

You should better use this config file so you get both USA and MEXICO (tested and it works)

{    
"layers":  {    
    "mylayer": {    
        "src": "ne_10m_admin_1_states_provinces.shp",    
            "filter": { "adm0_a3": ["MEX", "USA"] }    
        }    
    }    
}

The result with Greenland or Hawaii Isles can be annoying. You can delete them with your vectorial drawing software or you can filter them with Kartograph.py using not combined with nested expressions. See in the docs the detailed filter part.

For attributes info, see this GIF

QGis attributes infos

0
-2

I cannot answer in Kartograph but you can create SVGs in QGIS and QGIS runs on MAC.

QGIS Mac Link.

SVG in QGIS Link.

If you check this board you will notice an earlier GIS SE question when they failed to convert shapes to SVG in Kartograph.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.