kartograph / kartograph.py Goto Github PK
View Code? Open in Web Editor NEWUNMAINTAINED! Renders beautiful SVG maps in Python.
Home Page: http://kartograph.org/docs/kartograph.py
UNMAINTAINED! Renders beautiful SVG maps in Python.
Home Page: http://kartograph.org/docs/kartograph.py
The current implemented simplification algorithm is based on filtering points by distance. It would be great to have some smarter algorithms on board.
The idea is to add support for all projections included in PROJ.4 by adding a generic wrapper projection:
proj:
id: proj4
opts: "+proj=moll"
Hi everybody,
I would like import "kartograph" in my python library but it's doesn't work..
Can u help me ?
(I have a mac).
iMac:~ aktayen$ sudo python /Users/aktayen/Desktop/kartograph/setup.py install
running install
running bdist_egg
running egg_info
writing requirements to kartograph.py.egg-info/requires.txt
writing kartograph.py.egg-info/PKG-INFO
writing namespace_packages to kartograph.py.egg-info/namespace_packages.txt
writing top-level names to kartograph.py.egg-info/top_level.txt
writing dependency_links to kartograph.py.egg-info/dependency_links.txt
writing entry points to kartograph.py.egg-info/entry_points.txt
warning: manifest_maker: standard file 'setup.py' not found
reading manifest file 'kartograph.py.egg-info/SOURCES.txt'
writing manifest file 'kartograph.py.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.8-intel/egg
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
creating build/bdist.macosx-10.8-intel/egg
creating build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/PKG-INFO -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/SOURCES.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/dependency_links.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/entry_points.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/namespace_packages.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/not-zip-safe -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/requires.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
copying kartograph.py.egg-info/top_level.txt -> build/bdist.macosx-10.8-intel/egg/EGG-INFO
creating 'dist/kartograph.py-0.6.1-py2.7.egg' and adding 'build/bdist.macosx-10.8-intel/egg' to it
removing 'build/bdist.macosx-10.8-intel/egg' (and everything under it)
Processing kartograph.py-0.6.1-py2.7.egg
removing '/Library/Python/2.7/site-packages/kartograph.py-0.6.1-py2.7.egg' (and everything under it)
creating /Library/Python/2.7/site-packages/kartograph.py-0.6.1-py2.7.egg
Extracting kartograph.py-0.6.1-py2.7.egg to /Library/Python/2.7/site-packages
kartograph.py 0.6.1 is already the active version in easy-install.pth
Installing kartograph script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/kartograph.py-0.6.1-py2.7.egg
Processing dependencies for kartograph.py==0.6.1
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 3.0alpha2
Downloading http://pypi.python.org/packages/source/l/lxml/lxml-3.0alpha2.tar.gz
Processing lxml-3.0alpha2.tar.gz
Running lxml-3.0alpha2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-yrLkn_/lxml-3.0alpha2/egg-dist-tmp-bUJz0y
Building lxml version 3.0.alpha2.
Building without Cython.
Using build configuration of libxslt 1.1.26
warning: no files found matching '*.txt' under directory 'src/lxml/tests'
unable to execute clang: No such file or directory
error: Setup script exited with error: command 'clang' failed with exit status 1
(Sorry for my english.. i'm french)
Ty..
Hi,
First off I want to commend you on such awesome work! Kartograph is great.
Just a quick point, the API reference needs updating. For example on the first page it says you can run it from command line this way : kartograph config.json -o map.svg
Though it is missing an 'svg' between the kartograph and config.json.
It is also very confusing and if possible test items such as shape files coud be included, it would be great.
Thanks.
Using an RTree
every modified line segment can be checked for intersections with existing line segments. If an intersection is introduced, the point shouldn't be removed.
see implementation in Bloch.py
For full geekyness
http://www.progonos.com/furuti/MapProj/Normal/ProjPoly/projPoly2.html#WPS
As seen in QGis.
API proposal:
layers:
- id: streets
styles:
categorized:
column: highway
attrs:
motorway:
stroke-weight: 2px
primary:
stroke-weight: 1px
Hello,
I can't get kartograph working on a Mac OS X 10.7.4. It compiles fine and it runs but I consistently get the same error. I'm not a Python expert to make much sense from the stack dump. The shape file is from the Natural Earth website. Here is a transcript of my terminal shell:
mac:kartograph jakub$ kartograph svg config.json
-> full extend
Traceback (most recent call last):
File "/usr/local/bin/kartograph", line 8, in <module>
load_entry_point('kartograph.py==0.2.2', 'console_scripts', 'kartograph')()
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/cli.py", line 103, in main
args.func(args)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/cli.py", line 65, in svg
K.generate(cfg, args.output)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/kartograph.py", line 59, in generate
svg.preview()
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/svg.py", line 37, in preview
call(["firefox", "tmp.svg"])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 486, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
And here is the JSON config file I'm using. I tried different ones with absolute paths to the shape files. Still no luck.
{
"proj": {
"id": "ortho",
"lon0": -81,
"lat0": 47.903225806451616
},
"layers": [
{
"id": "countries",
"src": "shp/ne_110m_admin_0_countries.shp"
}
],
"export": {
"width": 800,
"height": "auto"
},
"bounds": {
"padding": 0.02
}
}
Many thanks,
Jakub
in kartograph/proj/cylindrical.py
on line 114, in init self.phi0 = rad(lat0 * -1)
NameError: global name 'rad' is not defined
I seem to get this error when using the latlon and mercator projections but robinson works just fine.
What dependencies if any does kartograph.py require? What is required in config.js?
Currently, I'm hung on:
/usr/bin/python: can't find 'main.py' in 'kartograph'
Thanks for sharing your work and I'm looking forward to the new functionality in kartograph.py especially the ability to add attributes!
Latitude lines projected behind the globe appear in front as horizontal lines.
hi, i like to know about this trace generated using kartograph.py for generating svg maps
used command :
python c:\Kartograph\kartograph\kartograph.py SHP_TEST.json -o SHP_TEST.svg
Traceback (most recent call last):
File "c:\Kartograph\kartograph\kartograph.py", line 2, in
from options import parse_options
File "c:\Kartograph\kartograph\options.py", line 7, in
import os.path, proj, errors
File "c:\Kartograph\kartograph\proj__init__.py", line 50, in
from azimuthal import *
File "c:\Kartograph\kartograph\proj\azimuthal__init__.py", line 19, in
from azimuthal import Azimuthal
File "c:\Kartograph\kartograph\proj\azimuthal\azimuthal.py", line 20, in
from kartograph.proj.base import Proj
File "c:\Kartograph\kartograph\kartograph.py", line 2, in
from options import parse_options
ImportError: cannot import name parse_options
regards
On Mac OS X 10.7.4 I get this error Kartograph-Error: unknown shape type (1) in shapefile
when I try to load populated places by Natural Earth. I also tried to create a simple shape file with one point just to see if it loads but I get the same error. Maps with polygons or lines render fine.
It would be nice to be able to render markers and labels on the map.
Was able to install Kartograph in Windows without any errors. Running kartograph on the command line however gives the following error:
Traceback (most recent call last):
File "C:\Python27\Scripts\kartograph-script.py", line 8, in
load_entry_point('kartograph.py==0.5.2', 'console_scripts', 'kartograph')()
File "C:\Python27\lib\site-packages\pkg_resources.py", line 318, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "C:\Python27\lib\site-packages\pkg_resources.py", line 2221, in load_entry_point
return ep.load()
File "C:\Python27\lib\site-packages\pkg_resources.py", line 1954, in load
entry = import(self.module_name, globals(),globals(), ['name'])
File "C:\Python27\lib\site-packages\kartograph.py-0.5.2-py2.7.egg\kartograph__init__.py", line 2, in
from kartograph import Kartograph
File "C:\Python27\lib\site-packages\kartograph.py-0.5.2-py2.7.egg\kartograph\kartograph.py", line 2, in
from options import parse_options
File "C:\Python27\lib\site-packages\kartograph.py-0.5.2-py2.7.egg\kartograph\options.py", line 8, in
import proj
File "C:\Python27\lib\site-packages\kartograph.py-0.5.2-py2.7.egg\kartograph\proj__init__.py", line 21, in
from base import Proj
File "C:\Python27\lib\site-packages\kartograph.py-0.5.2-py2.7.egg\kartograph\proj\base.py", line 21, in
from shapely.geometry import Polygon, LineString, Point, MultiPolygon, MultiLineString, MultiPoint
File "C:\Python27\lib\site-packages\shapely\geometry__init__.py", line 4, in
from geo import box, shape, asShape, mapping
File "C:\Python27\lib\site-packages\shapely\geometry\geo.py", line 5, in
from point import Point, asPoint
File "C:\Python27\lib\site-packages\shapely\geometry\point.py", line 7, in
from shapely.coords import required
File "C:\Python27\lib\site-packages\shapely\coords.py", line 8, in
from shapely.geos import lgeos
File "C:\Python27\lib\site-packages\shapely\geos.py", line 71, in
lgeos = CDLL("geos.dll")
File "C:\Python27\lib\ctypes__init_.py", line 353, in init
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
I ran into the following issue while generating a svg map. The used shapefile is the Admin 1 โ States, Provinces loaded into QGIS to select all the german states and then saved as.
kartograph svg map.yaml -o germany.svg
-> full extend
Traceback (most recent call last):
File "/usr/local/bin/kartograph", line 8, in <module>
load_entry_point('kartograph.py==0.2.0', 'console_scripts', 'kartograph')()
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.0-py2.7.egg/kartograph/cli.py", line 95, in main
args.func(args)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.0-py2.7.egg/kartograph/cli.py", line 64, in svg
K.generate(cfg, args.output)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.0-py2.7.egg/kartograph/kartograph.py", line 30, in generate
view = self.get_view(opts, bbox)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.0-py2.7.egg/kartograph/kartograph.py", line 201, in get_view
return View(bbox, w, h - 1)
TypeError: unsupported operand type(s) for -: 'str' and 'int'
{
"proj": {
"id": "ortho",
},
"layers": [
{
"id": "countries",
"src": "germany-real.shp",
"attributes": {
"NAME_1": "Bundesland",
}
}
],
"export": {
"width": "auto",
"height": "auto"
},
"bounds": {
"padding": 0.02
}
}
I hope someone can help. Thanks!
Really needs to be on board..
must not be missing in Kartograph
Instead of the rather complicated getopt
interface Kartograph should use argparse
It makes much more sense to put the styling information into a separate stylesheet instead of embedding them into the map configuration. This has the following advantages:
The Kartograph command line interface would get a new parameter -s or --style which can be used to add a stylesheet to a map.
> kartograph map.yaml -s styles.css
Internally, Kartograph uses tinycss to parse the stylesheet and to detect which declaration to add to which map feature. Kartograph will not put the style declarations into style
attributes since this cannot be read by some graphic software (e.g. Illustrator). However, Kartograph will try to minify the output size by putting common styles to the layer group instead of assigning them to every feature.
When I try to render a (pseudo?)cylindrical projection with 0.2.2 (e.g. winkel3), I get following error:
Traceback (most recent call last):
File "/usr/local/bin/kartograph", line 8, in <module>
load_entry_point('kartograph.py==0.2.2', 'console_scripts', 'kartograph')()
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/cli.py", line 103, in main
args.func(args)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/cli.py", line 65, in svg
K.generate(cfg, args.output)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/kartograph.py", line 26, in generate
proj = self.get_projection(opts)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/kartograph.py", line 94, in get_projection
proj = projC(**p_opts)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/proj/pseudocylindrical.py", line 366, in __init__
Aitoff.__init__(self, lon0=lon0, flip=flip)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/proj/pseudocylindrical.py", line 341, in __init__
PseudoCylindrical.__init__(self, lon0=lon0, flip=flip)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/proj/pseudocylindrical.py", line 26, in __init__
Cylindrical.__init__(self, lon0=lon0, flip=flip)
File "/Library/Python/2.7/site-packages/kartograph.py-0.2.2-py2.7.egg/kartograph/proj/cylindrical.py", line 32, in __init__
from Polygon import MultiPolygon as Poly
ImportError: cannot import name MultiPolygon
This seems to have been introduced with this commit: 84d80fa
To some degree, Kartograph could allow the import of KML and GeoJSON. Both formats are slightly more complex than shapefiles, since they can store hierarchical structures instead of just a plain list of features and can have arbitrary meta data for each feature. However, there might be a way to allow import.
Regarding the hierarchical structure one can
Regarding the meta data we might simply assume that every feature has the same attributes and throw errors if not.
I assume that is the way QGis is handling KML import as well.
yeah, heart-shaped..
path attributes should be lowercase and non-letters should be replaced with dashes
Todo: simplification, etc
In the current version of Kartograph, the rendering of a globe (e.g. using orthographic projection) needs to be fixed.
Hi,
I have just finished the installation of Kartographer (it was pretty dificult, maybe I have do something wrong, it could explain the following problem), and when I try to create a first test map, the command line tell me "pkg_resources.distributionnotfound: polygon".
I never use Python before, so I don't really know if it is a bug or an error I have made, I hope I don't do a wrong manipulation and I hope it's the good place to say that...
Regard, Tom
I had to install Kartograph using the "manual" instructions, as the version of polygon included in the setup.py does not compile on either of my Macs (running 10.7.3 with gcc 4.2). (The latest version on the Polygon github installs properly from its setup.py). Once installed, I tried to run the test script, and hit the following error:
$ kartograph svg united-states.yaml -o states.svg
Proj(laea, lon0=-96.5, lat0=37.5)
simplifying layer_0
layer_0
Traceback (most recent call last):
File "/usr/local/bin/kartograph", line 8, in <module>
load_entry_point('kartograph.py==0.1.3', 'console_scripts', 'kartograph')()
File "/Library/Python/2.7/site-packages/kartograph.py-0.1.3-py2.7.egg/kartograph/cli.py", line 57, in main
K.generate(cfg, output)
File "/Library/Python/2.7/site-packages/kartograph.py-0.1.3-py2.7.egg/kartograph/kartograph.py", line 58, in generate
svg.preview()
File "/Library/Python/2.7/site-packages/kartograph.py-0.1.3-py2.7.egg/kartograph/svg.py", line 37, in preview
call(["firefox", "tmp.svg"])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 486, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
The contents of united-states.yaml are:
layers:
- src: shp/united-states.shp
bounds:
mode: bbox
data: [-120,25,-73,50]
The shapefiles are those downloaded from http://data.kartograph.org/united-states.zip.
Since this involves a call to Firefox, I tried upgrading to the latest version of Firefox (11), but it does not appear to've helped.
please disregard
The polygon clipping library that's currently used is based on GPC which has a license that only allows non-commercial use. Would be great to have this dependency replaced by a free alternative. Namely, we could wrap Angus Johnson's Clipper library as a Python module and use it instead of Polygon
.
RaphaelJS 2.1.0 now comes with utility functions for point in polygon tests and computing polygon intersections.
This will allow to install kartograph using
pip install kartograph
In order to include more simplification algorithms (#6) it is needed to reduce the general complexity of the simplification problem. Currently the algorithms operate on polygons, but it is a lot simpler to make them operate on line segments. Therefor all polygons should be split into a set of unique lines segments. After simplification the line segments are merged back to polygons.
Hi,
After a clean install (from the git master) on a fresh Ubuntu 12.04 (in a virtual box VM), I'm encountering some problems with creating a SVG made of several layers coming from the same shape file.
I'm really starting to use kartograph.py (and any GIS software for that matter), so I could totally be wrong, but it looks like the second time, the filter is applied to the result of the first data filtering, hence a warning by kartograph that my subsequent layers are empty.
Here's my JSON config :
{
"proj": {
"id":"mercator"
},
"layers": {
"Alsace": {
"src": "geodata/ne_10m_admin_1_states_provinces_shp.shp",
"attributes": ["ISO","Region","ProvNumber"],
"filter": {
"and": [["ISO","=","FRA"],["ENGTYPE_1","=","Region"],["ProvNumber","=",12]]
}
},
"Aquitaine": {
"src": "geodata/ne_10m_admin_1_states_provinces_shp.shp",
"attributes": ["ISO","Region","ProvNumber"],
"filter": {
"and": [["ISO","=","FRA"],["ENGTYPE_1","=","Region"],["ProvNumber","=",7]]
}
},
"Auvergne": {
"src": "geodata/ne_10m_admin_1_states_provinces_shp.shp",
"attributes": ["ISO","Region","ProvNumber"],
"filter": {
"and": [["ISO","=","FRA"],["ENGTYPE_1","=","Region"],["ProvNumber","=",18]]
}
},
"Basse-Normandie": {
"src": "geodata/ne_10m_admin_1_states_provinces_shp.shp",
"attributes": ["ISO","Region","ProvNumber"],
"filter": {
"and": [["ISO","=","FRA"],["ENGTYPE_1","=","Region"],["ProvNumber","=",21]]
}
}
}
}
And here's the command line output :
xxx@ubuntu64:~/kartograph-test$ kartograph --format svg --output regions.svg regions.json
ignoring empty layer Aquitaine
ignoring empty layer Auvergne
ignoring empty layer Basse-Normandie
execution time: 0.770 secs
The resulting SVG only contains the first layer ("Alsace").
If I remove that first layer from the config, I'll get the (first now) "Aquitaine" layer in the SVG, but not the others :
xxx@ubuntu64:~/kartograph-test$ kartograph --format svg --output regions.svg regions.json
ignoring empty layer Auvergne
ignoring empty layer Basse-Normandie
execution time: 0.660 secs
I tried to create individual symlinks to every "ne_10m_admin_1_states_provinces_shp.*" file (one per layer), and pointing every layer to its "own" .shp file, but to no avail :
@ubuntu64:~/kartograph-test$ kartograph --format svg --output regions.svg regions.json
ignoring empty layer Aquitaine
ignoring empty layer Auvergne
ignoring empty layer Basse-Normandie
execution time: 1.622 secs
Regards,
R.
For convenience reasons I will soon add the following command:
kartograph inspect myshapefile.shp
Output:
The shapefile contains 12345 records and contains the following attributes:
OBJECTID, VertexCou, ISO, NAME_0, NAME_1, VARNAME_1, NL_NAME_1, HASC_1, TYPE_1,
ENGTYPE_1, VALIDFR_1, VALIDTO_1, REMARKS_1, Region, RegionVar, ProvNumber,
NEV_Countr, FIRST_FIPS, FIRST_HASC, FIPS_1, gadm_level, Region_Cod, Region_C_1
Hi, I don't know the best way to do this, but I think the Ubuntu how-to needs a bit of a tweak in the sample configuration file.
It won't work for me unless I make layers an array:
The wiki currently says:
{ "layers": { "src": "..." } }
whereas it only works for me if:
{ "layers": [ {"src": "..."} ] }
I thought I would pass it on!
svgfig seems to be a bit over-featured for what Kartograph actually needs. A more simple XML package should work as well and would simplify the installation procedure (svgfig has no pypi package yet).
Additionally to JSON, Kartograph could easily accept YAML configurations as well, which are easier to write for some..
xfrange in the graticule source steps too coarsely when you go very close in satellite - I was going up-close to a city and had to reduce the step to see any curve in the lines. Maybe it should be set to (maxlon-minlon)/720 or something?
Currently setup.py install doesn't work on some systems (especially not on windows).
for some maps it would be awesome to have multiple projections per map. example use case is a map of the United States with Alaska and Hawaii in separate views.
SVG
<metadata>
<views>
<view id="v0"><proj />...</view>
<view id="v1"><proj />...</view>
</views>
</metadata>
<g id="usa" data-view="v0">...</g>
<g id="alaska" data-view="v1">...</g>
JSON-Config
Use multiple json files per map.
kartograph usa.json -o usa.svg
kartograph alaska.json -o usa.svg
Another option would be to replace the first level dictionary with an array of dictionaries.
To keep things simple, Kartograph should only support SVG output.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.