Shapefile导入PostGIS会生成Django日期时间错误

时间:2018-08-07 10:15:18

标签: django shapefile qgis geodjango

嗨,我正在尝试使用Shapefile填充Django应用程序的PostGIS数据库。我的models.py如下:

class Flow(models.Model):
    # Primary key
    flow_id = models.AutoField("ID, flow identifier", primary_key=True)

    # Other attributes
    stime = models.DateTimeField("Start time")
    stime_bc = models.IntegerField("Year of start time before Christ")
    stime_unc = models.DateTimeField("Start time uncertainty")
    etime = models.DateTimeField("End time")
    etime_bc = models.IntegerField("Year of end time before Christ")
    etime_unc = models.DateTimeField("End time uncertainty")
    final_vers = models.BooleanField("1 if it's the final version, else 0",
                                default=False)
    com = models.CharField("Comments", max_length=255)
    loaddate = models.DateTimeField("Load date, the date the data was entered "
                            "(in UTC)")
    pubdate = models.DateTimeField("Publish date, the date the data become "
                           "public")
    cb_ids = models.ManyToManyField(Bibliographic)

    # Foreign key(s)
    fissure_id = models.ForeignKey(Fissure, null=True,
                           related_name='flow_fissure_id',
                           on_delete=models.CASCADE)
    cc_load_id = models.ForeignKey(Contact, null=True,
                           related_name='flow_cc_id_load',
                           on_delete=models.CASCADE)
    cc_pub_id = models.ForeignKey(Contact, null=True,
                          related_name='flow_cc_id_pub',
                          on_delete=models.CASCADE)

    # Override default table name
    class Meta:
        db_table = 'flow'

我想将coulees.shp Shapefile的功能添加到数据库中(更精确地在流表中)。属性表如下所示:

Atribute table

为此,我使用Django图层映射:

import os
from django.contrib.gis.utils import LayerMapping
from .models import Flow

mapping = {'stime':'stime', 'stime_bc':'stime_bc', 'stime_unc':'stime_unc',  'etime':'etime', 'etime_bc':'etime_bc', 'etime_unc':'etime_unc', 'com':'com', 'loaddate':'loaddate', 'pubdate':'pubdate', 'geometry':'geometry'}

shp = os.path.abspath(
    os.path.join(os.path.dirname(__file__), 'data', '/home/sysop/Coulees/coulees.shp')
)


def run(verbose=True):
    lm = LayerMapping(
        Flow, shp, mapping,
        transform=True
    )
    lm.save(verbose=True)

但是当我尝试运行此功能时,出现以下错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/mapobs/mapobs/app/load.py", line 30, in run
    transform=True
  File "/opt/mapobs/lib/python3.5/site-packages/django/contrib/gis/utils      /layermapping.py", line 106, in __init__
    self.check_layer()
  File "/opt/mapobs/lib/python3.5/site-packages/django/contrib/gis/utils/layermapping.py", line 256, in check_layer
    (ogr_field, ogr_field.__name__, fld_name))
django.contrib.gis.utils.layermapping.LayerMapError: OGR field "<class     'django.contrib.gis.gdal.field.OFTDate'>" (of type OFTDate) cannot be mapped to Django   DateTimeField.

不幸的是,我在互联网上找不到任何有用的文档。

0 个答案:

没有答案
相关问题