Difference between revisions of "Land usage"
imported>Relet (+now allows for multiple colours to have the same meaning) |
imported>Relet (+now with sorted output and moar colours.) |
||
Line 13: | Line 13: | ||
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. | 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. To do so, use the pipette tool in your favourite image editor and select a pixel in a large field of uniform colour. Copy the colour values for R(ed), G(reen), B(lue) - and A(lpha = opacity), which should always be 255. | + | Note that Google uses antialiasing. Hence, the script will only recognize large areas of uniform colour, but not anything in-between. Also, due to some shading effects, several colours are used for the same type of area across the graticule. 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. To do so, use the pipette tool in your favourite image editor and select a pixel in a large field of uniform colour. Copy the colour values for R(ed), G(reen), B(lue) - and A(lpha = opacity), which should always be 255. I have tried to compile a first list of used colours in the source code, please update this as needed. |
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". | 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". | ||
Line 19: | Line 19: | ||
=== Example === | === Example === | ||
<pre>./graticount.py berlin.png | <pre>./graticount.py berlin.png | ||
− | + | 37.03% Forests | |
− | + | 29.14% Fields | |
− | + | 11.23% Natural reserves | |
− | + | 9.19% Roads | |
− | + | 6.84% Settlements | |
− | + | 3.84% Highways | |
− | + | 2.12% Water | |
+ | 0.62% Industrial | ||
</pre> | </pre> | ||
Line 34: | Line 35: | ||
import Image, sys | import Image, sys | ||
− | colors = {( | + | colors = { |
− | ( | + | (183,205,161,255):"Natural reserves", |
− | + | (183,205,162,255):"Natural reserves", | |
− | ( | + | (184,206,162,255):"Natural reserves", |
− | (255, | + | (211,215,198,255):"Forests", |
− | ( | + | (211,215,199,255):"Forests", |
− | ( | + | (212,215,199,255):"Forests", |
− | ( | + | (212,216,199,255):"Forests", |
− | ( | + | (216,208,206,255):"Industrial", |
+ | (216,208,207,255):"Industrial", | ||
+ | (235,224,214,255):"Settlements", | ||
+ | (235,224,215,255):"Settlements", | ||
+ | (235,224,216,255):"Settlements", | ||
+ | (236,225,216,255):"Fields", #type 1 | ||
+ | (242,195, 72,255):"Highways", | ||
+ | (243,195, 72,255):"Highways", | ||
+ | (243,196, 72,255):"Highways", | ||
+ | (243,196, 73,255):"Highways", | ||
+ | (244,196, 73,255):"Highways", | ||
+ | (242,233,227,255):"Fields", #type 2 | ||
+ | (243,233,228,255):"Fields", | ||
+ | (243,233,229,255):"Fields", | ||
+ | (243,234,229,255):"Fields", | ||
+ | (252,241,134,255):"Roads", | ||
+ | (252,241,135,255):"Roads", | ||
+ | (252,242,135,255):"Roads", | ||
+ | (253,242,135,255):"Roads", | ||
+ | (253,243,135,255):"Roads", | ||
+ | (254,243,135,255):"Roads", | ||
+ | (171,185,205,255):"Water", | ||
+ | (172,185,205,255):"Water", | ||
+ | (172,186,205,255):"Water", | ||
+ | (172,186,206,255):"Water", | ||
} | } | ||
Line 48: | Line 73: | ||
counts = {} | counts = {} | ||
total = 0 | total = 0 | ||
+ | results = [] | ||
image = Image.open(sys.argv[1]) | image = Image.open(sys.argv[1]) | ||
Line 60: | Line 86: | ||
total = total + count | total = total + count | ||
for label, count in counts.iteritems(): | for label, count in counts.iteritems(): | ||
− | print "%.2f%%\t%s" % | + | results.append((count*100.0/total, label)) |
+ | results.sort(reverse=True) | ||
+ | for result in results: | ||
+ | print "%.2f%%\t%s" % result | ||
</pre> | </pre> |
Revision as of 22:34, 19 August 2008
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.
Contents
Usage
- Highlight your graticule in the peeron map.
- Make a screenshot (moar zoom = moar better).
- Save it in your preferred lossless image format (png is fine).
- 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. Also, due to some shading effects, several colours are used for the same type of area across the graticule. 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. To do so, use the pipette tool in your favourite image editor and select a pixel in a large field of uniform colour. Copy the colour values for R(ed), G(reen), B(lue) - and A(lpha = opacity), which should always be 255. I have tried to compile a first list of used colours in the source code, please update this as needed.
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 37.03% Forests 29.14% Fields 11.23% Natural reserves 9.19% Roads 6.84% Settlements 3.84% Highways 2.12% Water 0.62% Industrial
Code
it's python. ready for take-off.
#!/usr/bin/env python import Image, sys colors = { (183,205,161,255):"Natural reserves", (183,205,162,255):"Natural reserves", (184,206,162,255):"Natural reserves", (211,215,198,255):"Forests", (211,215,199,255):"Forests", (212,215,199,255):"Forests", (212,216,199,255):"Forests", (216,208,206,255):"Industrial", (216,208,207,255):"Industrial", (235,224,214,255):"Settlements", (235,224,215,255):"Settlements", (235,224,216,255):"Settlements", (236,225,216,255):"Fields", #type 1 (242,195, 72,255):"Highways", (243,195, 72,255):"Highways", (243,196, 72,255):"Highways", (243,196, 73,255):"Highways", (244,196, 73,255):"Highways", (242,233,227,255):"Fields", #type 2 (243,233,228,255):"Fields", (243,233,229,255):"Fields", (243,234,229,255):"Fields", (252,241,134,255):"Roads", (252,241,135,255):"Roads", (252,242,135,255):"Roads", (253,242,135,255):"Roads", (253,243,135,255):"Roads", (254,243,135,255):"Roads", (171,185,205,255):"Water", (172,185,205,255):"Water", (172,186,205,255):"Water", (172,186,206,255):"Water", } stats = {} counts = {} total = 0 results = [] 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]] = colors[pixel] in counts and counts[colors[pixel]]+count or count for label, count in counts.iteritems(): total = total + count for label, count in counts.iteritems(): results.append((count*100.0/total, label)) results.sort(reverse=True) for result in results: print "%.2f%%\t%s" % result