GAE中GAE中GAE模型的空边界框结果

2024-06-08 08:16:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在GAE中使用python中的geomodel来获取边界框。我的理解是定义一个框,然后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] Box created with N:56.497527 E:-3.214624 S:54.497527, W:-3.014624

数据存储中的条目包括: {“venueLat”:55.9570323,“venueCity”:“Edinburgh”,“venueZip”:“EH1 3AA”,“venueLong”:-3.1850223,“venueName”:“爱丁堡剧场”,“venueState”:,“venueCountry”:“UK”} 和 {“venueLat”:55.9466506,“venueCity”:“Edinburgh”,“venueZip”:“EH8 9FT”,“venueLong”:-3.1863224,“venueName”:“Edinburgh艺术节剧院”,“venueState”:,“venueCountry”:“UK”}

这两种方法的位置都在上面定义的边界框内。我已经打开了调试,并且边界框获取似乎确实在搜索geocells,因为我得到的输出如下所示:

INFO 2011-07-19 20:47:09,487 geomodel.py:114] bbox query looked in 4 geocells

然而,似乎没有任何结果得到回报。我已经确保为所有模型运行update_location(),以确保底层geocell数据是正确的。有人有什么想法吗?在

谢谢


Tags: selfbox定义fetchfloatqueryresults边界
1条回答
网友
1楼 · 发布于 2024-06-08 08:16:00

要添加到数据库的代码-

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()

搜索附近对象的代码

^{pr2}$

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

相关问题 更多 >