Tuesday, 30 April 2013

Hedgerows

And so back to the question that started me off on all this: hedgerows

There's a long history behind hedgerows. Some field boundaries are thought to date back to the bronze age (or even before); the pattern of some Anglo-Saxon fields has hardly changed since; there are field boundaries that were originally laid out in medieval times.

Hedgerows in these cases are described as "ancient".

However, the busiest period of hedge building in the UK was during the enclosures of common land between 1720 and 1840. This is estimated to have created about 200,000 miles of hedges. By the middle of the 19th century around half of all hedges must have been created by this process. Since then hedgerows have tended to disappear. There has been little large-scale planting since World War One, and developments in farming since the middle of the 20th century mean that perhaps a quarter of hedgerows have since been removed - though the rate of attrition now seems to have slowed.

The bottom line is that a substantial proportion of existing hedgerows in Britain must have originally been laid out in the late 18th and early 19th century.

The best estimate I have found of what is left dates from about twenty years ago. It says there were then about 300,000 miles of hedges across the UK. In absence of anything better, I'm going to assume that the figure is much the same now. Let's call it 500,000 km.

Roughly 17,000km of hedges have been added to OSM. About 3% of those are in residential, commercial or industrial areas, so they don't really count for this purpose. About 11% are definitely rural (based on land use tagging), but there's no obvious way to judge the type of land use for the other 86%. I'm guessing that it's mostly rural. That suggests that about 16,000km of hedgerows in OSM are in rural areas. They amount to roughly 3% of the total we should expect to find. That's not high coverage, but it's fairly typical for features receiving relatively little attention in OSM, and it's enough to start playing around with.

A normal hedgerow will encircle a field, and fields are all sorts of different shapes and sizes. At first I thought that in aggregate there should be roughly equal lengths of hedge heading in every possible direction. But then I heard that (all else being equal) farmers would tend to lay out hedges to keep any shadows cast on their crops to a minimum. To quote a Victorian farming manual:

"Should a field, or a number of fields, require laying off anew, the North and South fences should run due North and South for the purpose of giving the ridges an equal advantage of the sun both forenoon and afternoon".

Things are never quite as simple as the theory, but in a really simple world, we should expect fields to be aligned with the points of the compass, and longer in the north-south direction.

Quite a lot of our local field patterns date from enclosure, and the largest and flattest fields do seem to be aligned with the compass, and longer in a north-south direction than they are east to west.

Looking nationally, according to what has been plotted in OSM (for the British Isles), field boundaries do tend to run "horizontally" in a broadly East-West direction, or "vertically", in a broadly North-South direction. This is true for hedges, fences and walls. I have to admit that I don't see much evidence here that fields tend to be longer in a north-south direction than they are in an east-west direction.





In reality, of course, many hedges follow natural features, such as streams or the slope of hills; and many follow man-made features such as roads or paths. It would only be in a fairly featureless landscape that landowners had a free choice where to lay out their field boundaries. The relationships between a field boundary, and man-made features is likely to have a particularly complex history.

But lets suppose for a moment, that there were enough landowners who were free to chose where they built field boundaries, and that the result still shows up in the data. We might expect landowners to follow the advice above, and try to align the left and right side of fields as closely as possible to due north, so that  shadows on the crops were minimised. There is probable a case for keeping fields more or less rectangular, but the case for aligning the north and south boundaries of a field with due east and west would be weaker. So they would be more inclined to follow natural and existing man-made features. The boundaries would be seem to be oriented more randomly, because they were shaped by other considerations..

When I look at the distribution of orientations around the main compass points, I'm not even sure I can see evidence that the fall of the sun might have had an effect on the direction of north / south field boundaries. The spread around the North-South axis seems similar to the spread around the East-West axis.

So there we are. Field boundaries tend to be aligned with the main points of the compass, but beyond that there is little here to suggest that the fall of the sun has much effect.

I should, of course, point out that the data I am using includes quite a lot of noise. For simplicity I'm not including quite of a lot of data that might be relevant (traces that mark the outline of a field, but omit the type of barrier, for example). And although they don't make up a huge proportion of the total, it would probably be better to eliminate boundaries in in urban areas, which shouldn't count as field boundaries.

