London Drug Map

A look into open data about crime and policing in England.
londondrugs banner
Found at I downloaded a date range from 2011 through 2016, ~5 years. The uncompressed filesize for all select-able policing forces was approximately 5.45 GB. A quick C# script was written to filter out only the “Drug” crime type category, and it’s long/lat degree coordinates.

The output was used to make the map below. Click map for larger size.


1more londonmap

The downloadable data comes in a multi-directory/multi-file structure. Below is a c# console application which was created to parse the root folder, and export the specific crime type’s coordinates throughout out all the files.

Console.BufferHeight = 4000;
string dirPath = @"C:\LONDON3\";
List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
Dictionary<string, int> dictUniqueCrime = new Dictionary<string, int>();
string OUTPUTFILE = "date, longitude, latitude\r\n";
foreach (var dir in dirs)
    Console.WriteLine("{0}", dir.Substring(dir.LastIndexOf("\\") + 1));
    string filepath = @"C:\LONDON3\";
        filepath += dir.Substring(dir.LastIndexOf("\\") + 1);
    string line;
    string[] fileEntries = Directory.GetFiles(filepath);
    foreach (string fileName in fileEntries)
        System.IO.StreamReader file =
            new System.IO.StreamReader(fileName);
        while ((line = file.ReadLine()) != null)
            string[] parts = line.Split(',');
            //crime id
            string month = parts[1];
            //reported by
            //falls by
            string longitude = parts[4];
            string latitude = parts[5];
            //crime type
            //Console.WriteLine("crime type ::::;  "  + parts[9]);
            string crimetype = parts[9];
            // Console.WriteLine(parts[10]);
            if (crimetype == "Drugs")
                if ( dictUniqueCrime.ContainsKey(crimetype) )
                    int existing = dictUniqueCrime[crimetype];
                    existing += 1;
                    dictUniqueCrime[crimetype] = existing;
                    dictUniqueCrime.Add(crimetype, 1);
                string lines =  month + ", " + longitude + ", " + latitude+"\r\n";
                System.IO.StreamWriter file1 = new System.IO.StreamWriter("C:\\Airplanes\\____2011-2016ALL UK DRUGS.csv", true);
var items = from pair in dictUniqueCrime
            orderby pair.Value ascending
            select pair;
foreach (KeyValuePair<string, int> pair in items)
    Console.WriteLine("{0}: {1}", pair.Key, pair.Value);

Leave a Reply

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