User:Jules/pymongo

From XPUB & Lens-Based wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
import pymongo, sys
from math import sqrt
from pymongo import MongoClient
client = MongoClient()
#client = MongoClient('localhost',27017)

db = client.poetic_geoips
collection = db.ips

#precision
thresh = 0.00001

keep = []

a = 1
b = 2
c = 0

bot = sqrt(a*a + b*b)
for d in collection.find():
	lat,lon = d['coordinates']
	ip = d['ip']
	# print >> sys.stderr, "lat,lon", lat, lon
	top = abs((a*lat)+(b*lon)+c)
	dist = top / bot
	if (abs(dist) < thresh) and lat != 0.0 and lon != 0.0:
		print >> sys.stderr, "hit", lat, lon, ip


As a result for a diagonal such as:
abs((1*lat)+(2*lon)+1)
with thresh = 0.001


Result.png