The San Francisco Police Department has recently launched a new initiative to fight drug dealing near schools. As outlined in this article in the San Francisco Chronicle last Thursday, the police department is targeting drug dealers within 1,000 feet of San Francisco schools who are dealing heroin, crack, or methamphetamine during school hours. These particular drug offenses violate the “Juvenile Drug Trafficking and Schoolyard Act of 1988” and can add two to three years to the offender’s prison sentence.
The following video walks through how quickly we were able to use SpatialKey to filter down over 14,000 crime records from the past 90 days to isolate these exact drug crimes. By the end of this short 5-minute video we produce a list of the schools that have these particular narcotics incidents near them. This is an example of using the powerful proximity filtering in SpatialKey to filter one dataset by buffering around another, as well as filtering by type of crime, day of week, and hour of day.
Both the crime data and the school locations were downloaded from San Francisco’s new data warehousing website: datasf.org. The police department provides a feed of the last 90 days of crime incidents as a shapefile. The dataset used in the video was downloaded on September 21, 2009 and includes crime records from June 25, 2009 to September 20, 2009. Additionally, the city’s GIS department provides the files for the locations of all the private and public schools in San Francisco (both as shapes and as points).
How we did it: step-by-step
I’ll walk through a visual explanation of how we filtered down the 14,653 crimes. These steps are the ones you see performed in the video. You can click each screenshot thumbnail on the right to view the full screenshot.
Step 1: Load in the crime data
We imported the shapefile that we downloaded from the SFPD’s website into SpatialKey and opened a new full-screen map template. This initial map shows all 14,653 incidents. The heatmap shows the distribution of crimes in the city. It is very clear that the most crime activity occurs downtown.
Step 2: Buffer around the schools
We then brought in our second dataset, which was the shapes of all the public and private schools in San Francisco. We used the Proximity Filter capabilities of SpatialKey to create a 1,000 foot buffer around each school and only include the crimes within that buffer. You can see the filter in action and how it removed all the crimes that are not near schools. This filtered out approximately 6,000 crimes and brought our total count down to 8,417.
Step 3: Only show drug crimes
Since we were only interested in narcotics crimes, we opened up a pod to show the type of crime (this was a field called “Category” in the data provided by the SFPD). We filtered out all crimes except “Drug/Narcotics,” which left only 1,849 crimes.
Step 4: Filter by day of week and hour of day
Then we filtered by Day of Week to only include crimes occurring Monday through Friday. We also opened up a histogram showing the distribution by hour of day and we selected a range from 7 am to 4 pm. This is an approximation of school hours. Obviously all schools will have slightly different exact hours of operation.
Step 5: Only show heroin/crack/meth
The Juvenile Drug Trafficking and Schoolyard Act is specifically for certain types of drug crimes, so we needed to filter out the other drug crimes that we weren’t interested in. Luckily, the SFPD provides a field in the dataset called “Description” that provides more granular detail about the type of crime, including what type of drug was involved. We filtered out any crimes that did not include the sale of heroin, crack cocaine, and methamphetamine. This brought our total dataset down to 166 crimes.
So in literally under 4 minutes we were able to go from over 14,000 crimes to a very targeted list of 166 and from 243 schools down to a list of 21 that we would want to act on.
This data included crimes during the summer when it is likely that most schools are not in session. The purpose of this example is not to find the exact crimes that occurred during the actual school hours, but instead to find the geographic locations where crimes tend to occur during school hours. The areas we highlighted tend to have drug crimes occur at the right time of day, so we are extrapolating that during the school year this trend would continue.
It is also important to note that this is data of active police activity (ie arrests, citations). This means it is not a comprehensive dataset of where crime occurs. This is data about where the SFPD is arresting people. This is an important distinction to keep in mind. An increase in the number of arrests in a certain area may very well be a very good thing indicating that the police are focusing on certain problematic areas, not necessarily that actual crime in those areas is on the rise.
The video, images, and reports in this post were created with publicly accessible data. We have no association with the San Francisco police department (but we’d love to, so contact us if you’re from the SFPD and want to use SpatialKey).