Saturday, October 11, 2014

GIS with R

Initially I tried QGIS, thinking that a system using a GUI interface would be quicker than one where you have to code and spend time figuring out syntax and data structures. WRONG! After crashes and a frustrating attempt to create a heat map, I switched to using R. Yes, figuring out which libraries to use and understanding the syntax took time, but I found it was still faster than trying to use QGIS.

I overlaid the Google maps image of San Francisco with the Police Districts shapefile, then colored the districts based on the frequency of violent crime in the area. The piece that took the most time was putting the district names at the center of each district, because I couldn't figure out how to get the latitude and longitude of shapefile centers. Eventually StackOverflow came to my rescue: http://stackoverflow.com/questions/16462290/obtaining-latitude-and-longitude-with-from-spatial-objects-in-r


San Francisco PD Department Shapefile: https://data.sfgov.org/Public-Safety/SFPD-Districts-Zipped-Shapefile-Format-/8yyx-6uur

Here's the R Notebook: http://rpubs.com/LukasHalim/28754


I also did some non-GIS analysis, to whether crimes are reported more at certain times, which crimes are reported most frequencly, and whether certain Police Districts have a higher proportion of unresolved incidents.

Crime Frequency

Crimes by Hour