Pregunta

Recently I started using Kartograph. I am inexperienced in SVG, so the map creation is creating headaches for me. After initial trouble creating a world map that outlines country borders - similar to this - and a few other things(city regions and some decorating elements), my problem boils down to a undocumented - or at least I haven't found it in the docs - error. I guess it is related with my ignorance towards the kartograph.py framework.

The json file I provide Kartograph looks like that:

    {
    "proj": {
        "id": "lonlat",
        "lon0": 20,
        "lat0": 0
    },
    "layers": {
        "background": {
            "special": "sea",
            "charset": "latin-1",
            "simplify": false
        },
        "graticule": {
            "special": "graticule",
            "charset": "latin-1",
            "simplify": false,
            "latitudes": 1,
            "longitudes": 1,
            "styles":{
                "stroke-width": "0.3px"
            }
        },
        "world":{
            "src": "ne_50m_admin_0_countries.shp",
            "charset": "latin-1",
            "simplify": false
        },
        "lakes":{
            "src": "Lakes.shp",
            "charset": "latin-1",
            "simplify": false
        },
        "trees":{
            "src": "Trees.shp",
            "charset": "latin-1",
            "simplify": false
        },
        "depth":{
            "src": "DepthContours.shp",
            "charset": "latin-1",
            "simplify": false
        },
        "cities":{
            "src": "CityAreas.shp",
            "charset": "latin-1",
            "simplify": false
        }
   }

}

I know the output file will be huge and the generation will take ages, but it is just a test. I will experiment with the "simplify" option later. Much of the code in the file is based on this tutorial. Also, the empty simplify clause might not be necessary, but kartograph complained about the lack of the option, so I added it.

The command I use is this one:

kartograph world.json -o world.svg

It runs for some time(I guess, parsing all the input files etc.) before aborting. Now, the error I am facing is this one:

    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__()
  50: me.bounds_poly = me._init_bounds()  map.py, in _init_bounds()
  192: features = self._get_bounding_geometry()  map.py, in _get_bounding_geometry()
  257: charset=layer.options['charset']
get_features() got an unexpected keyword argument 'filter'

I tried looking at the file which throws the error(map.py), but I realized quickly that there's just too much interaction in the files for me to grasp things quickly.

I hope the data I provided is sufficient for someone more familiar with kartograph than me to track the error down.

UPDATE: The error is still valid. I tested it on both a MacBook Pro and an Asus Netbook now(Arch and Bodhi Linux, respectively).

Thanks in advance, Carson

¿Fue útil?

Solución 2

I also had problems with that error. But, after many trials to set up everything, I noticed that apparently it only appears in the command-line version of Kartograph, and not when using Kartograph as a Python module in a script. I.e., try to include the json dictionary into a Python script where you import kartograph, like in the example here below.

I also put an example of filtering, for the record, because it was another thing that failed to work when using the command-line version of Kartograph.

# file: makeMap.py
from kartograph import Kartograph
K = Kartograph()

def myfilter(record):
    return record['iso_a3'] in ["FRA","ITA","DEU"]


config = {
    "layers": {
        "mylayer": {
            "src": "ne_50m_admin_0_countries.shp",
            "filter": myfilter,
            "attributes": {"iso_a3":"iso_a3", "name":"name", "id":"iso_a3"}
        }
    }, 
}

K.generate(config, outfile='world.svg')

Then, run the script as a Python script:

python makeMap.py

Otros consejos

As far as I know, you can solve that problem by including a 'bounds' parameter. It is in deed very tricky, because according to the documentation (is it valid to call it 'documentation') this error should not appear, since the only required parameter is 'layers'. Also, how the bounds are defined depend apparently from the chosen projection. For your example I would use a simple polygon bounds.

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