Skip to main content

Posts

Showing posts from 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...

Mapping the population density of New Zealand with QGIS, SQLite and TileMill

There are over 4.4 million people living in New Zealand, but they’re not evenly distributed across the country. On my travels, I’ve been to some very remote areas like Doubtful Sound in Fjordland with a permanent population of one! Where do the New Zealanders live? Let’s create a population density map of New Zealand. Doubtful Sound According to Lonely Planet , 63% of New Zealanders live on the North Island, 20% on the South Island, 10% in Australia, 5% in the rest of the world, and 2% are travelling! The area of New Zealand is 268,021 km2 (Norway has 385,252 km2), which means there are about 16.5 New Zealanders per km2. Norwegians have a bit more space, we're only 15.5 persons per km2. Auckland I want to map the population density as a choropleth map , using darker colors for higher densities. But which units or geographical areas should I use? The regions (territorial authorities) I mapped in my last blog post are too big to show the population density of the c...

Mapping the regions of New Zealand with MapShaper and Leaflet

There are 16 regions of New Zealand , and during my trip I’ll be visiting 15 of them (I’m saving the Taranaki region for my next visit). This blog post shows how you can download and simplify region boundaries, and add them to a map as an interactive layer. The region is the top tier of local government in New Zealand. Eleven are governed by an elected regional council, while five are governed by territorial authorities (the second tier of local government) which also perform the functions of a regional council. The current regions came about in 1989, when they replaced more than 700 boards which had been formed in the preceding century. The geographic extents of the regions are largely based on drainage basins , following drainage divides such as the Southern Alps.  The dataset I’m using is from Statistics New Zealand , the national statistical office. Koordinates.com has made life easier by collecting geographic data from Statistics New Zealand on their portal. I’v...

Mapping New Zealand: Creating a road map

I’ve travelled around New Zealand by bus, car, boat, and by foot. In a previous blog post , I created a “Where I’ve Been Map” using markers for each of the places I’ve stayed. Let’s add some lines showing the route between the markers. I've destroyed my National Geographic map while travelling around the New Zealand. How can I add the roads travelled to my digital map? Travelling around New Zealand can be quite an experience. This is a well known sight. I’ll concentrate on the roads in this post, and deal with boat and foot tracks later. As I didn’t carry a GPS when travelling by bus or car, I had to find the road lines from a different source. I’m using road data from LINZ for my map, but I’m sure you can achieve the same with OpenStreetMap data. First, I created an empty shapefile in QGIS for my road data. Then I marked and copied the roads I’ve travelled from the LINZ shapefile, and pasted the road segments into my own shapefile. I also had to cut road lines ...

Mapping New Zealand: Clustering DOC Huts with Leaflet

In New Zealand, long distance walking or hiking for at least one overnight stay is known as tramping . There is a great network of over 950 huts throughout New Zealand operated by the Department of Conservation (DOC). I’ve just stayed in four of the huts while tramping the Abel Tasman Coast Track , and you need a lifetime to reach them all. It’s much quicker to map them. DOC huts in the Abel Tasman National Park . Awaroa Hut I was fortunate to visit the geospatial unit at the DOC office in Wellington. They have a lot of ineresting conservation projects going on, and it seemed to be a great place to work in New Zealand, especially when you can combine digital work with practical field work. You can download DOC's geospatial data for free on their data portal . Unfortunately, the datasets are not available as shapefiles, so it might require some wizardry to extract the data from KML. Luckily, the Koordinates guys have done this already, and you can download the shape...

Mapping New Zealand: Where are the hot and cold springs?

New Zealand has a large number of cold and hot springs , where water flows to the surface of the earth from underground. Where can you find these springs? This blog post will show you can visualise a spring point dataset on a Leaflet map.  You can find spring point dataset at LINZ Data Service , which contains 147 significant springs either by size or location. I downloaded the dataset as a shapefile, and converted it to GeoJSON using ogr2ogr : ogr2ogr -f "GeoJSON" -lco COORDINATE_PRECISION=4 nz-spring-points.json nz-spring-points-topo-150.shp  The resulting GeoJSON FeatureCollection can be assigned to a JavaScript variable: var springs = {"type":"FeatureCollection","features":[{... ... and visualised with Leaflet's GeoJSON layer and L.circleMarker : Here is the result: Fullscreen map Te WaikoropupÅ« Springs in Golden Bay, discharging 14,000 litres of water per second , - the largest freshwater springs in New...