在GAE中使用geomodel的空边界框结果

时间:2011-07-19 20:54:22

标签: python google-app-engine geohashing

我正在尝试使用python中的geomodel在GAE中进行边界框提取。我理解你定义一个框,然后geomodel fetch将返回所有结果,其中坐标位于此框内。我正在输入GPS纬度和经度(55.497527,-3.114624),然后在这个坐标的给定范围内建立一个N,S,E,W的边界框,如下所示:

latRange = 1.0
longRange = 0.10
provlat = float(self.request.get('latitude'))
provlon = float(self.request.get('longitude'))
logging.info("Doing proximity lookup")
theBox = geotypes.Box(provlat+latRange, provlon-longRange, provlat-latRange, provlon+longRange)
logging.info("Box created with N:%f E:%f S:%f, W:%f" % (theBox.north, theBox.east, theBox.south, theBox.west))
query = GeoVenue.all().filter('Country =', provcountry)
results = GeoVenue.bounding_box_fetch(query, theBox, max_results=10)
if (len(results) == 0):
    jsonencode = json.dumps([{"error":"no results"}])
    self.response.out.write(jsonencode)
    return;
...

这总是返回一个空的结果集,即使我知道有一个事实,结果在框记录输出中指定的范围内:

  

INFO 2011-07-19 20:45:41,129 main.py:117]用N创建的框:56.497527 E:-3.214624 S:54.497527,W:-3.014624

我的数据存储区中的条目包括: {“venueLat”:55.9570323,“venueCity”:“Edinburgh”,“venueZip”:“EH1 3AA”,“venueLong”:-3.1850223,“venueName”:“Edinburgh Playhouse”,“venueState”:“”,“venueCountry” :“英国”} 和 {“venueLat”:55.9466506,“venueCity”:“Edinburgh”,“venueZip”:“EH8 9FT”,“venueLong”:-3.1863224,“venueName”:“Festival Theater Edinburgh”,“venueState”:“”,“venueCountry” “:”英国“}

其中两个肯定都有位于上面定义的边界框内的位置。我打开了调试,并且边界框fetch似乎确实搜索了geocells,因为我得到了以下行的输出:

  

INFO 2011-07-19 20:47:09,487 geomodel.py:114] bbox查询查看了4个地理单元

然而,似乎没有结果返回。我确保为所有模型运​​行update_location()以确保底层地理单元数据是正确的。有没有人有任何想法?

由于

1 个答案:

答案 0 :(得分:0)

要添加到数据库的代码 -

from google.appengine.ext import db
from models.place import Place

place = Place(location=db.GeoPt(LAT, LON)) # location is a required field 
                                           # LAT, LON are floats
place.state = "New York"
place.zip_code = 10003
#... set other fields
place.update_location() # This is required even when 
                        # you are creating the object and 
                        # not just when you are changing it
place.put()

搜索附近对象的代码

base_query = Place.all() # apply appropriate filters if needed
center = geotypes.Point(float(40.658895),float(-74.042760))
max_results = 50
max_distance = 8000

results = Place.proximity_fetch(base_query, center, max_results=max_results,
                                max_distance=max_distance)

它也应该与边界框查询一起使用,只需记住在将对象添加到数据库之前调用update_location。