Data of crimes in Vancouver (Canada) from 2003 to 2017 Columns:
- TYPE - Type of Crime - string
- YEAR - Year when the reported crime activity occurred - numeric
- MONTH - Month when the reported crime activity occurred - numeric
- DAY - Day when the reported crime activity occurred - numeric
- HOUR - Hour when the reported crime activity occurred - numeric
- MINUTE - Minute when the reported crime activity occurred - numeric
- HUNDRED_BLOCK - Generalized location of the report crime activity - numeric
- NEIGHBOURHOOD - Neighbourhood where the reported crime activity occurred - numeric
- X - Coordinate values projected in UTM Zone 10 - numeric
- Y - Coordinate values projected in UTM Zone 10 - numeric
- Latitude - Coordinate values converted to Latitude - numeric
- Longitude - Coordinate values converted to Longitude - numeric
TYPE | YEAR | MONTH | DAY | HOUR | MINUTE | HUNDRED_BLOCK | NEIGHBOURHOOD | X | Y | Latitude | Longitude |
---|---|---|---|---|---|---|---|---|---|---|---|
Other Theft | 2003 | 5 | 12 | 16 | 15 | 9XX TERMINAL AVE | Strathcona | 493906.5 | 5457452.47 | 49.26980201 | -123.0837633 |
Other Theft | 2003 | 5 | 7 | 15 | 20 | 9XX TERMINAL AVE | Strathcona | 493906.5 | 5457452.47 | 49.26980201 | -123.0837633 |
./generowanie_json.sh
./importowanie.sh
./ustaw_baze.rb
Tworzy geo_indeks potrzebny do skryptu punkty_w_okolicy.rb
coll.indexes.create_one( { "location"=> "2dsphere" } )
./pokoloruj.rb
Użytkownik podaje typ przestępstwa i kolor na jaki mają być pokolorowane punkty na mapie oznaczające dane przestępstwo
Przykładowy pokolorowany geojson
./punkty_w_okolicy.rb
Pobiera długosc i szerokość geograficzną od użytkownika i liczy ilość zbrodni w okolicy ("$minDistance" : 1000, "$maxDistance" : 5000). Następnie skrypt pyta użytkownika czy zapisac w kolekcji crime_export wyszukane zbrodnie.
matched_crime = coll.find(
{
"location"=>
{ "$near"=>
{
"$geometry"=> { "type"=> "Point", "coordinates"=> [ longitude_to_search.to_f, latitude_to_search.to_f ] },
"$minDistance"=> 1000,
"$maxDistance"=> 5000
}
}
}
).limit(200).to_a
./centroid_crime.rb
Pobiera typ zbrodni i liczy centroide danego typu przestępstwa. Następnie wynik zapisuję w kolekcji.
ag = coll.aggregate([
{"$match"=> {"properties.type_of_crime": type_to_search}},
{"$replaceRoot"=> { newRoot: "$location" }},
{"$project"=> { "type": 1, szerokosc: { "$arrayElemAt"=> [ "$coordinates", 0 ] },dlugosc: { "$arrayElemAt"=> [ "$coordinates", -1 ] }}},
{"$group"=> { _id: type_to_search ,srednia_szerokosc: { "$avg" => "$szerokosc"}, srednia_dlugosc: { "$avg"=> "$dlugosc"} } }
] )
./policz_w_miesiacu.rb
Pobiera rok i miesiąc od użytkownika a następnie wyświetla ilość zarejestrowanych przestępstw w wybranym czasie.
all_chosen_crimes = coll.find({ "properties.year"=> year_to_search.to_i,
"properties.month"=> month_to_search.to_i })
puts all_crimes.group_by{|e| e}.map{|k, v| [k, v.length]}.to_h
./export_geojson.sh
Utworzony zostaje plik crime.geojson