Hurried Thoughts: Counting Area on Equirectangular Maps
Short one today: Just a little tool I worked up.
I've heard a few people asking lately about how to work out the true area of different continents on flat maps with distorted area. My usual recommendation so far has been to reproject the map to an equal-area projection and then count the pixels there—many image editors will show you the area of a selection in pixels. To be clear, though all flat map projections distort shapes and distances, you can perfectly preserve area (to the limit of the image resolution), and there are a variety of projections that do so; Mollweide is usually a good pick, but some form of cylindrical equal-area may be more convenient here because it's still rectangular and so should fill out the whole image, so you don't have to worry about what portion of the image should be counted as part of the total area of the surface.
But not everyone is familiar with the tools for reprojecting maps and even if they are it may be inconvenient, so I worked up a quick tool to count map areas directly in equirectangular projection, the most popular option for directly drawing a world map.
Now, I do need to emphasize that it specifically has to be an equirectangular projection. I think some people believe that all rectangular map projections are the same, but there's really a fair number of them, and the tool will give dramatically wrong results if applied to something like a Mercator projection. Equirectangular projections are built such that latitude and longitude on the globe correspond directly to x and y position on the map, which makes it fairly easy to correct the area distortion (it scales with cosine of latitude, and latitude can be assumed to scale linearly with map height from -90° to 90°). Equirectangular maps usually have a 2:1 width:height aspect ratio (i.e. they're twice as wide as tall), but they're not the only maps about that shape, and in principle they can be stretched or squeezed vertically. The tool I've built will still work fine with stretched equirectangular maps, but again that's not to say it will work with any shape of rectangular map; the difference between equirectangular projection and something like Miller runs deeper than just overall shape.
The map should also be global, rather than a subset of the world. Well, strictly speaking it only has to be vertically full, running from pole to pole; you can put in a map cut down to a subset of longitudes, but then the results will show area as a portion of that section of the world's area. (For anyone savvy enough to mess around with map aspects, it should also work in any aspect, so something like a Cassini projection would work, but it has to be oriented so that the long axis, corresponding to the equator in normal projection, is always horizontal).
The map should also stretch to the exact edges of the image, rather than there being some border or margin not part of the actual world's surface.
And finally, this tool will only work for raster images—which are constructed of pixels and used in tools like paint.net or gimp—and not vector images—which are constructed of lines and used in tools like inkscape.
Presuming you have an appropriate map image, use of the tool should be fairly straightforward: the repository contains both a python script (requiring numpy) and a standalone .exe, in either case run through a command line input: First, you'll be prompted for the image name, which should include any filetype like ".png", and then you'll be prompted for the total area of the map, though you can put in "0" to skip this and it'll just give you area as percentages of the world's total surface; for reference, Earth's surface area is 510 million km2.
The tool then looks through the image, finds each unique color, and then counts up the total area of that color, adjusting the true area of each pixel based on its position on the map. An artistically colored map may have thousands of unique shades, so to use this tool you may have to make a quick copy with all areas divided into separately colored regions; as a quick tip, make sure that you have any antialiasing turned off on any selection or color-fill tool so that you can completely fill areas with single colors rather than having blurred edges.
Here, for example, I've taken a map of Earth and divided it into black sea and white land:
The tool will then show a list of the colors its found and their corresponding area. It can't really show a full range of color within command line so it'll show the RGB values (or single value for a greyscale image), which you should generally be able to find on the image in an image editor with the color picker tool (if it helps, the image is scanned top-down by rows and left-right in each row, and each color will be listed based on the order in which they are first encountered). So here, it's showing about 70% area for the black oceans and 30% for the white land, which is about accurate considering that I wasn't too careful in how I prepared this map so it's overrepresenting the area of small islands and missing the Caspian sea:
If I wanted to know the area of each continent, I could then color in each separately:
And then the results are again about as they should be considering my sloppy bordering:
In any case, you'll then get the option to save the results, first to a text file, which essentially just saves what you see in the command line to the file area_counts.txt, and then to a .csv file, which can be read in a spreadsheet editor, showing each color value, the percentage areas, and the unit areas in separate columns (if excel asks if you want to convert the numbers, say yes).
Again the tool is available here in both python and standalone .exe forms, hope you find it useful.
Very useful tool. Thank you!
ReplyDeleteOh, nice. The method I've been using is just to reproject the equirectangular map as an equal-area one and then use GIMP to count the pixels. But this is probably a simpler method.
ReplyDeleteWonderful tool! Been looking for something like this for ages. I greatly appreciate it, thank you!
ReplyDeleteWait, this is SO MUCH EASIER to do then what I was doing before. I was manually tracing each of my continents in GPlates and using the measurement tool afterwards...
ReplyDeleteI was always waiting for a good way to measure continent size. Previously, I would use Globe 3D and try to eyeball the sizes
ReplyDelete