<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Calisto MT";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hello all,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am working on mapping the density of calls for service for our police department in my town. Please excuse me because I’m completely self-teaching R, so I’m probably pretty inefficient in my programming. Also, this is probably a simple answer, so I apologize for that, but I hope someone can help. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The data that I have indicates the address of the call for service and I am interested in aggregating to regions of the town so that I can create a heat map that shows where in the town there are higher demands for service for police. My strategy thus far has been to geocode the address points, then to create a grid structure over the town, and then overlay the points to assign them to a grid. Then, I would like to calculate the frequency of which a cell has calls for service within it and create a heat map of the high density demand locations. Then, I’d like to map it with an overlay of the town streets (which I can do). <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Can anyone help on where to do next? I can calculate frequencies after I’ve converted the overlay output into a data frame, but I’m not sure how to add that in as like an attribute to the Spatial Polygon structure that I’ve created. I think this is almost like a join when you’re using ArcMap, but I’m not sure how to have that third variable for each cell and then plot it with appropriate color codes. Any ideas on how to get to the next point?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Here is some of the code I’ve done so far, which has gotten me to the point that I’ve geocoded the addresses, created a grid-like spatial polygon, and then overlayed the points to the polygon, then created the df for the overlay. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(gdata)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(ggmap)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(dismo)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(XML)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(PBSmapping)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(rgeos)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(sp)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>library(gstat)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>cfs<-read.xls("cfs.xlsx", sheet="Sheet1")<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>##create grid<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>grid<-GridTopology(c(-78.55, 38.85), c(0.0012, 0.0010), c(50,50))<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>grid.points<-SpatialPoints(grid)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>grid.pixels<-SpatialPixels(grid.points)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>poly<-as(grid.pixels, "SpatialPolygons")<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>plot(poly, col="white", border="grey", axes=T)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>## geocode addresses and plot<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>add<-geocode(cfs$location.address, oneRecord=FALSE)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>coordinates(add)<-c("longitude", "latitude")<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>plot(add, col="red", axes=T, add=T, pch=21)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>##overlay incidents to grid<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>over<-overlay(poly,add)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>over.df<-data.frame(over)<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks,<o:p></o:p></p><p class=MsoNormal>Reid<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b><span style='color:#222222;background:white'>Reid A. Wodicka | Town Manager</span></b><b><span style='color:#222222;background:white'><o:p></o:p></span></b></p><p class=MsoNormal><span style='color:#222222;background:white'>Town of Woodstock, Virginia<o:p></o:p></span></p><p class=MsoNormal><span style='color:#222222;background:white'>135 North Main Street | Woodstock, Virginia 22664<o:p></o:p></span></p><p class=MsoNormal><span style='color:#222222;background:white'>Phone: 540-459-3621 | Fax: 540-459-3085<o:p></o:p></span></p><p class=MsoNormal><span style='color:#222222;background:white'><a href="mailto:reid.wodicka@townofwoodstockva.gov"><span style='color:#0563C1'>reid.wodicka@townofwoodstockva.gov</span></a> | <a href="http://www.townofwoodstockva.gov"><span style='color:#0563C1'>http://www.townofwoodstockva.gov</span></a><o:p></o:p></span></p><p class=MsoNormal><span style='color:#222222;background:white'><o:p> </o:p></span></p><p class=MsoNormal><a href="http://www.facebook.com/pages/Town-of-Woodstock-Virginia/201011663375674"><b><span style='font-size:10.0pt;font-family:"Calisto MT";color:blue;text-decoration:none'><img border=0 width=32 height=32 id="Picture_x0020_1" src="cid:image001.png@01CEA8AC.DF008E80" alt="FB Icon"></span></b></a><span style='font-size:8.0pt;font-family:"Calisto MT";color:#4F6228'> </span>To find out the latest information, LIKE US on Facebook!<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>