def getCountriesInViewPo rt self lat1 lng1 lat2 lng2 cond None limit 3

 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
def getCountriesInViewPort(
self, lat1, lng1, lat2, lng2, cond=None, limit=30,continent_id=None):
box = """if(x(startpoint(box)) < x(endpoint(box)),
PolyFromText(concat("Polygon((",
x(startpoint(box))," ",y(startpoint(box)),",",
x(startpoint(box))," ",y(endpoint(box)),",",
x(endpoint(box))," ",y(endpoint(box)),",",
x(endpoint(box))," ",y(startpoint(box)),",",
x(startpoint(box))," ",y(startpoint(box)),"))")),
PolyFromText(concat("Polygon((",
x(startpoint(box))," ",y(startpoint(box)),",",
x(startpoint(box))," ",y(endpoint(box)),",",
"180 ",y(endpoint(box)),",",
"180 ",y(startpoint(box)),",",
x(startpoint(box))," ",y(startpoint(box)),"))")))"""
# PolyFromText(concat("MultiPolygon(((",
# x(startpoint(box))," ",y(startpoint(box)),",",
# x(startpoint(box))," ",y(endpoint(box)),",",
# "180 ",y(endpoint(box)),",",
# "180 ",y(startpoint(box)),",",
# x(startpoint(box))," ",y(startpoint(box)),")),((",
# "-180 ",y(startpoint(box)),",",
# "-180 ",y(endpoint(box)),",",
# x(endpoint(box))," ",y(endpoint(box)),",",
## x(endpoint(box))," ",y(startpoint(box)),",",
# "-180 ",y(startpoint(box)),")))")))"""
if lng1 >= lng2:
condition = """Intersects(%(box)s, PolyFromText("Polygon((
%(lng1)s %(lat1)s,%(lng1)s %(lat2)s,%(lng2)s %(lat2)s,
%(lng2)s %(lat1)s,%(lng1)s %(lat1)s))"))""" %\
{"box":box,"lat1":lat1,"lng1":lng1,"lat2":lat2,"lng2":lng2}
else:
condition = """
Intersects(%(box)s, PolyFromText("Polygon((
%(lng1)s %(lat1)s,-180 %(lat1)s,
-180 %(lat2)s,%(lng1)s %(lat2)s,%(lng1)s %(lat1)s))")) or
Intersects(%(box)s, PolyFromText("Polygon((
180 %(lat1)s,%(lng2)s %(lat1)s,
%(lng2)s %(lat2)s,180 %(lat2)s,180 %(lat1)s))"))""" %\
{"box":box,"lat1":lat1,"lng1":lng1,"lat2":lat2,"lng2":lng2}
if continent_id:
if continent_id=="RU":
condition+=" AND (continent='%s' or ussr=1)" % continent_id
else:
condition+=" AND continent='%s'" % continent_id
if cond:
condition+=(" AND "+cond)
# use index(cities_trips_index)
countries = self.site.createStream(self.id, indexNum=0,
order=[("title_ru","ASC"),("title_en","ASC")])
countries.addToCondition(condition)
return countries