There are also quirks in the way mappers choose which data should be plotted. For example (from inspection), it looks to me as though field boundaries that don't follow the edge of a road are more likely to be plotted than field boundaries which do. This might affect the results.

So it's all very speculative. Nevertheless, it's provided an interesting diversion: for me, ,and I hope for others.

---------------------------------

By the way, more "horizontal" hedges in OSM were drawn from west to east than from east to west, but obviously there is no inherent direction implied here. Contributors must just be more likely to draw "horizontal hedges "rightwards". They don't seem to have a similar preference between drawing "vertical" hedges "upwards" (from south to north) or "downwards" (north to south).

Road alignments revisited


Here is the plot of road orientations in the British Isles, with the earlier problem with projection fixed.

As before, mappers seem to have a preference for tracing roads in a West-to-East direction. There also seems to be a preference among highway engineers for building roads along the main points of the compass, and a tendency to avoid roads at 45 degrees to the main points of the compass. The pattern is similar for all types of road.

With the exception of motorways, there is also a bit of a bulge at around 70 degree east of due north. I can't see why that should be, but given the volume of data that underlies this, it's unlikely to be a fluke, so there should be some rational explanation.

In the previous discussion there was a suggestion that mappers might provide more detailed traces for roads running horizontally (East-West, rather than North-South) but I can't see evidence of that in the data. The average length of road segments is much the same for all directions.

Anyway, for what it's worth, there it is. Not as interesting as the graph that had a fundamental error in it (unfortunately) - but hopefully a bit closer to reality.

Monday, 29 April 2013

Building alignments revised

 

With thanks for all the help, and apologies for causing confusion, I now have a more sensible view of how buildings are aligned in OSM, at least for the British Isles. The main puzzle is solved, and of course it was all my own fault. I had realised that I had to re-project the data to get sensible estimates of way lengths, but I hadn't realised that I needed to do the same to get to the orientation. Of course it is blindingly obvious with hindsight, but at the time....  

Now that is fixed, the distribution looks more sensible to me. 

It is still showing spikes on the four main points of the compass, and a smaller cluster rotated about 30% anti-clockwise. Whether that is how buildings are actually oriented is another question altogether. I haven't managed to extract the source for most of these outlines, but about 3% of them say they are traced from OS Open Data, and about 1.5% from Bing. All show similar characteristics.

Now a similar analysis is grinding through for roads, and I will post the results when I get them, in case anyone is still interested.

What is going on here? ...continued

Thanks for the interesting responses to the last past.

I'm inclined to think that the most plausible explanations are that the "spikes" are artefacts, and that most of the effect I am seeing are due to aligning buildings so they capture the sun.

However, I'm not sure it can be as simple as that.

Here is a similar plot based on the alignment of different types of road in the British Isles. The characteristics are similar to buildings: a bias towards East-West orientation, and spikes at the main points. There also seems to be quite a strong tendency for UK mappers to draw roads from West to East, which is quite interesting, but not particularly important. You wouldn't expect the same effect for buildings of course - because they need to be traced all the way round.

We could imagine the travel of the sun affecting both roads and buildings. There might be a link between the alignment of buildings and residential roads, and some other built up roads for example. But I'm not sure this would explain why all the different road types show the same effect.

The bottom line is that I can't convince myself that the travel of the sun is sufficient explanation.

My other concern is that different map projections are having an effect on my calculation of way lengths. But at the moment I can't see what the problem could be. This time I've used ST_Distance_Sphere  to calculate the distance between end points of each straight line, instead of transforming coordinates to OSGB and using ST_Length. I haven't tried ST_Distance_Spheroid yet, but perhaps I should. I understand it is more accurate, but much slower. And surely it wouldn't make enough difference to have this much effect. Or would it?

Sunday, 28 April 2013

What is going on here?


The chart illustrates the alignment of buildings in the OSM database, for the British Isles. The trace of each building was divided into line segments, and the orientation of each segment to due north was calculated. Then the lengths of segment were totalled according to their orientation, and the result plotted as shown above.

If buildings were arranged randomly you would expect the plot to be more-or-less circular: with roughly equal lengths of the building perimeter heading in every direction. Clearly life isn't as simple as that.

