<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/spatial-networks-case-study-st-james-centre-edinburgh-13/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://scottishsnow.wordpress.com/2017/10/08/spatial-networks-stjames-1/"> R – scottishsnow</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Last year I spent a bit of time learning about routing and network analysis. I created a <a rel="nofollow" href="https://mikerspencer.carto.com/viz/c7cf448e-2727-11e6-8d2f-0ecd1babdde5/public_map" target="_blank">map of distance from each GB postcode to the nearest railway station</a>. At the time my local council were also looking at changing school catchments and building new schools. This also seemed like an excellent project for routing analysis. I made some progress on this, but never wrote it up.</p>
<p>One aspect I was really interested in was common routes. When you create a shortest path network from many points to a single destination you get a lot of lines which converge on the same place. Can we use this for anything else? Can we count how many lines share the same pathways? This would be particularly useful for prioritising investment in safe routes to school, or walking and cycling infrastructure.</p>
<p>I was spurred to look at this analysis again from the tweet below:</p>
<blockquote class="twitter-tweet">
<p dir="ltr" lang="en">Have to question the merits of people coming from the west driving across the city centre to get to St James’s Ctr.</p>
<p>— Cllr Scott Arthur (@ProfScottThinks) <a rel="nofollow" href="https://twitter.com/ProfScottThinks/status/916211752425132032?ref_src=twsrc%5Etfw" target="_blank">October 6, 2017</a></p>
</blockquote>
<p>For background, the St James’s Centre in Edinburgh is being demolished and a new shopping centre built to replace it. There’s been <a rel="nofollow" href="http://www.broughtonspurtle.org.uk/news/no-major-rethink-picardy-place" target="_blank">a lot of (justified) complaint</a> surrounding the new road layout at Piccadilly Place, because it prioritises motorised traffic over <a rel="nofollow" href="https://twitter.com/urbanthoughts11/status/913863196892680195" target="_blank">more efficient and effective ways of transporting people in cities</a> (foot, bike, bus and tram). On top of this, the new St James’ centre will have a <a rel="nofollow" href="https://twitter.com/SpokesLothian/status/916015561620025344" target="_blank">greatly increased number of spaces for parked cars</a> (1800 from 550. With 300 for residents).</p>
<p>Scott’s tweet made me think about catchment area for the St James’ centre. How far away are different parts of Edinburgh? Which roads would be most travelled to get there? If one increases the number of parking spaces at a location, surely the number of cars travelling to that location will increase. What will the impact on the road network be?</p>
<p>There are some great resources to help us with this. The data source I’m going to use is <a rel="nofollow" href="https://www.ordnancesurvey.co.uk/innovate/innovate-with-open-data.html" target="_blank">Ordnance Survey OpenData</a>. In particular we need <a rel="nofollow" href="https://www.ordnancesurvey.co.uk/business-and-government/products/os-open-roads.html" target="_blank">Open Roads</a> and <a rel="nofollow" href="https://www.ordnancesurvey.co.uk/business-and-government/products/code-point-open.html" target="_blank">CodePoint</a> (postcodes). Software I’ll use for this task are <a rel="nofollow" href="http://qgis.org/" target="_blank">QGIS</a>, <a rel="nofollow" href="https://grass.osgeo.org/" target="_blank">GRASS GIS</a> and <a rel="nofollow" href="https://cran.r-project.org/" target="_blank">R</a>. These are open source and require a little practice to use, but the effort pays off!</p>
<p>After reading data into GRASS I calculated the distance network from all postcodes to the St James’ Centre:</p>
<pre>
# connect postcodes to streets as layer 2
v.net --overwrite input=roads points=postcodes output=roads_net1 operation=connect thresh=400 arc_layer=1 node_layer=2

# connect st james to streets as layer 3
v.net --overwrite input=roads_net1 points=stjames output=roads_net2 operation=connect thresh=400 arc_layer=1 node_layer=3

# shortest paths from postcodes (points in layer 2) to st james (points in layer 3)
v.net.distance in=roads_net2 out=pc_2_stjames flayer=2 to_layer=3

# Join postcode and distance tables
v.db.join map=postcodes column=cat other_table=pc_2_stjames other_column=cat

# Make a km column
v.db.addcolumn map=postcodes columns=&quot;dist_km double precision&quot;
v.db.update map=postcodes column=dist_km qcol=&quot;dist/1000&quot;

