【问题标题】:Importing GeoPt data with the Google AppEngine BulkLoader YAML使用 Google AppEngine BulkLoader YAML 导入 GeoPt 数据
【发布时间】:2010-07-28 05:40:53
【问题描述】:

我正在从包含 GeoPt 列的 csv 文件上传数据。我有这样的引号中的 GeoPt 列数据:SomeData,"54.321,-123.456",MoreData

我的 bulkloader.yaml 文件有一个这样的条目: - 属性:位置 外部名称:位置 # 类型:GeoPt Stats:该类型中的 1 个属性。

当我进行上传并转到 DataStore 查看器时,我看到该位置已作为字符串而不是 GeoPt 上传。我不确定导入它的正确方法是什么。也许它需要一个 import_transform?

【问题讨论】:

    标签: google-cloud-datastore


    【解决方案1】:

    创建一个uploadutil.py 文件并在其中添加此方法:

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

    然后将这个添加到bulkloader.yaml:

    为 uploadutil 添加导入:

    - import: uploadutil
    

    并添加属性:

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

    【讨论】:

      【解决方案2】:

      如果在上传数据时收到NameError global name 'db' is not defined,请添加行

       from google.appengine.ext import db
      

      到文件uploadutil.py

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-14
        • 1970-01-01
        相关资源
        最近更新 更多