Importing GeoPt data with the Google AppEngine BulkLoader YAML

对着背影说爱祢 提交于 2019-12-12 09:03:01

问题


I am uploading data from a csv file with a GeoPt column in it. I have the GeoPt column data in quotes like this: SomeData,"54.321,-123.456",MoreData

My bulkloader.yaml file has an entry like this: - property: location external_name: LOCATION # Type: GeoPt Stats: 1 properties of this type in this kind.

When I do the upload and go to the DataStore viewer I see the location has been uploaded as a string instead of a GeoPt. I'm not sure what the proper way to import this would be. Perhaps it requires an import_transform?


回答1:


Create a uploadutil.py file and add this method in it:

def geo_converter(geo_str):
    if geo_str:
        lat, lng = geo_str.split(',')
        return db.GeoPt(lat=float(lat), lon=float(lng))
    return None

Then add this in bulkloader.yaml:

Add import for uploadutil:

- import: uploadutil

And add property:

- property: location
      external_name: LOCATION
      import_transform: uploadutil.geo_converter



回答2:


If you get NameError global name 'db' is not defined while uploading data, add line

 from google.appengine.ext import db

to file uploadutil.py



来源:https://stackoverflow.com/questions/3350193/importing-geopt-data-with-the-google-appengine-bulkloader-yaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!