Skip to content

Instantly share code, notes, and snippets.

@nikolaswise
Last active August 29, 2015 14:19
Show Gist options
  • Save nikolaswise/ba9e52edb534663bb9dc to your computer and use it in GitHub Desktop.
Save nikolaswise/ba9e52edb534663bb9dc to your computer and use it in GitHub Desktop.
Ten easy steps!

Concept

Lower Albina looks at using classical analog-era metaphors to address web cartography and creating of the 'map'. At it's root, this conceptual model requires 3 layers:

  1. Base Layer
  2. Study Layer
  3. Reference Layer

This is similar to the ideas behind basemap/layers/labels, but simplified. Each layer has it's own, very narrow, scope.

The base layer and the reference layer can both exist as single objects or tile layers in the web map to avoid issues of overwhelming the map with data, and simplify the amount of control needed over layering. One tile layer for the base, one tile layer for the Reference.

Base Layer

The base layer will underlay the rest of the map. It is related to the basemap, but has much less going on. The base layer only holds as much information as needed to ground the study layer (or each individual study layer) with the geography. For Lower Albina, the Base Layer only has two data sets:

  1. 5 Foot Contours, classified by elevation.
  2. County Taxlots

Reference Layer

The Reference Layer contains data that sits over the study layer. This layer provides precise context about geography that is further up the conceptual hierarchy than the data in the study layer. The reference layer for Lower Albina includes

  1. Bridges
  2. Light and Heavy Rail lines
  3. Roads
  4. Neighborhood information
  5. Water Bodies

Creating Base and Reference Layers

This is complicated. There are a lot of good stuff out there. To get at them all though, one has to do a lot of meandering to get around plenty of probs.

Good Stuff

  • Easy Reprojection of data
  • High quality demographic data available.
  • High Quality cartographic data rendering tools
  • Layer Compositing and Tile Generation

Probs

  • City of Portland data sets are huge, bigger than our study area.
  • Proprietary data formats from local government GIS departments.
  • ArcGIS Online has no support tile layers that contain multiple layers.
  • MapBox Studio has no tools for examining, classifying, and styling data across ramps.
  • AGO exports GeoJSON with x,y as meters from Null Island in WGS84 .
  • MBS can't handle WGS:84 as meters from Null Islands. Needs to be reprojected as lat/long in decimal degrees.
  • Neither AGO or MBS provide reprojection tools.
  • AGO doesn't support sub-pixel rendering
  • AGO raster tiles look a little rough.
  • MBS wont let go of tiles, either in vector or raster.

Step By Step

I dealt with the trubs so you don't have to. Looking at one layer of data, here's how we make high quality (raster for now) tiles and consume them in our Leaflet app. Repeat data layer steps as needed until your base or reference layer is done.

0. Find Your Data

This is important. Lower Albina uses the Portland Streets Centerlines data to create a layer that sits on reference layer. Download your data.

screenshots__0033_screen shot 2015-04-17 at 10 27 04 am

1. Upload that Data to Arcgis Online

This is gives us access to the ArcGIS's pretty excellent data manipulation tools and cartographic abilities. If you have an ArcGIS org running, and an account with your org, you can just use that. If you don't, this step has it's own gotchas, so we'll go through that step by step really quick.

a. Get free developer account at Arcgis for Developers This will give you access to AGO, along with some free credits every month you can use to run analysis tools and hit service endpoints in your app later on. Don't sign up for a Public Account with AGO - these things are useless and don't let you create or store any content, or provide any credits to use the tools, or any way to acquire credits. screenshots__0032_screen shot 2015-04-17 at 10 33 15 am

b.* Once you get confirmation of your new developer account, Sign in to ArcGIS Online. This is weird. Don't ask. screenshots__0031_screen shot 2015-04-17 at 10 33 18 am

c. Navigate to 'My Content', and 'Create' a new item 'From my Computer' Grab your data set - this means the entire .zip file in the case of shapefiles screenshots__0030_screen shot 2015-04-17 at 10 34 43 am

d. Done! AGO will create a Feature Layer of your data! screenshots__0029_screen shot 2015-04-17 at 10 46 08 am

2. Crop Data to Study Area

We don't need ALL the streets in Portland for our Reference Layer in Lower Albina. We need to crop down the data so we only need to deal with the bits that we're concerned this. This is a little complicated also.

a. Open > Add layer to new map to get the feature layer on the Map Viewer, where we can start working with it. If your data set is large, it won't draw completely. A modal might pop up telling you this - this is okay! Your data is in there, but AGO is just drawing the first 1000 features to try and avoid destroying your browser. Thanks AGO. screenshots__0028_screen shot 2015-04-17 at 10 47 53 am

b. Add > Add Map notes Layer to draw out your area of study. screenshots__0027_screen shot 2015-04-17 at 10 49 23 am screenshots__0026_screen shot 2015-04-17 at 10 50 40 am

c. Pop back to the details tab, and find the Secret Dropdown Menu of Ultimate Power on your data layer. screenshots__0025_screen shot 2015-04-17 at 10 51 33 am screenshots__0024_screen shot 2015-04-17 at 10 51 36 am

d. Select Perform Analysis. screenshots__0023_screen shot 2015-04-17 at 10 51 42 am

e. To crop the data to just our study area, we need to 'Find Locations' > 'Find Existing Locations'. Add an expression that has a geographic query with your map notes layer. screenshots__0022_screen shot 2015-04-17 at 10 52 04 am

f. Run the analysis with the current extent. This will keep your cost down. You can see how many credits this will burn with the 'show credits button.' My analysis is going to cost 4.643 out of my free 50 credits a month. This is about 46 cents in USD. Analysis will probably take a while. screenshots__0021_screen shot 2015-04-17 at 10 52 46 am screenshots__0020_screen shot 2015-04-17 at 10 53 06 am

