class: center middle white bigger background-image: url(images/bus.jpg) # Cartography crash course Andy Woodruff and Mike Foster OpenVis Conf 2016 Workshop [axismaps.io/crash-course](http://axismaps.io/crash-course/) --- class: middle ## Hello **Andy Woodruff** Development lead and partner at Axis Maps, board of directors of the North American Cartographic Information Society (NACIS), mapper of Boston things, and general promoter of cartography [@awoodruff](http://twitter.com/awoodruff) | [andywoodruff.com](http://andywoodruff.com) **Mike Foster**: GIS and Data Visualization Specialist, Instructor at MIT Department of Urban Studies and Planning. FOSS4G Boston 2017 Planning Committee Member, and member of North American Cartographic Information Society (NACIS) [@mjfoster83](http://twitter.com/mjfoster83) | [mjfoster.net](http://www.mjfoster.net/) We are also two of the three organizers for [Maptime Boston](http://maptimeboston.github.io)! --- class: middle ## Overview This is a cartographic crash course. Mastery of mapping takes a lot of learning—and a lot more than a few hours! Today's goal is to provide a hands-on introduction to some common mapping concepts, data, and open-source technologies, and to provide resources for further learning. Many of these slides contain information that we can't spend much time on today. We're going to introduce some topics only briefly, leaving the slides and resources list as future reference. --- class: bigger, middle ## At a glance 1. Core cartography concepts 2. Geographic data 4. Static (print) map workflows 4. Interactive (web) map workflows --- class: center, middle white background-image: url(images/heartmaps.jpg) # What is a map? Sounds like a silly question, but it's important to understand the **what** and **why** of maps. --- class: bigger ## Textbook definition A map is a *representation* of a place. It is a symbolic interpretation of place and highlights the relationships between elements in space, either perceived or actual. It reflects choices and biases of the mapmaker. It does not and cannot represent _everything_ in the place. Things must be omitted, simplified, etc. for the map to make sense. --- class: bigger ## Types of maps **Reference maps** emphasize the **location** of spatial phenomena, e.g. topographic maps or road maps. **Thematic maps** emphasize the **spatial pattern** of geographic attributes, e.g. population density or income. --- background-image: url(images/reference.png) class: center, middle, white # Reference --- class: middle, center # Common types of thematic maps --- background-image: url(images/choropleth.png) class: center, middle, white # Choropleth --- A **choropleth map** is a map in which **areas** are shaded by **color** to represent values. Choropleth maps are perhaps the most common and familiar type of thematic map, frequently seen for demographic or political data. .float-right[] - Good for data (ideally _abrupt_) aggregated to areal units such as states. - Colors might be classed into discrete bins of data value ranges (more on that soon!) or unclassed and continuous. - Rule #1: choropleth maps should not be used with projections that badly distort area. - Rule #2: data values should be normalized, not simple counts. For example, _population per square mile_ is appropriate, while just _population_ is not. More guidelines for choropleth maps: http://www.axismaps.com/guide/choropleth/ --- background-image: url(images/prop_symbol.jpg) class: center, middle, white # Proportional Symbols --- On a **proportional symbol map**, symbols (such a circles) are scaled in proportion to the data they represent. Symbols might represent point data, but it is also common for proportional symbols to be used for area features. .float-right[] - These can be a good way around limitations of choropleth maps: they do not require an equal-area projection, and they do not require normalized data. - Instead of sizes being directly proportional to value, sometimes symbols are **range-graded** (or **graduated**) in which case data values are binned into several discrete symbol sizes. - Symbols should be correctly scaled by _area_, not radius. For example, if a circle is to be twice as big as another circle, its radius should be √2 larger than the other circle's, not twice as large. (Sometimes an additional perceptual scaling factor is applied to compensate for human weakness in estimating sizes.) - Choose symbol size and map size carefully, or else proportional symbols can easily overwhelm a map. More guidelines on proportional symbols: http://www.axismaps.com/guide/proportional_symbols/ --- class: center, middle, white background-image: url(images/boston_dots_vote.jpg) # Dot --- **Dot maps** use points to represent counts of a geographic phenomenon. Dot Density maps rely on visual scatter to show spatial pattern. - **One to One Relationship** In dot maps with a one to one relationship, **one dot on the map represents one instance of a geographic phenomenon**. One to one dot maps are similar to standard reference maps in that they represent correct geographic location. Care must be taken to ensure this. Methods for determining the exact spatial location include **geocoding** (extracting a latitude from a latitude and longitude point) and **reverse geocoding**, (getting an address for a latitude and longitude point). - **One to Many Relationship** In one to many relationships, **each dot on the map represents a number of phenomena**. For example, one dot is equal to 100 persons. This is called a dot density map. These maps are different in that the dots do not represent actual spatial location, but rather represent aggregated data and are randomly placed within an enumeration unit. Some methods for placement include random, even dispersement, and unit centroid. Data is often aggregated for one or many reasons, including resolution of the dataset, privacy of the phenomena, or the number of measurements. More guidelines on dot maps: http://www.axismaps.com/guide/dot_density/ --- class: center, middle, white background-image: url(images/contour.jpg) # Contours --- **Contour** or **isarithmic** maps interpolate values between points. Contour maps are most recognized as useful maps for representation of elevation or depth, but they can also be used to represent more thematic phenomena, such as temperature, weather, or social phenomena through a heat map, measuring data such as crime instances or social media checkins. In contour maps, **isolines are linear paths along which data values of a specific variable are considered to be equal**. For example, a contour line representing ten feet would presume that at any point on that line, the elevation is ten feet. Contour maps are typically used to represent continuous data, or discrete data that is perceived as continuous. Often data when measured at discrete locations but perceived as continuous can be made into a surface through interpolation methods. Contours are usually drawn at regular intervals (i.e. 10, 20, 30, etc.) or through a binning process similar to the creation of a choropleth map. More guidelines on isarithmic maps: https://en.wikipedia.org/wiki/Contour_line --- class: center background-image: url(images/other_map_types.jpg) ## Other types of maps --- class: center middle white background-image: url(images/mapdesign.jpg) # Map design --- ## Elements of map design **Design** in cartography can be thought of as the set of [human decisions](https://somethingaboutmaps.wordpress.com/2015/05/19/design-is-human/) behind the map—not only the _look_ of the map, but also choices about data, interaction, and more. We'll give an overview of some of the important considerations in map design. First, a few overarching things to think about initially: - **Medium.** Many design decisions depend on how the map will be displayed, usually meaning either on paper or on a digital device. (And in the digital realm, either on desktop screens or small mobile devices.) Sometimes a map needs to work for several different media, which can mean several sets of designs. - **Audience and purpose**. _What_ you intend to accomplish and for _whom_ are huge drivers of map design. For example, if you're mapping for an expert audience, the map can probably be more complex than if it's meant for the general public. - **Map-worthiness.** Just because data *can* be mapped doesn't mean it *should* be mapped! It's always important to think about whether geography is important to your story. If not, [consider other ways to visualize it](http://www.ericson.net/content/2011/10/when-maps-shouldnt-be-maps/), or simply provide a table. --- ## Map interaction #### Static Map A static map represents data at a snapshot in time. Historically, maps are static. Static maps are generally print maps, but could also be digital images found on your computer or online. #### Interactive Map Interactive maps are maps that allow for user interaction, data exploration, and animation. Interactive maps are usually web-based, on a computer, phone, or table. Interactive maps can represent static data, or can load data at intervals or on demand. Considerations in design include legibility, usability, and things such as screen size and what items the user can interact with. Interactive maps can be **exploratory** (encouraging the user to explore datasets and geographies) or **prescriptive** (leading users through a story about the data and geography). What you use depends on your audience, data, and intended purpose of your map. --- class: center middle  Cartography Cubed - Alan MacEachren, "How Maps Work" http://www.amazon.com/How-Maps-Work-Representation-Visualization/dp/157230040X --- ## Hierarchy *What are the different elements around the map, and what are their relative importance?* In all maps, some elements stand out, and some fall to the back. Properly utilizing both **intellectual** and **visual** hierarchy in your map composition will help emphasize your message and make the map easier to read. Where your eye goes first when you look at the map is the element that has the highest level in the visual hierarchy. .float-right[] **The Squint Test** - Squint at your map and see what pops out. Choose a visual hierarchy for your that properly represents the intellectual hierarchy. Big items are bigger, important items are darker. More guidelines on map hierarchy: https://www.e-education.psu.edu/geog486/node/1858 --- ## Visual variables .float-right[] .float-right[.caption[[image source](http://go.owu.edu/~jbkrygie/krygier_html/geog_353/geog_353_lo/geog_353_lo08.html)]] "The differences in map elements as perceived by the human eye" ([wiki.gis.com](http://wiki.gis.com/wiki/index.php/Visual_Variables)). No matter what the type of map, these are the fundamental ways in which visual symbols can be distinguished. [Jacques Bertin](https://en.wikipedia.org/wiki/Jacques_Bertin) proposed an original set in _Semiology of Graphics_ (1967): - Position - Size - Shape - Value (lightness) - Color (hue) - Orientation - Texture The list has since been further expanded by other researchers. --- ## Color Color is one of the more challenging design elements to perfect. It takes experience and a designer's eye to produce pleasing and effective color schemes, but there are also some guidlines to follow. - Bear in mind certain cartographic conventions, such as blue for water and green for natural areas. - Avoid red-green color schemes, as a significant population is colorblind and won't perceive these well. - Keep an eye on how your color choices affect **figure-ground**, the appearance of things being in the foreground or background. - .float-right[] For choropleth maps, use color ramps appropriate to the data. Is it **sequential** (ordered from low to high, e.g. population density), **diverging** (values above or below some break point, e.g. population change), or **qualitative** (having no natural order, e.g. race/ethnicity)? More on color: http://www.axismaps.com/guide/color_schemes/ http://colorbrewer.org (click the "i" icons in each section) --- ## Data classification Most choropleth maps (and some other types) divide data into a handful of bins (ideally 3–7). There are several [common classification schemes](http://wiki.gis.com/wiki/index.php/Classification) for dividing up data different ways—and they have a great impact on the map. The same data can result in radically different maps, depending on the classification scheme. Also, **normalize your data**. Densities and ratios are more meaningful in finding trends than absolute numbers.  .caption[[John Nelson, _Telling the Truth_](http://uxblog.idvsolutions.com/2011/10/telling-truth.html)] --- class: center middle  .citation[[xkcd](https://xkcd.com/1138/)] --- ## Scale and Generalization Cartography is all about abstraction. It is not possible to show every detail, especially at small scale ("small scale" = zoomed out, "large scale" = zoomed in). Thus a map requires [generalization](http://www.gitta.info/Generalisati/en/html/index.html). Common generalization tasks include: - Selection: choosing which objects to include on the map - Simplification: reduce the number of vertices in an object - Smoothing: reduce sharp angles to smoother curves - Aggregation: group points into areas - Amalgamation: group areas into larger areas - Collapse: reduce a detailed object to a point symbol - Merge: grouping of line features - Refinement: select only portins of an object to display - Exaggeration: amplify a part of an object (for clarity) - Enhancement: add detail that visually elevates an object - Displacement: separate objects (for clarity) --- ## Projections and Coordinate Systems The surface of the earth is curved, maps are flat. A map projection is the mathematical transformation of the Earth to a flat surface. Models of the earth called **ellipsoids** and **datums** are used as spherical surrogates for the actual surface of the earth. A **Map Projection** is the tranformation from a **3D ellipsoid** to a **2D surface**. **Coordinate systems** are measurement grids that locate specific points and apply measurements to the earth. This is the science of [Geodesy](https://en.wikipedia.org/wiki/Geodesy). *All information should be in file metadata.* - Maps distort. Projections can be used to retain properties of **shape, distance, size, or direction**. One or more of these can be maintained, but not all. - When given **latitude and longitude**, it will most commonly use the [WGS1984](https://en.wikipedia.org/wiki/World_Geodetic_System) datum. To calculate values such as area or distance, you need to project this data. - Projections that preserve relative size are good for choropleth mapping. - [UTM (Universal Transverse Mercator)](https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system) is a global standard for minimizing distortion locally. Coordinates are in **meters**, not latitude and longitude. [Pick a zone.](http://www.dmap.co.uk/utmworld.htm) More guidelines on projections and coordinate systems: http://mjfoster83.github.io/projections/index.html#/ http://www.axismaps.com/guide/projections/ --- class: center middle  --- ## Text Text on your map is important, and can serve several different functions. Type can convey information through words, but since type is part of the visualization, characteristics of type can communicate meaning. A user can vary size, font, boldness, italics, serifs, and more. Type on maps is found not only in labels, but also supplemental information, such as legends and sources, and in prose. Prose exists as blurbs or write ups that establish information not evident in the visual display of the map. In general, **let the graphic speak where it can**... but this might not always be possible. When it comes to text, **BE CONSISTENT**. A good rule of thumb is to **choose two fonts, one serif font, and one sans-serif font**. Use fonts that have many different weights, such as **bold, italic, regular, or light** and encode information in these. Utilize principles of your **visual and intellectual hierarchy** with text. Make important things bold and big, and lesser important things smaller and lighter (or even, off the map!). More guidelines on map text: https://www.e-education.psu.edu/geog486/node/1947 Additional guidelines on using prose on maps - Marty Elmer http://maphugger.com/post/75374571098/practical-cartography-maps-and-prose --- ## Recap As with most things, getting good at map design requires learning and experience, and lots of time staring at maps, and of course, lots of time making maps! Look to the literature and to good examples. #### Elements of Map Design - Medium - Static and Interactive - Hierarchy - Visual and Intellectual - Visual Variables - Color - Data Classification - Data Normalization - Scale and Generalization - Projections and Coordinate Systems - Text --- ## Recommended reading Seriously, buy an actual textbook! It's worth having if you work with maps. Online resources, as great as they are, don't (yet) rival the depth of real books. "Making Maps: A Visual Guide to Map Design for GIS", Krygier and Wood http://www.amazon.com/Making-Maps-Second-Edition-Visual/dp/1609181662 "Thematic Cartography and Geovisualization, 3rd Edition", Slocum, McMaster, Kessler, and Howard http://www.amazon.com/Thematic-Cartography-Geovisualization-Terry-Slocum/dp/0132298341 "Elements of Cartography", Robinson and Morrison http://www.amazon.com/Elements-Cartography-Arthur-H-Robinson/dp/0471555797 "How Maps Work", MacEachren http://www.amazon.com/How-Maps-Work-Representation-Visualization/dp/157230040X Some Axis Maps Documents: http://www.axismaps.com/guide/ Or checkout the Resources sheet we will give you. --- class: middle, center white background-image: url(images/data.jpg) # Geographic data --- ## Geographic phenomena **Discrete phenomena** occur at distinct locations, e.g. indivudal people. **Continuous phenomena** occur all over a region, e.g. elevation. **Abrupt phenomena** change suddenly, e.g. electoral votes per state. **Continuous phenomena** change gradually, e.g. temperature  .caption[Alan MacEachren] --- ## Levels of measurement Data produced from geographic phenomena may be **qualitative** (no numerical values) or **quantitative** (numerical values), or more specifically, one of four **levels of measurement**. **Nominal:** categorical and non-ordered, e.g. official languages **Ordinal:** ordered, but non-numerical, e.g. "Low", "Medium", and "High" **Interval:** ordered, with understood numerical differences, but an arbitrary zero point, e.g. Farhenheit or Celsius temperature scales **Ratio:** full-on numerical, with a non-arbitrary zero, e.g. population. (Ratio is the most common numerical data type.) --- ## Basics of geographic data Most geographic data is one of two types: - **Vector:** shapes (or _features_) defined by geometry. Points, lines, and areas. - **Raster:** image data, defined by pixels, for example an elevation surface  And comprises two components - **Location:** e.g., latitude and longitude, and/or vector geometry - **Attributes:** information or numerical data about the feature --- class: center, middle white background-image: url(images/dataformats.jpg) # Data formats --- Geographic data come in a lot of flavors. Some common formats include: **Vector** *data in points, lines, and polygons* - Tabular, e.g. a CSV table of points - Shapefile: the longtime standard, actually a collection of files. Clunky but still prevalent. - GeoJSON: common for web maps. Easily consumed by javascript code. - KML/KMZ: the google earth format - GeoPDF: georeference PDF - Databases: e.g., PostGIS **Raster** *data held in pixels* - GeoTIFF - DEM (Digital Elevation Model) More on spatial data formats: https://4326.us/maptime-data-formats/#/ --- ## Let’s look at some data files .bigger[[Shapefile](data/shp-example.zip)]  --- ## Let’s look at some data files .bigger[[GeoJSON](data/geojson-example.json)]  --- ## Let’s look at some data files .bigger[[CSV](data/csv-example.txt)]  --- ## Geocoding With point data, if you're lucky it will have latitude and longitude information. Sometimes you only have addresses, though. Turning those addresses into latitude/longitude points requires a process called [geocoding](https://en.wikipedia.org/wiki/Geocoding). Geocoding, honestly, is _hard_ because addresses are not simple. People have put a ton of work into good geocoding technology, but it still may not be right 100% of the time. There are a variety of [services and tools for geocoding](http://tolomaps.com/resources/#geocoding)—some of which can cost money. --- class: center middle white background-image: url(images/download.png) # Data sources --- ## OpenStreetMap [OpenStreetMap](http://openstreetmap.org) is an open, free, editable map of the world. It is the standard street map data source in the open source community, and increasingly is the basis for maps in many major apps and products.  OSM data extracts (e.g., [Mapzen's metro extracts](https://mapzen.com/data/metro-extracts/)) are a handy source for things like streets in your map. Be aware: use of OSM data requires [proper attribution](http://www.openstreetmap.org/copyright)! More on OpenStreetMap: http://maptimeboston.github.io/osm-101/#0 --- ## Natural Earth Public domain cartographic reference data at several scales, created by expert cartographers. http://www.naturalearthdata.com/  Quick downloads of GeoJSON: http://geojson.xyz/ --- ## Government data [US Census TIGER/Line files](https://www.census.gov/cgi-bin/geo/shapefiles/index.php) are a good source of Census geographies (tracts, etc.) as well as other reference shapes. Some have basic demographic data attached, while others may require table joins to get data. Many states, cities, or other local entities have GIS data repositories. In Massachusetts, we have [MassGIS](http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/datalayers/layerlist.html), city GIS data (for example [Cambridge's](https://www.cambridgema.gov/GIS/gisdata)), and general open data sites like those of [Boston](https://data.cityofboston.gov/), [Cambridge](https://data.cambridgema.gov/), and [Somerville](https://data.somervillema.gov/). --- class: bigger ## There's always Google! Often, this is how you find what you're looking for: "_[thing]_ shapefile" "_[thing]_ geojson" "_[thing]_ gis files" --- ## Working with data Once you have data, you might need to do some things to it before turning it into a map. Some typical tasks and tools: - **Clean it up** using a tool like [OpenRefine](https://github.com/OpenRefine/OpenRefine/wiki/Documentation-For-Users). - Use **spreadheet** software (Excel, Google Sheets, LibreOffice, and so forth) to make calculations, format values, filter and categorize, etc. - **Simplify** geometry using [Mapshaper](http://mapshaper.org/). This is almost always a good idea unless your data was already designed for the map scale you will use. - Perform **spatial operations** using command-line tools (e.g. [GDAL](http://www.gdal.org/) or [Mapshaper's command line interface]((https://github.com/mbloch/mapshaper)) or GIS software (which we'll demo shortly). - Use a **text editor** to manipulate a variety of things. Find-and-replace and [regular expressions](https://en.wikipedia.org/wiki/Regular_expression) can be your best friends. - **Convert** between different formats using tools such as [Mapshaper](https://github.com/mbloch/mapshaper), [geojson.io](http://geojson.io/), [ogr2ogr](http://www.gdal.org/ogr2ogr.html), or GIS. --- class: center middle white background-image: url(images/ratmap.jpg) # Let’s make a map! --- ## A basic map workflow 1. Acquire data 2. Clean and edit data as necessary 3. Import data to GIS 4. Further geodata processing if needed 5. Symbolize data and lay out map including other elements 6. Export map to image, or vector format for further design work --- ## GIS _Geographic Information System_ “A system designed to capture, store, manipulate, analyze, manage, and present all types of spatial or geographical data.” ([Wikipedia](https://en.wikipedia.org/wiki/Geographic_information_system)) A lot of tools, sets of tools, or operations can fall under this umbrella; however “GIS” often refers to a single piece of software. [ArcGIS](http://desktop.arcgis.com/en/) by Esri has long reigned supreme as *the* GIS software. It’s powerful, and everywhere… but also expensive. [QGIS](http://www.qgis.org/en/site/) is the open-source GIS software of choice. It’s growing more awesome every day and has an excellent community of users. **This is what we’ll use to make a map today.** We only have time for a brief look at a few of the features of QGIS. Today's purpose is to expose you to some of the core capabilities of QGIS, and to show you what GIS can do in general. Don't worry if you can't follow everything! A list of more in-depth resources and tutorials will follow. --- ## Data for our map We're going to make a #ratmap! It will use data from the following places: [Mapzen OSM metro extract of Boston](https://mapzen.com/data/metro-extracts/) [Boston neighborhoods](https://data.cityofboston.gov/City-Services/Boston-Neighborhood-Shapefiles/af56-j7tb) [Boston open 311 requests](https://data.cityofboston.gov/City-Services/311-Service-Requests/awu8-dc52) Or, you can download all data for the map [here](data/qgis-example.zip). --- There's a lot going on in QGIS. But most of the time, for basic mapping, you'll likely only use a handful of core tools.  --- ## Importing data Typical geographic data formats can be opened directly in QGIS, through the "Add Layer" menu or toolbar, or simply by dragging and dropping. QGIS [supports lots of data formats!](https://docs.qgis.org/2.2/en/docs/user_manual/working_with_vector/supported_data.html)  Another common way to get data into a map is with a **table join**. In this case, you have a table of data belonging to geographic entities (e.g., states) but not the geographic shapes themselves. QGIS can join the table to a separate geodata file, as long as they both have some key field that matches. [Learn more about table joins here.](http://www.qgistutorials.com/en/docs/performing_table_joins.html) --- ## Visualizing Data The first task with data in GIS is often simply to see what it looks like, and make sure the file works and contains what was expected. Once you open a data file, it will automatically be drawn with some default styles.  --- ## Layers Most maps in GIS are organized in terms of **layers**. Each layer represents a geographic data set (e.g., country outlines or city points), or some kind of annotation. Generally, they are shown in a list stacked in the same order as they are drawn on the map (i.e., bottom layer on the bottom, top layer on the top).  --- ## Projection Projection is important! There are two types of project properties (_Project_ menu, _Project Properties..._) you're likely to deal with: **general properties** such as background color and units of measurements, and **CRS**. CRS stands for _coordinate reference system_, and for practical purposes this is your map projection. Choose the projection to best fit your map extent! (need link)  --- ## Attributes Attributes are what drive a thematic map, and lot of time working in GIS is spent dealing with attributes in one way or another, be it [viewing the attribute table, selecting features based on attribute values](http://www.qgistutorials.com/en/docs/working_with_attributes.html), [identifying features on the map](http://docs.qgis.org/2.0/en/docs/user_manual/introduction/general_tools.html#identify), [calculating new attributes](https://docs.qgis.org/2.2/en/docs/user_manual/working_with_vector/field_calculator.html), or symbolizing features by attribute (up next).  --- ## Symbolizing data Data symbolization may be the biggest task of mapping in GIS. This is where you set styles, not only for representing attribute values but also for creating the look of your map. Styles can be applied layer-wide, or they can be set according to attribute values, with variable colors, widths, sizes, etc.  Styling vector layers is a big topic! [Start here](http://www.qgistutorials.com/en/docs/basic_vector_styling.html) for learning it in QGIS. --- ## Editing data QGIS offers powerful [editing tools](https://docs.qgis.org/2.2/en/docs/user_manual/working_with_vector/editing_geometry_attributes.html) for changing attributes, editing geometry, and adding or removing features. One common editing task is called _digitizing_: tracing new vector features from an exisitng source such as an image.  --- ## Geoprocessing Many advanced calculations and geometry operations are possible with GIS. For example, you might want to merge polygons together, or convert polygons to lines. In QGIS, look under the Vector menu, the [processing toolbox](http://docs.qgis.org/2.0/en/docs/user_manual/processing/toolbox.html), or in [plugins](http://www.qgistutorials.com/en/docs/using_plugins.html).  --- ## Map layout and export Typically the final step in a cartographer's use of GIS is to lay out the map on a page along with elements such as titles, and export to an image or other format. In QGIS this is done with the [Print Composer](http://docs.qgis.org/2.0/en/docs/user_manual/print_composer/print_composer.html).  Very nice maps can be made with QGIS alone, but most professional cartographers will refine further in a vector graphics program, such as Illustrator or the open-source alternative Inkscape. --- ## Recap Things you might want to do with software like QGIS: - Import and view data - View attributes - Edit data (attributes and geometry) - Advanced geoprocessing and analysis - Make a map! There's much more to learn about QGIS (and GIS in general)! - http://giscommons.org/ - http://docs.qgis.org/2.8/en/docs/training_manual/index.html - http://www.qgistutorials.com/en/docs/making_a_map.html - http://duspviz.mit.edu/intro-to-qgis/#0 (or maptime, whichever is more up to date) --- ## More options for static maps - [ArcGIS](http://desktop.arcgis.com/en/) - [R](http://spatialanalysis.co.uk/r/) - [MAPublisher](http://www.avenza.com/mapublisher) and [Adobe Illustrator](http://www.adobe.com/products/illustrator.html) - [Mapbox](https://www.mapbox.com/help/create-a-static-map/) --- class: middle center white background-image: url(images/web.jpg) # Web maps --- class: bigger ## What is a web map? A _digital map_ is on a computer, but may not be accessible by internet, and is relatively static if it is. A _web map_ depends on the internet. It is usually interactive and not always self-contained. A web map might be a reference map like Google Maps, a data-driven map of something like election results, or anything in between. An introduction to web maps: https://github.com/maptimeBoston/web-maps-101 --- ## When should a map be interactive? The web makes it tempting to go bananas and throw everything into a map, with all kinds of interaction and data and everything. Avoid the temptation. Design carefully for your purpose, and think about what is gained by adding interaction. The map still needs to look good and have a good user experience. Especially bear this in mind if your users are only going to spend 15 seconds looking at the thing. The reader doesn't always _want_ to interact with a map. [Why We Are Doing Fewer Interactives](https://github.com/archietse/malofiej-2016/blob/master/tse-malofiej-2016-slides.pdf) by Archie Tse, New York Times [Making maps, part 1: Less interactivity](http://blog.apps.chicagotribune.com/2011/03/08/making-maps-1/) by Brian Boyer --- ## Web map design considerations Web maps are like static maps in many ways. All the same design considerations we discussed earlier are still relevant on the web. In addition to visual design, we need to think about the design of **interaction** and **user experience**. - Is the user interface understandable? - Is interaction comfortable and apparent to users? - Does the map move? Animation can be confusing if not carefully designed. - Does the map function smoothly? Don't push technology too far if it will crash browsers and melt phones. - Is the map readable and usable on various media, from mobile devices to large desktop screens? There is much more to say about web map design! We will provide further resources soon. --- ## Web map technology Web mapping is a quickly evolving arena, technically. Your options will seem more diverse than the static GIS world, and often come with a steeper learning curve. But several companies do focus on products and services aimed at lowering the barrier of entry. Those comapnies are happy to guide you through easy web mapping with their products, and we will introduce some of them later. First, though, let's take a look at how you can **build your own web map**! It's a good way to become familiar with some of the fundamental technology involved. The essence of web maps is only a few things: 1. Data 2. Code 3. A basemap: a reference map on top of which data might be displayed --- ## Slippy map A map that can be panned and zoomed (like Google Maps) is sometimes called a “slippy map” in the lingo. Most slippy maps are: 1. In the Mercator projection 2. Tiled (either as images or vector data)  Learn more: [Web Maps 101](http://maptimeboston.github.io/web-maps-101/#0), [Anatomy of a Web Map](http://maptime.io/anatomy-of-a-web-map/) --- ## Let’s make a web map! [Leaflet](http://leafletjs.com) is the most popular open-source javascript library. It is lightweight and easy to use, supporting basic map interactions, tiled map layers, and vector data layers (such as geojson data). It’s a good place to start a journey of custom web mapping. This will be a simplified demo that provides a taste of a web mapping workflow. As always, it takes a lot of learning and work to really master web maps. Learning to code is of course a big part of that, if you’re not already a coder. Fortunately, there are tons of resources and an amazing open mapping community to assist you in learning this stuff. Many more resource links will be provided shortly, but here's one from our Maptime chapter: http://maptimeboston.github.io/leaflet-intro/ --- ## Beginning at the end Click to take a look at this [example of a simple web map](http://bl.ocks.org/awoodruff/2488ee1fdf0cf063904e). Notice how little code there is! It doesn't take much to get started with web maps, so don't be intimidated. [](http://bl.ocks.org/awoodruff/2488ee1fdf0cf063904e) --- class: bigger ## Anatomy of *this* web map: - Our data - A basemap - html/js code --- ## Basic setup The skeleton of a Leaflet web map is an HTML page, some extenral scripts, and some code of our own. ```html
A Leaflet map!
``` --- ## We need a basemap! Unlike a static map, where the extent of your base data is limited, on a web map it usually covers many scales and often vast areas. This means a LOT of data and design decisions. (For example see how you get more detail as you zoom into Google, and the designs change.) Therefore a making a basemap on your own can be a huge task. We’ll point out some resources and services for doing just that, but very often you’ll be using a pre-made (whether by you or by someone else) basemap. There are [many, many basemaps](https://leaflet-extras.github.io/leaflet-providers/preview/) out there that you can use. The best bet is to go with one that's free to use and derived from OpenStreetMap data. You can't legally just grab basemaps from places like Google Maps!  --- ## Loading a basemap in Leaflet Tiled basemaps have a URL template for each tile's zoom level and x/y coordinate. It typically looks like this: `http://tiles.mapc.org/basemap/{z}/{x}/{y}.png` Using that, setting up a simple slippy map is a breeze! Just initialize the map and plug in that tile URL. In this example we're using a basemap from [MAPC](http://www.mapc.org/). ```javascript // initialize the map var map = L.map('map').setView([42.35, -71.08], 13); // load a tile layer L.tileLayer('http://tiles.mapc.org/basemap/{z}/{x}/{y}.png', { attribution: 'Tiles by
MAPC
, Data by
MassGIS
', maxZoom: 17, minZoom: 9 }).addTo(map); ``` Example: [basic Leaflet map with tiled basemap](http://bl.ocks.org/awoodruff/e9739a6719e0604eef58) --- ## Data Cool, now we want our own data on top of the basemap. We'll use the #ratmap data as GeoJSON. Leaflet can load and display GeoJSON data very easily. Remember the steps it took to get here? It's not an uncommon workflow: 1. Download CSV data from the Boston data site 2. Load CSV in QGIS 3. Filter data to include only Rodent Activity 4. Save filtered data as GeoJSON --- ## Loading data to leaflet We use jQuery to help load the GeoJSON file, and then only one line of code to [display it](http://bl.ocks.org/awoodruff/1dc36a658a2e24e01b12)! ```html
A Leaflet map!
``` --- ## Customizing & getting more advanced We can use custom icons... ```javascript // load GeoJSON from an external file $.getJSON("rodents.geojson",function(data){ var ratIcon = L.icon({ iconUrl: 'http://andywoodruff.com/maptime-leaflet/rat.png', iconSize: [60,50] }); L.geoJson(data,{ pointToLayer: function(feature,latlng){ return L.marker(latlng,{icon: ratIcon}); } }).addTo(map); }); ``` And add popups... ```javascript pointToLayer: function(feature,latlng){ var marker = L.marker(latlng,{icon: ratIcon}); marker.bindPopup(feature.properties.Location + '
' + feature.properties.OPEN_DT); return marker; } ``` --- ## And beyond… With more coding, you can do awesome things! Perhaps a [choropleth map](http://bl.ocks.org/awoodruff/3ce5d735126a56dfff94) or [clusters](http://bl.ocks.org/awoodruff/5de3553bb1f1b0c5f90d). The beauty of something like Leaflet is that it provides a basic framework upon which you can build amazing maps with your own data, creatvity, and coding cleverness. The key to mastering web maps is not necessarily learning how to use specific libraries—that's often the easy part—but being comfortable with code and geographic data in general. We have only provided a glimpse of the technical side of Leaflet and web maps today. If you're not already comfortable with web development, resources like Mike's [web map workshop](http://duspviz.mit.edu/web-map-workshop/) can help build up skills necessary for advanced web mapping. --- ## Additional options for web maps - **[D3](https://d3js.org/)** - very powerful JavaScript library for expressive data visualization, including many built-in mapping functions. It has a steeper learning curve, but is well-documented with many [examples](https://github.com/mbostock/d3/wiki/Gallery) and [tutorials](http://alignedleft.com/tutorials/d3) out there. - **[Mapbox](https://www.mapbox.com/)** - A company on the cutting edge of web mapping, offering a whole platform and suite of tools. Especially good for designing and hosting global maps based on OpenStreetMap. - **[CartoDB](https://cartodb.com/)** - Web-based tool for plugging your data into a map quickly and easily, but also with many powerful capabilities. We highly recommend this if you're looking for the most painless way of turning your data into a web map. - **[OpenLayers](http://openlayers.org/)** - Another open-source web mapping library, similar to Leaflet in some ways. It's more feature heavy and has been around a while, with a lot of contributors behind it. - **[ArcGIS Online](http://www.arcgis.com/features/)** - Esri's product, intended as an easy, user-friendly way to make and share maps with your data. But, like their desktop software, it's geared more toward larger organizations than the open web, and doesn't have a free tier. --- ## Web mapping recap - "Web maps" are _powered by_ the web, not simply any maps that are online. - GeoJSON is the geodata format most commonly used for web maps. - "Slippy maps" are based on a standard tiling system, using either image tiles or vector data tiles. - [Leaflet](http://leafletjs.com) is the most popular open-source JavaScript library for building slippy maps. - Simple maps require little code, but coding is important. Improve your expertise by copying examples and studying how they work. --- ## Summary of everything! - If your data has a spatial component, you think it might contain some type of geographic trend, or reveal a geographic pattern, you can map it! - Maps are visual interpretations of place and highlight relationships between elements in space. Cartography is the study and practice of making maps. - When designing a map, one must consider the map medium, elements of design such as hierarchy, color, and font, data classification, normalization, scale, and projection, and how each of them affect the representation of your data. - Carefully consider how you want the user to interpret and interact with your map. You are telling a story! - Many types of software and tools exist for mapping, many of which designed around data management and analysis. These include QGIS, ArcGIS, R, Leaflet, and OpenLayers. - Despite your best efforts, not everything should be mapped, even if the data is spatial. Consider your options and what visual methods best convey your message to the reader. The data is the most important part. - View lots of maps and explore lots of examples. Over time, you will develop your own style and technique. --- ## Where to go from here [Maptime](http://maptime.io/) is a global collection of groups fostering collaborative learning of open mapping technologies. See if your city has a chapter! If you're local to Boston, join ours! There are several awesome mapping conferences coming up: - [FOSS4G North America](https://2016.foss4g-na.org/) - Raleigh, NC next week! - [State of the Map US](http://stateofthemap.us/) - Seattle, July 23–25 - [NACIS](http://nacis.org/annual-meeting/current-meeting/) - Colorado Springs, October 19–22. Call for participation is open! (Andy is on the NACIS board of directors) - [FOSS4G 2017](http://2017.foss4g.org/) - International conference here in Boston, August 2017. (Mike is on the planning committee) --- ## Learn more! There are many, many resources for learning about mapping. We've mentioned a few in the course of this workshop, but have compiled a more comprehensive list to go along with all the topics covered today. Go forth and learn! .bigger[ **[Cartography Crash Course Resources list](resources.html)** axismaps.io/crash-course/resources.html] Happy mapping! .citation[Andy and Mike]