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:

San Francisco PD Department Shapefile:

Here's the R Notebook:

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