What the chart suggests is:

  • A relatively high proportion of buildings are oriented along the main points of the compass: North-South and East-West. Hence the spikes at the top and bottom, left and right.
  • There is a second, smaller, cluster of walls that run roughly 15 degrees (anti-clockwise) off the main points of the compass. Lets say EENE, WWSW
  • There is a tendency to align buildings so that longer walls run roughly East-West and shorter walls run roughly North - South. Hence the oval shape in the chart, with the major axis running horizontally, and the minor axis running vertically.
The question is, why?

Specifically: I loaded an extract of OSM data covering the British Isles into a Postgres / Postgis database. I split ways that define buildings into individual line segments (the straight lines between each node). I calculated the orientation of each line segment using the ST_Azimuth function. All of this was based on the original WGS84 projection. I calculated the length of each segment by transforming the projection to OSGB 1936, and using the ST_Length function to get the length in metres. Totals were summed in the Postgres query, and I plotted the results in Excel. 

For what it's worth, I've tried this with various man-made features (roads, hedges, etc). The east-west orientation seems pretty common. So far I've only found the spikes on the main points of the compass for buildings.

Tuesday, 16 October 2012

Local maps

Things have been pretty busy over the last few months. Partly because we are still working through the house decorating, and fixing. Partly because we got a puppy (which provides endless amusement). And partly because we are getting more involved in various local activities. One of those is helping to produce  a newsletter for one of our local societies. I thought some of the items in the newsletter might benefit from a map, so I set off on a journey to work out how best to produce street plans of a small town, with various content overlaid. As I should have known, that's turned out to be something of a diversion.

A few years ago, my first effort at generating maps from OSM data was based on overlaying the standard renders with KML files. That worked fine when I wanted to highlight a route, or a few locations, over a slippy map and place it on a web site.

Later I got it into my head that I would try to replicate the old Bartholomew's half-inch maps using OSM data. I wanted to generate maps that covered quite a large area (roughly the size of a county), and I wanted to do quite a lot of manipulation of the data. I used Mapnik to do the rendering, and a Postgis database to manage the content, with various home-made tools based on SQL and Perl.

Now I only need to cover quite a small area. Most of the time I just want to map the centre of a small town, so the maps are only a mile or so across. Sometimes I will want to cover a bit more of the surrounding area, but still no more than a few miles in each direction. The amount of data that I need to crunch is quite small.

At the moment I'm using Quantum GIS (QGIS), working directly from OSM extracts. There are a few glitches, but for most purposes it works fine. I'm not going to attempt a whole cook-book, but here are some tips, based on my experience so far:

  • I am using the Openlayers plugin in QGIS. Openlayers will add a raster layer to your map pulled from the standard Mapnik render, or from Bing imagery (or various other sources). These help with positioning your overall map, selecting data to download, and editing stuff that you want to add.
  • I use the OSM plugin in QGIS. Among other things, over a small area, that will download data directly from the OSM database, which gets you started quickly. 
  • Change the default OSM styles. I got hold of the "light" styles described here, then edited them to suit my purposes. They look a lot better than the standard styles, particularly when you are overlaying data to highlight features on top of a base map
  • For areas that are too big to work directly from OSM data, I'm downloading the Planet data, and extracting a subset using OSMOSIS. This isn't very sophisticated in the way it trims the bounding box, so you need to add a fairly generous margin to pick up any long ways that run outside the area you are interested in.
  • Where I want to edit data for my own purposes, I'm using Perl to do automated edits on my local data extract, or JOSM on my local extract for manual edits. Every time I do this I'm scared I will accidentally upload my edits back to OSM. If there is a less risky alternative I'd love to hear about it. So far I haven't hit the wrong button. On the sort of data volumes I'm handling this is fast enough, and much easier than Postgis, but I'm beginning to miss some of the more sophisticated Postgis tools.
  • I don't think I've yet worked out the best way to add extra GIS data for my own use. The basics - to add a layer, draw some features, edit them, apply styles and labels - are straightforward enough. However I'm starting to want to go on and edit more attributes, add a mix of lines and points, and the like. But without going into full-blown database management. The tools all seem to be there, but I've not got my head around how to do it easily (yet).
  • I haven't found a decent way of showing the shape of the landscape on my small maps, because the free elevation data is too coarse. Across a slightly wider area covering a few miles, it's not hard to import OS Landform data (ASC format) into QGIS, re-scale it to get smoother shading, then colour according to elevation, add hillshading, contours, or whatever.
  • I've been reprojecting stuff to the National Grid Coordinate system (OSGB 27700, rather than WGS 84). To my eyes, the proportions looks more as they should, and it also allows me to work in map units of a metre, rather than degrees, or pixels.
  • Don't expect everything to work. I'm still having problems with roundabouts, and multipolygons with inners and outers. Most of the time this doesn't matter to me, and where it does I'm kludging the data to work around it. Maybe there's a better solution, but I can live without one for now.
  • In my experience, using data in different ways is one of the best ways of improving quality. So I make a note of anything in the base data that is going to need fixing, so that I can go back and fix it later. But I make sure that I handle the fixes separately from anything in the data that I want to adjust for my own purposes. That way there is no confusion between "I want my map to look like this" and "OSM should hold the data like this". I'm now starting to use separate data and separate layers for the stuff that I pull directly from OSM, and leave unchanged, and the stuff that I am pulling from OSM, and editing before I use it. That's partly just because it makes it easier to manage, but I think it's probably good practice anyway.
