Land usage

From Geohashing
Revision as of 17:12, 19 August 2008 by imported>Relet (New page: Here's a small piece of code that allows you to calculate the land usage distribution in your graticule. It's a hack, and you should know how to interpret the results. === Usage === # Hig...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Here's a small piece of code that allows you to calculate the land usage distribution in your graticule. It's a hack, and you should know how to interpret the results.

Usage

  1. Highlight your graticule in the peeron map.
  2. Make a screenshot.
  3. Save it in your preferred lossless image format (png is fine).
  4. Run this script with the image file as a parameter.

Note: You may have to adapt the color values - read the next section.

How it works

The script basically counts pixels on your screenshot. It has a list of colours which are used on the map for certain areas.

On the screenshot of your graticule, all pixels within the graticule highlight are slightly rosé, compared to everything else. Forests are green-rosé, Natural reserves are dark-green-rosé, bodies of water are blue-rosé, and so on. The script counts all pixels for which a meaning is given, and ignores everything else. Finally, it compares the count of each colour with the total count of identified pixels.

Note that Google uses antialiasing. Hence, the script will only recognize large areas of uniform colour, but not anything in-between. The colours given are some few examples for the rendering used in Germany - if for example your highways are rendered in a different colour, you may have to adapt it. You may also want to add your own.

As the maps overemphasize roads on smaller scales, their results will likewise be exaggerated. You may want to ignore them alltogether, or interpret the value as "being rather close to a road/highway".

Example

./graticount.py berlin.png
3.00%   Highways
35.00%  Fields
6.00%   Settlements
33.00%  Forests
10.00%  Natural reserves
1.00%   Water
8.00%   Roads

Code

it's python. ready for take-off.

#!/usr/bin/env python
import Image, sys

colors = {(185,207,163,255):"Natural reserves",
          (213,217,200,255):"Forests",
          (245,235,230,255):"Fields",
          (255,244,136,255):"Roads",
          (245,197,73 ,255):"Highways",
          (173,187,207,255):"Water",
          (237,226,217,255):"Settlements",
          (218,210,218,255):"Restricted",
         }

stats = {}
counts = {}
total = 0

image = Image.open(sys.argv[1])
for pixel in image.getdata():
  stats[pixel] = (pixel in stats) and stats[pixel]+1 or 1

for pixel, count in stats.iteritems():
  if pixel in colors:
    counts[colors[pixel]] = count

for label, count in counts.iteritems():
  total = total + count
for label, count in counts.iteritems():
  print "%.2f%%\t%s" % (count*100/total, label)