AppEngine GeoPt Data Upload
- by Eric Landry
I'm writing a GAE app in Java and only using Python for the data
upload. I'm trying to import a CSV file that looks like this:
POSTAL_CODE_ID,PostalCode,City,Province,ProvinceCode,CityType,Latitude,Longitude
1,A0E2Z0,Monkstown,Newfoundland,NL,D,47.150300000000001,-55.299500000000002
I was able to import this file in my datastore if I import Latitude
and Longitude as floats, but I'm having trouble figuring out how to
import lat and lng as a GeoPt. Here is my loader.py file:
import datetime
from google.appengine.ext import db
from google.appengine.tools import bulkloader
class PostalCode(db.Model):
id = db.IntegerProperty()
postal_code = db.PostalAddressProperty()
city = db.StringProperty()
province = db.StringProperty()
province_code = db.StringProperty()
city_type = db.StringProperty()
lat = db.FloatProperty()
lng = db.FloatProperty()
class PostalCodeLoader(bulkloader.Loader):
def __init__(self):
bulkloader.Loader.__init__(self, 'PostalCode',
[('id', int),
('postal_code', str),
('city', str),
('province', str),
('province_code', str),
('city_type', str),
('lat', float),
('lng', float)
])
loaders = [PostalCodeLoader]
I think that the two db.FloatProperty() lines should be replaced with
a db.GeoPtProperty(), but that's where my trail ends. I'm very new to
Python so any help would be greatly appreciated.