migurski / Dymo

Map label placer with simulated annealing.
148 stars 17 forks source link

Dymo

Dymo is a placement script for map labels, isolated from the purpose-built code in GeoIQ’s Acetate. Dymo resolves positions for densely-packed point labels, and results in layouts make your maps look like they’ve been touched by a cartographer.

Dymo uses Simulated Annealing to derive an acceptable global label set, described in Steven Wouderberg’s October 2007 presentation at Utrecht University. See an animation of the process over time in these two videos of U.S. and European place names:

QUICK START

Demo area: Run make geojson to anneal labels for San Francisco and Israel sample areas from zooms 4 to 10. This will automatically build the data files, too (eg: make data). Should run in less than an hour.

World: Annealing the entire world will take several days to several weeks and will require lots of RAM and many processor cores. Modify the Makefile to remove the spatial filter as below:

# COMPOSITE FILTER (fast!)
# SPATIAL_FILTER=  --filter-bounding-box $(FILTER_SANFRANCISCO) --filter-bounding-box $(FILTER_JERUSALEM)
# NO FILTER (slow! If no filter is desired, uncomment line below, comment out line above.)
SPATIAL_FILTER=

You can change the fonts and population steps in the Makefile, too.

DETAILS

dymo-label.py is a script that converts lists of cities with included font information to GeoJSON point and label files suitable for use in geographic rendering.

Mamata Akella at the National Park Service has written a detailed tutorial on Dymo and Tile Mill, to “avoid label overlaps and improve the overall legibility of park names dramatically.” The tutorial shows how to prepare data for Dymo using ArcGIS Desktop.

Label Usage

Place U.S. city labels at zoom 6 for two minutes:

python dymo-label.py -z 6 --minutes 2 --labels-file labels.json --places-file points.json data/US-z6.csv.gz

Place U.S. city labels at zoom 5 over a 10000-iteration 10.0 - 0.01 temperature range:

python dymo-label.py -z 5 --steps 10000 --max-temp 10 --min-temp 0.01 -l labels.json -p points.json data/US-z5.csv

Both examples will result in a pair of GeoJSON files, labels.json and points.json. The first will contain rectangular label areas, the second will contain center points of places successfully positioned by Dymo. Because labels will collide in different ways depending on map scale, labels must be placed separately for each zoom level:

U.S. Labels

For larger datasets, it’s almost always faster to run dymo-label.py with the --minutes option instead of --min-temp/--max-temp, because Dymo will automatically partition labels based on mutual overlaps and perform many small annealing processes.

Data Included

Look in data/ for a list of zoom-by-zoom city locations, organized by continent and selected by Justin O’Bierne. Data is distributed separately from code, see downloads for a link.

To prepare your own city lists or modify fonts and font sizes in input lists, Use dymo-prepare-places.py to apply population-specific font choices to an in-bound list.

Prepare-Places Usage

python dymo-prepare-places.py --font 0 fonts/Arial.ttf 10 --font 1000000 fonts/Arial.ttf 12 --zoom 5 data/North-America-all.txt.gz data/North-America-z5.txt

Sample Output

These sample images were created during the development of Acetate, and show the results of town placement.

Central Japan:

Central Japan

Western Europe:

Western Europe

Northen Appalachians:

Northen Appalachians

Advanced Options

Dymo Prepare Places

Dymo Label

Advanced Prepare Places Usage

Advanced Label Usage

Dependencies

Some of the advanced options, such as custom map projections, will require the following libraries:

For projection-specific inputs, see this projections transform list.

Tips

Who

Copyright 2010-2012 Michal Migurski, Nathaniel V. Kelso, and GeoIQ, offered under the BSD license. Uses Richard J. Wagner’s Python annealing library.

We’re not affiliated with Dymo Corporation.