Tuesday, December 8, 2009

Tuesday Tools: MapShaper

Have you ever had a shapefile whose features were so detailed that it looked messy and detracted from the message you were trying to convey?  When creating aesthetically pleasing maps, it is important to use shapefiles with a level of detail appropriate to the scale of the map.  For example, a map of the entire United States does not need to show every tiny bend in the rivers that demarcate state borders; however, those bends may be significant in a detailed map of a small town that lies along the state border.

There are two primary GIS techniques, called simplification and smoothing, that can be used to alter the appearance of shapefiles.  ArcGIS features both the Simplify and Smooth tools, which are included in ArcToolbox in the Data Management toolbox, under the Generalization toolset.  Unfortunately, these two tools are only available at the ArcInfo license level, precluding many ArcGIS users from having access to them.  (The GIS/Data Center does have a limited number of ArcInfo licenses available for patron use.)

The simplify tool reduces the number of vertices in the original data, resulting in a smaller and more manageable file with a lower resolution.  This tool is especially beneficial when modifying shapefiles for online GIS applications, where display time and processing time can be important.  It is important to note that this method is most appropriate for eliminating detail that is not required when the image is zoomed out.  When zoomed in closely, simplification often results in features that look even worse than the original.  Below is the image from the ESRI Support Center illustrating the two simplification methods available in ArcGIS.



The smooth tool smooths out sharp corners that are often the result of limited data sampling.  In contrast to the simplify tool, the smooth tool may actually create more vertices and more detail than was in the original shapefile, so it may not be desirable for web applications, but can be beneficial for creating aesthetically pleasing maps of detailed regions.  Below is the image from the ESRI Support Center illustrating the two smoothing methods available in ArcGIS.  Note that the Paek method smooths out and removes the peaks at each vertex, while the Bezier method maintains all vertices, but smooths the lines connecting them.



While the two ArcGIS tools are helpful, they can be tedious to use, because switching methods and levels of simplification requires exporting numerous iterations of shapefiles, comparing them all in a map document, and remembering what settings were used.  In other words, you cannot visually see which settings you like the best without first exporting the shapefile.

Mark Harrower (of the UW Cartography Lab) and his former student, Matthew Bloch (who now creates great interactive maps for the New York Times website), created an online Flash-based application, called MapShaper, that brings these same tools to the public in a free format that is far more intuitive to use than the existing ArcGIS tools.  Currently, MapShaper only features a simplify tool, though a smooth tool may become available in the future.  You are also limited to uploading shapefiles smaller than 80MB, which is more than sufficient for most general work.  The beauty of MapShaper is that you can see the results in real-time as you adjust the simplification method and level using a simple radio selection button and slider bar.  As a result, you can preview your selections before exporting, allowing you to export only once you are satisfied with the output.



In order to test out MapShaper, we selected a shapefile of Canada, because the jagged coastlines of the numerous islands in northeastern Canada often cause the country outline to look much thicker and messier in that region than along the Hudson Bay and the U.S. border.  In addition, there is extremely little development in that region, so it is highly unlikely that anyone interpreting the map would require a great level of detail there.  Below is an image of the original shapefile of Canada.



After importing the Canada shapefile into MapShaper and simplifying it 75% using the Special Visvalingam method, notice that the entire border now has a uniform appearance regarding the line weight of the country border.



Since MapShaper only outputs the simplified .shp and .shx files, the .dbf file (and any other accompanying files) from the original shapefile must be copied and renamed to match the new output shapefile before it will be usable.

But what happens if the simplification causes you to loose detail in an important area of your map?  For example, in the map below showing the vertices of numerous ocean inlets, imagine that fishing piers were located on the top and bottom inlets.  Simplification of the coastline would remove all the inlets, causing the fishing piers to look like they were on land. 



Conveniently, MapShaper allows you to remove or lock individual vertices before simplification, for fine-tuned manual control over the simplification process.  In the image below, we have marked the vertices of the inlets that we want removed (shown in orange) and marked the critical vertices of the inlets that we want to keep (shown in red).



Now, when we increase the simplification level, the removed inlets disappear, the top and bottom inlets remain in simplified form, and the inlets that were not marked either way become much shorter and less detailed.