3. Style your data

Turn off your source and map notes layer, and use the Secret Dropdown Menu of Ultimate Power on the basemap layer to turn the transparency all the way up. Now we have our layer, and can do some good stuff to it. screenshots__0019_screen shot 2015-04-17 at 11 03 54 am

Use the Secret Dropdown Menu of Ultimate Power to 'Change Style' on your layer, and go nuts in there. screenshots__0018_screen shot 2015-04-17 at 11 05 56 am

For these streets, I wont be pushing the limits of AGO's rendering tools. But I want to see what structure types there are, and set different widths of my lines. This shows each structure type as it's own color. Im going to set all my colors to white, and just change the widths. I'll do this in the next step, since AGO doesn't support sub-pixel rendering of line widths, which I will want to do. For now, Im going to pretend I want these colors so we can move on. screenshots__0017_screen shot 2015-04-17 at 11 07 55 am

4. Take a Screen Shot of AGO's Rendering Rules.

This is the end of the line for our use of AGO to work with the data. From this point on, we're just focusing on getting the stuff we want OUT of the ArcGIS system. We'll use the hard work that AGO did to examine, classify, create ramps for, and otherwise be really smart about our data set to re-create the renderer by hand in CartoCSS. We'll use this screenshot to get the field names, values, colors, and other good stuff we need to make this happen. screenshots__0015_screen shot 2015-04-17 at 11 10 05 am

A better example of the power that AGO's renderers give us is with the Contour data Lower ALbina uses in it's base layer. AGO gives us a histogram of the distribution of elevations in our study area, creates a classification of 10 natural breaks in the data, and assigned each class a step from our defined color ramp. In this step, we could use any of the (very good) default color ramps, and each class in the data would automatically get the correct color value. screenshots__0014_screen shot 2015-04-17 at 11 13 59 am

5. Get your Data Out of AGO

Using the Secret Dropdown Menu of Ultimate Power, view your layers item details page. Here we can convert our data to GeoJSON and download it.

a. 'Export' > Export File as GeoJSON. This will create a new item in our 'My Content' zone that's a GeoJSON file rather than a Feature Layer. This might take a while. AGO will forward you to this items details page. screenshots__0012_screen shot 2015-04-17 at 11 17 28 am

b. 'Open' > 'Download'. This will download your Geojson. Dont ask. screenshots__0011_screen shot 2015-04-17 at 11 19 05 am screenshots__0010_screen shot 2015-04-17 at 11 19 38 am

6. Convert from Meters From Null Island to Decimal Degree Coordinates

We're gonna use (Ogr2Ogr CLI)[http://www.gdal.org/ogr2ogr.html] for this.

$ogr2ogr streetsLatLong.geojson -t_srs 'WGS84' -f 'GeoJSON' Streets-Lower-Albina.geojson;

screenshots__0009_screen shot 2015-04-17 at 11 20 38 am

7. Get the Data into MapBox Studio

Sign up for a Free Account with Mapbox. Get your hands on MapBox Studio and start a new Source Project from Custom Vector Tiles. screenshots__0008_screen shot 2015-04-17 at 12 31 42 pm

Add a new layer, and select the GeoJSON that Ogr2Ogr gave us. Save that, and upload it to MapBox. screenshots__0007_screen shot 2015-04-17 at 12 32 02 pm screenshots__0006_screen shot 2015-04-17 at 12 33 15 pm

Once the data uploads, go find it in MapBox. Copy the source ID, and head back to mapbox studio. screenshots__0005_screen shot 2015-04-17 at 12 33 48 pm

8. Style Your Data in MapBox Studio

Create a new Style Project in MapBox Studio. As your data source, plug your uploaded Source ID into the little input at the bottom and hit 'Create'. screenshots__0004_screen shot 2015-04-17 at 12 34 45 pm screenshots__0003_screen shot 2015-04-17 at 12 35 17 pm

Now you can write CartoCSS in MapBox Studio to style the data. Grab your screenshot of AGO's render rules, and go to town implementing AGO Styles in CartoCSS. For the streets data set, I want to style some features in a way that the underlying data doesn't exactly reflect. MBS lets us go in and inspect feature by feature, and add a CartoCSS rule that addresses consistency at this level, which can't be done in AGO. screenshots__0002_screen shot 2015-04-17 at 12 36 01 pm screenshots__0001_screen shot 2015-04-17 at 12 38 11 pm screenshots__0000_screen shot 2015-04-17 at 12 50 17 pm

9. Upload the Style Project as MapBox Tiles

Once your style is uploaded, you can head over to MapBox and preview the tile. Make sure the tile are public in the API, and grab the preview url. For my Base Layer, it looks like this: screenshots__0038_screen shot 2015-04-17 at 1 10 11 pm

https://api.tiles.mapbox.com/v4/nikolaswise.65959181/page.html?access_token=pk.eyJ1Ijoibmlrb2xhc3dpc2UiLCJhIjoieVJJcE1QUSJ9.f8co32wYW_YTeh_KM6PGLA#15/45.5356/-122.6707

10. Consume in Leaflet

Consume your tiles in your Leaflet app, and add em to your map!

L.tileLayer('https://{s}.tiles.mapbox.com/v4/nikolaswise.65959181/{z}/{x}/{y}.png?access_token=pk.eyJ1Ijoibmlrb2xhc3dpc2UiLCJhIjoieVJJcE1QUSJ9.f8co32wYW_YTeh_KM6PGLA#15').addTo(map);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment