kartograph / kartograph.py

UNMAINTAINED! Renders beautiful SVG maps in Python.
http://kartograph.org/docs/kartograph.py
1k stars 195 forks source link

Is there anyway to use custom map data (non OpenStreetMaps) from POSTGIS? #96

Open stodge opened 10 years ago

stodge commented 10 years ago

It looks like Kartograph assumes a certain POSTGIS table structure:

kartograph config.json -o map.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__()
  61: layer.get_features()  maplayer.py, in get_features()
  81: charset=layer.options['charset']  layersource/postgislayer.py, in get_features()
  64: cur.execute('SELECT "%s" FROM %s WHERE %s' % ('", "'.join(fields), self.table, query))
column "way" does not exist
LINE 1: ...polyline WHERE (layer_id = 19) AND ST_Intersects( way, ST_Se...

I assume that Kartograph therefore assumes you are using map data from OpenStreetMap in POSTGIS? Is there anyway to use custom map data from POSTGIS? Thanks

gka commented 10 years ago

Oh, that's right, I only used this feature with OSM data. To support custom PostGIS we would need to specify which column contains the geo data? Or should we check the column type and use the first? What do you think?

stodge commented 10 years ago

I suppose the column could be specified in the json. Maybe:

{
    "layers": [
    {
        "id": "anotherlayer",
        "src": "postgis:dbname=dbname user=username password=password host=localhost",
        "table": "gis_polyline",
        "column": "the_geom",
        "query": "layer_id = 19"
    }
    ]
}

I assume the query option just specifies a WHERE clause?

gka commented 10 years ago

yes, or rather a part of the WERE clause if you're using the bbox filter:

https://github.com/kartograph/kartograph.py/blob/master/kartograph/layersource/postgislayer.py#L49-L53

gka commented 10 years ago

Btw, I just discovered that I already implemented automatic detection of geo column but I just forgot to use it in the bbox query.. Will fix it.