The bottom line is, if you want to generate a map of a relatively small area, QGIS may well do the job for you. It isn't a solution straight out of the box, but the learning curve isn't as steep as some of the alternatives. that I've tried.

And if you enjoy doing this stuff, then you might find that the person who edits the newsletter or the web site for one of your local societies might welcome some help.

Tuesday, 14 August 2012

Accidents in 20mph zones

Fullfact has been looking at various media reports on accident statistics in 20mph zones. In essence official statistics show that the number of accidents in 20mph zones has been rising. The conclusion drawn by some media is that this shows that 20mph zones don't work. In reality Fullfact finds that the figures take no account of the expansion in the use of 20mph limits. So an increase in the number of accidents tells us nothing about  the effectiveness of 20 mph zones.

To make any real sense of the raw data we would need to know how many roads have a 20 mph limit, and how much traffic they carry. It seems that the DfT can't help, because they don't know.

I wondered if the OSM data could provide any more information.

OSM contributors have added speed limits to about 9% of the UK road network. As a result, about 3,500km of road currently show a speed limit of 20 mph. That represents just under 1% of the whole road network, and just under 3% of minor urban roads.

We must bear in mind that some 20 mph zones will not yet be added to the database. And OSM data isn't always accurate, so it's also possible that some roads have been marked incorrectly as having a limit of 20mph. We could make some assumptions about roads that don't yet carry speed limit information, but it doesn't help a lot here. It is normally safe to assume that OSM data is incomplete, but less likely that data is inaccurate. So we can make a reasonable assumption that the true extent of 20mph roads is going to be higher than the recorded figure. In other words, we can use the data to estimate that at least 1% of the UK road network now has a 20mph limit, and 20mph limits now represent almost 3% of minor urban roads.

Meanwhile, according to ONS/DfT data, 20mph zones account for just over 1% of all accidents, and 1.6% of accidents in built-up areas. In other words, the proportion of accidents in 20mph zones seems no higher than the proportion of 20mph roads. If we just look at built-up areas then the accident rate in 20mph zones is about half what we might otherwise expect.

Perhaps more importantly, the DfT data on its own shows that the mix of accidents is different under different speed limits. With a 40mph limit, one in 100 accidents involves a death; at 30mph it is one in 200, and at 20mph it better than one in 300. In 20mph zones the number of deaths on the road could be as little as a tenth of the level elsewhere.

All this doesn't get us to complete and reliable figures, it can take no account at all of traffic volumes, and there are surely some more complex causes and effects underlying the data. Nevertheless, if the limited numbers that we have tell us anything, it is that accidents in 20mph zones are in line with the obvious hypothesis that lower speed limits are associated with fewer, less serious, accidents.



More here - http://www.sustrans.org.uk/resources/in-the-news/are-20-streets-really-less-safe