-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocationGenerator.py
More file actions
111 lines (102 loc) · 3.88 KB
/
LocationGenerator.py
File metadata and controls
111 lines (102 loc) · 3.88 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
##
# LocationGenerator.py -
#
# Module for generating psuedo "longitude" and "latitude" data pairs.
#
# XXX: change to actual latitude/longitude points.
# XXX: import actual city map and snap to intersections.
# This module generates points between the max/min long/lat values, at
# integer increments. We probably want to generate something to 4 decimal
# points (scale of meters).
#
# see:
# http://en.wikipedia.org/wiki/Decimal_degrees
#
##
import os
import sys
from random import randint
from TripCommon import *
class LocationGenerator:
'''
Module for generating psuedo longitude and latitude data pairs.
'''
def __init__(self, testQuadrant=None):
self.lastX = None
self.lastY = None
global g_minLatitude
global g_maxLatitude
global g_minLongitude
global g_maxLongitude
self.minLatitude = g_minLatitude
self.maxLatitude = g_maxLatitude
self.minLongitude = g_minLongitude
self.maxLongitude = g_maxLongitude
if testQuadrant is not None:
if testQuadrant == TOP_LEFT:
self.minLatitude = -72
self.maxLatitude = -1
self.minLongitude = 36
self.maxLongitude = 143
elif testQuadrant == TOP_RIGHT:
self.minLatitude = 18
self.maxLatitude = 71
self.minLongitude = 36
self.maxLongitude = 143
elif testQuadrant == BOTTOM_RIGHT:
self.minLatitude = 18
self.maxLatitude = 71
self.minLongitude = -144
self.maxLongitude = -1
elif testQuadrant == BOTTOM_LEFT:
self.minLatitude = -72
self.maxLatitude = -1
self.minLongitude = -144
self.maxLongitude = -1
elif testQuadrant == LEFT_EDGE:
self.minLatitude = -90
self.maxLatitude = -90
self.minLongitude = -144
self.maxLongitude = 143
elif testQuadrant == TOP_EDGE:
self.minLatitude = -72
self.maxLatitude = 71
self.minLongitude = 180
self.maxLongitude = 180
elif testQuadrant == RIGHT_EDGE:
self.minLatitude = 90
self.maxLatitude = 90
self.minLongitude = -144
self.maxLongitude = 143
elif testQuadrant == BOTTOM_EDGE:
self.minLatitude = -72
self.maxLatitude = 71
self.minLongitude = -180
self.maxLongitude = -180
else:
raise Exception("Unknown Test Quadrant:", testQuadrant)
def getNext(self):
if self.lastX is None or self.lastY is None:
self.lastX = randint(self.minLatitude, self.maxLatitude)
self.lastY = randint(self.minLongitude, self.maxLongitude)
return (self.lastX, self.lastY)
else:
xMove = randint(-g_maxDelta, g_maxDelta)
# cap the X new value
if self.minLatitude <= (self.lastX + xMove) <= self.maxLatitude:
newX = self.lastX + xMove
elif self.minLatitude >= (self.lastX + xMove):
newX = self.minLatitude
else:
newX = self.maxLatitude
yMove = randint(-g_maxDelta, g_maxDelta)
# cap the Y new value
if self.minLongitude <= (self.lastY + yMove) <= self.maxLongitude:
newY = self.lastY + yMove
elif self.minLongitude >= (self.lastY + yMove):
newY = self.minLongitude
else:
newY = self.maxLongitude
checkLocation((newX, newY))
return (newX, newY)