Importing GeoPt data with the Google AppEngine BulkLoader YAML
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 ha开发者_Python百科s 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?
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
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
精彩评论