AppEngine GeoPt Data Upload

csv, google-app-engine, python, upload

Solution

Ok, I got my answer from Google Groups (thanks Takashi Matsuo and Mike Armstrong). The solution is to modify my CSV file and combine lat and lng in a double-quoted string. The comma within the double-quoted string will not be counted as a CSV delimiter.

POSTAL_CODE_ID,PostalCode,City,Province,ProvinceCode,CityType,Point
1,A0E 2Z0,Monkstown,Newfoundland,NL,D,"47.150300000000001,-55.299500000000002"

Also, here is my new loader.py. Note that the GeoPtProperty takes a string with "00.0000,00.0000":

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()
  geo_pt = db.GeoPtProperty()

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),
                                ('geo_pt', str)
                               ])

loaders = [PostalCodeLoader]

Problem

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.

Original source