-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompute_bounding_boxes.py
More file actions
34 lines (32 loc) · 1.15 KB
/
compute_bounding_boxes.py
File metadata and controls
34 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
class Bounds:
def __init__(self):
self.latmin = None
self.latmax = None
self.lonmin = None
self.lonmax = None
def extend(self,path):
for pt in path:
if self.latmin == None:
self.latmin = pt[0]
self.latmax = pt[0]
self.lonmin = pt[1]
self.lonmax = pt[1]
else:
if pt[0]<self.latmin:
self.latmin = pt[0]
if pt[0]>self.latmax:
self.latmax = pt[0]
if pt[1]<self.lonmin:
self.lonmin = pt[1]
if pt[1]>self.lonmax:
self.lonmax = pt[1]
import pymongo
collection = pymongo.MongoClient().wwsupdb.rivers_merged2
for river in collection.find():
if river.has_key('osm') and river['osm'].has_key('paths') and len(river['osm']['paths'])>0:
bounds = Bounds()
for path in river['osm']['paths']:
bounds.extend(path)
b = [bounds.latmin,bounds.latmax,bounds.lonmin,bounds.lonmax]
collection.update({'_id':river['_id']},{"$set":{'osm.bounds':b}})