AppEngine GeoPt Data Upload

Posted by Eric Landry on Stack Overflow See other posts from Stack Overflow or by Eric Landry
Published on 2009-10-19T13:21:25Z Indexed on 2010/12/21 23:54 UTC
Read the original article Hit count: 197

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine