In this guide we will be downloading shapefiles from a single source, manipulating these to match a same map projection and optimizing these for performance in TileMill. To demonstrate how to alter a shapefile to use only what we need from it, I’ll cover how to create a custom layer from an existing source in step 3. Downloading shapefiles across resources on the web will invariably be formatted differently. For consistency it’s a good idea to ensure they all conform to the single spatial reference system. For performance reasons, we’ll make sure this is the same as the final output SRS. To get started, let’s download the ESRI shapefiles provide here: a collection of Shapefiles from Toronto http://toronto.ca/open. Note for beginners: “ESRI shapefile” a popular format that is comprised of at least three separate files that must be kept together. Generally when using them with TileMill they are kept together in a zip archive. To manipulate them, we’re going to unzip them and once we have formatted the data for our purposes the files will be archived again and imported into TileMill. See the TileMill manual for more details. GDAL, an open source set of command line tools that let you quickly manipulate geospatial data. This will allow us to keep our shapefiles consistent by formatting them to the same spatial reference. Quantum GIS, an open source Geographic Information System. For our purposes this will let us quickly load in shapefiles to preview the ones we want to use and create a custom one for our use in a map. As a base layer, I’ll be using admin_0_countries.zip which is provided out of the box with TileMill. Its SRS is the same as TileMill’s output projection, Google Mercator (or ‘EPSG:900913’). By running a quick command we can see the SRS definitions of each shapefile we downloaded: ogrinfo Neighbourhoods.shp -al -so The arguments -al and -so are flags to display this information as fields with sort order The important line here is the Layer SRS WKT value, which is a well-known text definition of the SRS. The first value is a description: NAD_1927_UTM_Zone_17N, which is different from our base layer that has a value of Google_Maps_Global_Mercator. GDAL provides an extremely helpful command that will quickly convert this shape file into a new, specified srs. Here’s that command: ogr2ogr formatted_neighbourhoods.shp Neighbourhoods.shp -t_srs EPSG:900913 To expand on this command we first state our output filename followed by the input filename (the file we wish to manipulate). -t_srs is the reproject/transform on output and ESPG:900913 is the code for the SRS we wish to set. There’s one last step I want to perform before I archive each of my shapefiles and import into a TileMill project. I will create an index file for Mapnik to utilize. There’s more on its performance benefits here. To give a geographical context to Toronto and its surroundings I want to include the lake of Ontario. Tilemill provides us with a lakes of the world shapefile lakes.zip out of the box but its more than what we need. I’m going to load this file into Quantum GIS and extract just the polygon of ontario lake as a geojson file. The GeoJSON format is great for this purpose as the data file is small and creating a file like this is quick and easy. See also this detailed tutorial on GeoJSON. Import Lakes.shp into QGIS by selecting command-shift V. This key command will import vector layers. When the file has loaded into QGIS we should should see the polygons visually projected on the canvas. From the toolbar, press and hold the “Select Features” icon. Choose “Select Features by Polygon” to capture what I wish to use. With the mouse over the selection, press ctrl and select to highlight a selection. I have now set a selection on Ontario to capture its polygon. Alternatively, I could have saved this as an ESRI file, then ran ogrinfo and ogr2ogr. For simplicity sake let’s keep this as a .geojson file for now. An optional step but with our new shapefiles I’ll package these neatly into a new directory called toronto. At this point I am all set to begin designing in TileMill. Be sure to manually set the projection of your GeoJSON layer to 900913, as SRS autodetection is not yet functional for GeoJSON files. Happy Mapping! Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified: April 18, 2016 @ 10:01 am