# Write to shp (for mapping in QGIS)
v.out.ogr -s input=postcodes output=pc_2_stjames format=ESRI_Shapefile output_layer=pc_2_station
</pre>
<p>We can see the results of this below:</p>
<div data-shortcode="caption" class="wp-caption"><img data-orig-file="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames.png?w=456" data-orig-size="1753,1240" data-medium-file="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames.png?w=456?w=300" data-attachment-id="1319" data-image-meta="{" data-image-description="" src="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames.png?w=456" data-permalink="https://scottishsnow.wordpress.com/2017/10/08/spatial-networks-stjames-1/pc_2_stjames/" data-large-file="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames.png?w=456?w=620" alt="pc_2_stjames" data-image-title="pc_2_stjames" sizes="(max-width: 620px) 100vw, 620px" data-comments-opened="1" class="wp-image-1319" data-recalc-dims="1">
<p class="wp-caption-text">Shortest road distance between each EH postcode and the St James’ Centre.</p>
</div>
<p>We can also zoom this map on the area inside the bypass and adjust the colouring to give us more resolution for shorter distances.</p>
<div data-shortcode="caption" class="wp-caption"><img data-orig-file="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames_zoom.png?w=456" data-orig-size="1753,1240" data-medium-file="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames_zoom.png?w=456?w=300" data-attachment-id="1377" data-image-meta="{" data-image-description="" src="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames_zoom.png?w=456" data-permalink="https://scottishsnow.wordpress.com/2017/10/08/spatial-networks-stjames-1/pc_2_stjames_zoom/" data-large-file="https://scottishsnow.files.wordpress.com/2017/10/pc_2_stjames_zoom.png?w=456?w=620" alt="pc_2_stjames_zoom" data-image-title="pc_2_stjames_zoom" sizes="(max-width: 620px) 100vw, 620px" data-comments-opened="1" class="wp-image-1377" data-recalc-dims="1">
<p class="wp-caption-text">Shortest road distance between each EH postcode and the St James’ Centre, zoomed on the area within the Edinburgh bypass.</p>
</div>
<p>Now we can use R to investigate how many postcodes are within these distances. R can talk directly to GRASS, or we can use the exported shp file.</p>
<pre>
library(rgdal)

# Read shp file
# Note OGR wants the full path to the file, you can't use '~'
postcodes = readOGR(&quot;/home/me/Projects/network/data/pc_2_stjames.shp&quot;)

hist(postcodes$dist_km, breaks=50)
# Rank the distances
x = sort(postcodes$dist_km)

png(&quot;~/Cloud/Michael/Projects/network/figures/stjames_postcode-distance.png&quot;, height=600, width=800)
par(cex=1.5)
plot(x, type=&quot;l&quot;,
     main=&quot;EH postcode: shortest road distances to St James centre&quot;,
     xlab=&quot;Number of postcodes&quot;,
     ylab=&quot;Distance (km)&quot;,
     lwd=3)
points(max(which(x&lt;2)), 2, pch=19, cex=2, col=&quot;purple4&quot;)
points(max(which(x&lt;5)), 5, pch=19, cex=2, col=&quot;darkorange&quot;)
legend(&quot;topleft&quot;,
       c(paste(max(which(x&lt;2)),
               &quot;postcodes within 2 km (walking distance)&quot;),
         paste(max(which(x&lt;5)),
               &quot;postcodes within 5 km (cycling distance)&quot;)),
       col=c(&quot;purple4&quot;, &quot;darkorange&quot;),
       pch=19,
       pt.cex=2)
dev.off()

# Get percentages
round(100 * max(which(x&lt;2)) / length(x))
round(100 * (max(which(x&lt;5)) - max(which(x&lt;2))) / length(x))
</pre>
<div data-shortcode="caption" class="wp-caption"><img data-orig-file="https://scottishsnow.files.wordpress.com/2017/10/stjames_postcode-distance.png?w=456" data-orig-size="800,600" data-medium-file="https://scottishsnow.files.wordpress.com/2017/10/stjames_postcode-distance.png?w=456?w=300" data-attachment-id="1369" data-image-meta="{" data-image-description="" src="https://scottishsnow.files.wordpress.com/2017/10/stjames_postcode-distance.png?w=456" data-permalink="https://scottishsnow.wordpress.com/2017/10/08/spatial-networks-stjames-1/stjames_postcode-distance/" data-large-file="https://scottishsnow.files.wordpress.com/2017/10/stjames_postcode-distance.png?w=456?w=620" alt="stjames_postcode-distance" data-image-title="stjames_postcode-distance" sizes="(max-width: 620px) 100vw, 620px" data-comments-opened="1" class="wp-image-1369" data-recalc-dims="1">
<p class="wp-caption-text">Ranked distance between EH postcodes and the St James centre, with markers for walking and cycling distance.</p>
</div>
<p>As we can see, 1868 postcodes are within walking distance of the St James’ Centre and 7044 within cycling distance. If we</p>
<ol>
<li>Ignore the other shopping centres around Edinburgh,</li>
<li>Assume that population density is consistent between postcodes,</li>
<li>Take the complete EH postcode locations as the catchment area,</li>
</ol>
<p>then 8 % of total customers are within walking distance (2 km), a further 22 % are within cycling distance (2-5 km) and the remaining 70 % would need to travel by other means. I wonder if there will be 330 cycle parking spaces at the St James centre? This would be proportional to the number of car parking spaces. This assumes that those beyond cycling distance need to drive, but much of the population will be near a bus stop.</p>
<p>Additional work:</p>
<ul>
<li>Create an <a rel="nofollow" href="https://grass.osgeo.org/grass72/manuals/v.net.alloc.html" target="_blank">allocation network</a> for all Edinburgh shopping centres with car parks. What is St James’ catchment from that?</li>
<li>Use the <a rel="nofollow" href="http://scotland.datashine.org.uk/" target="_blank">census data</a> to compare car ownership with the St James’ allocation network. Car ownership is probably quite low in the city centre!</li>
<li>Consider travel time, not just distance.</li>
<li>How many of those outside walking/cycling distance are near a bus stop?</li>
</ul>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scottishsnow.wordpress.com/1257/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/scottishsnow.wordpress.com/1257/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://scottishsnow.wordpress.com/2017/10/08/spatial-networks-stjames-1/"> R – scottishsnow</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/_325dJwFVe8" height="1"></a></div>