Skip to content
Prev 122 / 197 Next

[OGRUG] RStudio, CIty of Ottawa Trees Dataset & Ottawa Tree Canopy Project.

Hi Everyone,

Since there seems to be some interest in exploring this a bit more, here's the more technical explanation of what I've done so far. I'm an R novice at best, so I would be very happy to learn of better or more efficient or more elegant ways to accomplish this. As far as a webapp, the possibility of Shiny comes to mind, but I have no idea whether that's something you could bundle up and embed on a webpage and/or whether your Shiny server and R implementation necessarily need to be on the same machine. 

The dataset is here: http://data.ottawa.ca/dataset/tree-inventory-street-trees

The KML file is basically just a flavour of XML. I spent probably too much time messing around with the R XML stuff before finding the sp and rgdal packages (both at CRAN). The readOGR function from rgdal gave me a SpatialPointsDataframe object, that took just over half the size of the KML file in RAM. This gets you the coordinates in an array, and metadata still stored in blobs of XML. At first I just used perl regular expressions to go fishing for the fields I wanted but later I used readHTMLTable and laply to grab everything. 

Then to get it all into a pretty plot, I used ggmap to put a map down and ggplot to put the trees on top. At the end you get something like the linked PDF from the R script I included below:



https://dl.dropboxusercontent.com/u/4647535/GlebeTrees.pdf

Cheers,

Dan Buijs
On 2014-05-20, at 8:55 PM, Joseph Potvin wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-ug-ottawa/attachments/20140520/0c47cf4b/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OttawaTrees.R
Type: application/octet-stream
Size: 1724 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-ug-ottawa/attachments/20140520/0c47cf4b/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-ug-ottawa/attachments/20140520/0c47cf4b/attachment-0003.html>