0

我正在尝试使用 python 中的 geomodel 在 GAE 中获取边界框。我的理解是您定义了一个框,然后地理模型获取将返回所有结果,其坐标位于该框内。我目前正在输入 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”:“UK”} 和 {“venueLat”:55.9466506,“venueCity”:“爱丁堡”,“venueZip”:“EH8 9FT”,“venueLong”:-3.1863224,“venueName”:“Festival爱丁堡剧院”,“venueState”:“”,“venueCountry”:“UK”}

两者都绝对具有在上面定义的边界框内的位置。我已经打开了调试,并且边界框获取似乎确实搜索了地理单元,因为我得到了以下行的输出:

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

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

谢谢

4

1 回答 1

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 。

于 2011-12-03T04:11:35.903 回答