Visualizing SFPD’s “Operation Safe Schools”

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.

Data sources

Both the crime data and the school locations were downloaded from San Francisco’s new data warehousing website: 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

spatialkey_sfpd_crime_thumb1We 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

spatialkey_sfpd_crime_thumb3We 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

spatialkey_sfpd_crime_thumb4Since 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

spatialkey_sfpd_crime_thumb5Then 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

spatialkey_sfpd_crime_thumb6The 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).

12 thoughts on “Visualizing SFPD’s “Operation Safe Schools”

  1. Pingback: New SpatialKey Crime Example for San Francisco | Doug McCune

  2. Pingback: Mapping Saturn and GM Dealerships – Service is Still Nearby | SpatialKey blog

  3. You missed many of the cocaine, meth, heroin crimes when you selected them in the video.

    What you need is a text filter which you can apply to the descriptions. Selecting by hand (like you did) is slow and error-prone.

  4. Pingback: Opera Husband » Visualizing SFPD’s “Operation Safe Schools” | SpatialKey blog

  5. Regarding missing some of the crimes, we actually didn’t miss any of the sales of crack (cocaine base), meth, or heroin. The ones that you see that we didn’t select may have been possession offenses (we were only interested in sales) or cocaine offenses (as opposed to crack).

    Additionally, we do have text filters that you can use to type in valid values, although I wouldn’t argue that that would be more accurate than selecting them individually from the list in our example (this would entirely depend on the type and volume of data).

  6. Pingback: RSS For Gadgets » San Francisco’s open for data

  7. Pingback: San Francisco’s open for data | Pj News| Latest Daily News About World News, Business, Tech and Entertainment

  8. Pingback: Harnessing the power of City data with SpatialKey | SpatialKey blog

  9. Pingback: | Westminster Blog | The Steve Hilton Strategy Bulletins

  10. Pingback: SpatialKey Launched! « Blog

  11. Pingback: San Francisco, the city that’s open for data | Richard Hartley

Leave a Reply

Your email address will not be published. Required fields are marked *