Skip to content

Commit

Permalink
markers generated with easting northing
Browse files Browse the repository at this point in the history
  • Loading branch information
shearn89 committed Oct 9, 2011
1 parent de204c3 commit 3297ebf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
20 changes: 13 additions & 7 deletions main.rb
@@ -1,6 +1,7 @@
require 'rubygems'
require 'sinatra'
require 'sequel'
require 'rubypython'

# set :database => 'mysql://appathon:appathon@appathon.cdmwtnbgpare.eu-west-1.rds.amazonaws.com:3306/appathon'
# DB = Sequel.mysql 'appathon', :user => 'appathon', :password => 'appathon', :host => 'mysql://appathon.cdmwtnbgpare.eu-west-1.rds.amazonaws.com', :port => '3306'
Expand All @@ -12,14 +13,19 @@
end

def get_crimes_and_format
rows = DB.fetch("SELECT * FROM street_crime WHERE MBRContains(GeomFromText('Polygon((359825.0 170625.0,359827 170625,359827 170627,359825 170627,359825 170625))'), ukos);")
@string = '["'
rows.each{ |row| @string << row[:easting].to_s+','+row[:northing].to_s+'","' }
@string << rows.first[:easting].to_s+','+rows.first[:northing].to_s+'"]'
puts @string
return @string
# location = ??
# polygon = "GeomFromtext('Polygon((#{location[x]-100} #{location[y]-100},#{location[x]+100} #{location[y]-100},#{location[x]+100} #{location[y]+100},#{location[x]-100} #{location[y]+100},#{location[x]-100} #{location[y]-100}))'"
rows = DB.fetch("SELECT * FROM street_crime WHERE MBRContains(GeomFromText('Polygon((359726 170526,359926 170526,359926 170726,359726 170726,359726 170526))'), ukos);")

myHash = {}
rows.each{ |row|
key = '"'+row[:easting].to_s+','+row[:northing].to_s + '"'
myHash[key].nil? ? myHash[key] = 1 : myHash[key] += 1
}
return myHash
end

get '/dbtest' do
get_crimes_and_format
@coords = get_crimes_and_format
erb :index
end
6 changes: 6 additions & 0 deletions utmToLatLong.py
@@ -1,4 +1,5 @@
import math
import sys

def utmToLatLng(zone, easting, northing, northernHemisphere=True):
if not northernHemisphere:
Expand Down Expand Up @@ -50,3 +51,8 @@ def utmToLatLng(zone, easting, northing, northernHemisphere=True):
longitude = ((zone > 0) and (6 * zone - 183.0) or 3.0) - _a3

return (latitude, longitude)

if __name__ == "__main__":
print float(sys.argv[2])
print float(sys.argv[3])
print utmToLatLng(sys.argv[1], float(sys.argv[2]), float(sys.argv[3]))
5 changes: 3 additions & 2 deletions views/layout.erb
Expand Up @@ -45,10 +45,11 @@ function initialize() {
map.setCenter(pos);

// ADD MARKERS
<% @coords.each do |point| %>
<% @coords.each do |k,v| %>
marker = new google.maps.Marker({
position: new google.maps.LatLng(<%= point %>),
position: new google.maps.LatLng(<%= k %>),
map: map,
title: <%= '"'+ v.to_s + ' crimes"'%>
});
<% end %>

Expand Down

0 comments on commit 3297ebf

Please sign in to comment.