Skip to main content

Posts

Showing posts from November, 2012

How to minify GeoJSON files?

You can't do web mapping these days without knowing your GeoJSON . It's the vector format of choice among popular mapping libraries like Leaflet , D3.js and Polymaps . Size matters on the web, especially if you want to distribute complex geometries, like the world's countries. The challenge is even bigger if you want to target mobile users - or support web browsers with poor vector handling (IE < 9). This blog post will show you how to minify your GeoJSON files before sending them over the wire. The first thing you should do is to generalize your vectors so they don't contain more detail than you need. In a previous blog post , I was able to remove 90% of the coordinates without loosing to much detail for map scale I wanted to use. This will of course have a great effect on the file size. Today, I'm going to use country borders from the Natural Earth dataset . These datasets are already generalized for different scales (1:10m, 1:50m, and 1:110 million), so ...

Mapping New Zealand - a summary

I've had a fantastic two months study trip to New Zealand. Unfortunately, I had to go back to Norway this week to fill up my bank account - just when the summer was arriving in New Zealand. I'm going to miss the beautiful country with its great people.   New Zealand is the perfect country to map, as an isolated country surrounded by a vast ocean, and because of all the free data available. I hope my Mapping New Zealand blog series has been useful for others as well: Getting free data in New Zealand Creating a Seafloor Map of New Zealand Creating a seafloor map using shaded relief Creating a custom map tiling scheme for New Zealand’s seafloor Dealing with the antimeridian in TileMill Editing and merging shapefiles with QGIS Creating a shaded relief map of New Zealand Doing magic with TileMill Exporting tiles from TileMill Creating a "Where I've Been" map with Leaflet and CartoDB How to control your Leaflet map with URL parameters Where are the ho...

New Leaflet plugin to handle multiple TileMill layers

My setup for the population density map of New Zealand made it easy to create new choropleth maps with New Zealand census data. This blog post explains how you can use Leaflet to switch between multiple interactive layers created with TileMill. I wanted to create a map of the social geography of New Zealand, using the Index of Deprivation from the Department of Public Health, University of Otago. I downloaded a Excel sheet containing data for the 2006 census area units, which I also used for my population density map. I simply added the data to the same SQLite database, and created the map using the same techniques described in two previous blog posts ( 1 , 2 ). The Index of Deprivation is constructed from nine Census 2006 variables, and provides a summary deprivation score from 1 to 10. A score of 1 is allocated to the least deprived 10 percent of areas, and 10 is allocated to the most deprived 10 percent of areas. You'll find more information about the index in the Atla...

Creating map labels with TileMill

It's one obvious thing missing from my maps of New Zealand: map labels . This blog post will show you how to create a transparant layer with map labels with TileMill , which can be added as an map overlay in Leaflet or other mapping libraries. To create map labels, you need a point dataset containg at least a position and the label text. As we'll see later, information about type of place, importance etc. will also be useful. For my New Zealand maps, I'm using a dataset from LINZ Data Service: NZ Geographic Names (Topo, 1:500k) I started by using QGIS to convert the shapefile into SQLite database (by right-clicking on the layer name in QGIS and select “Save as…”). This allows us run SQL queries against the data in TileMill. The dataset includes three attributes or columns, - name, size and a code describing the type of place: I'm opening the SQLite file in TileMill: I'm using this SQL query to load the data from the SQLite database:    SELECT * FRO...

Exploring the MapBox stack: MBTiles, TileJSON, UTFGrids and Wax

In my last blog post , we created a population density map of New Zealand using QGIS, SQLite and TileMill. Today, we’re going to publish this map to the web using various MapBox inventions. I'll also show you how to publish an interactive TileMill map on your own web server using some PHP and JavaScript wizardry.  I love MapBox . The team behind this platform has created a series of new specifications, allowing us to create fast, good looking and interactive maps. The downside is the limited support for other map projections than Web Mercator. TileMill allows you to add legends and tooltips to your maps. I’ve added a legend to my population density map with a HTML snippet describing the map and the color scale. The tooltip shows when the user hovers over or clicks on the map. It allows us to show dynamic content - additional data, images, charts - for each map feature. I want to show the name, total population, area and population density for each feature: The d...