Get Large Scale International Boundaries Directly in TileMill

Blog

Estimated
3 min read

The Large-Scale International Boundaries dataset that was released by the U.S. Department of State on Friday is now available directly from within TileMill via the MapBox Geodata library.

329f2208f60c  0 gyXiK ceFV9QsQL

This data has been processed and optimized for better rendering in TileMill, including re-projection to Web Mercator and a range of simplified versions to choose from for lower zoom levels.

The dataset is very detailed. Most areas have inaccuracies of less than one kilometer, and no lines are known to be more inaccurate than four kilometers. This is far more accurate than Natural Earth, which is meant for a 1:10 million scale.

329f2208f60c  0mp9LAujjJRBwzyvX

Natural Earth 1.4.0 in orange and LSIB in blue

Technical notes on the data processing

Re-projection was done using ogr2ogr, then the two shapefiles were imported to a single PostGIS table.

All of the borders are split into multiple line segments — over 9,000 in total. I’m sure there are good upstream data management reasons for the data to be like this, but for rendering maps in TileMill the lines don’t need to be split up that much. In fact, having so many segments has unwanted side effects, such as resetting a dash pattern in the middle of a line which causes inconsistent dash lengths.

I derived a version of the data that merged geometries wherever possible without losing any data:

`create table lsib.lsib_grouped as (
  select
    min(gid) as gid,
    country1,
    country2,
    min(rank) as rank,
    label,
    st_linemerge(st_union(the_geom)) as geometry
  from lsib.lsib
  group by country1, country2, label
)`

After a few minutes of processing, this reduced the number of geometries down to 408 and reduced the total number of points in the data by over 45% — all without losing any amount of detail in the boundaries. MultiLineStrings were merged into single LineStrings where possible (with ST_LineMerge), and we still have separate lines for each border between two countries with the various ranks and statuses correctly maintained.

329f2208f60c  0qvD8CJJWk17 Zu0M

Red Xs mark nodes that were unnecessary duplicates and could be merged. Green dots mark nodes that may be duplicates but are necessary to keep.

Because the lines are so accurate we wanted to also derive simplified versions for smaller scales. There are versions with simplified geometries for each zoom level from one through ten with appropriate simplification settings in each. Zoom levels 11 and higher should use the full resolution geometries. Zoom level one uses a ST_Simplify tolerance of 51,200. The tolerance halves for each subsequent zoom level down to 100 at zoom level 10.

Burundi at various levels of detail for decreasing scales.

Available immediately

If you have a recent version of TileMill installed, these files should already be available from the MapBox cloud browser in the Add Layer window. TileMill is available for free at TileMill.com, if you haven’t downloaded it yet and would like to use it to make custom online maps. There are also pre-rendered tiles available on TileStream Hosting that you can composite with your own layers or download for offline use.

What we're doing.

Latest