class BuildingAddress(models.Model):
id = models.CharField(max_length=12,primary_key = True)
address = models.CharField(max_length=30)
city = models.CharField(max_length=30)
zip = models.CharField(max_length=10)
state = models.CharField(max_length=2)
primpgon = models.BigIntegerField()
numpgons = models.BigIntegerField()
x = models.FloatField()
y = models.FloatField()
censusbloc = models.CharField(max_length=15)
objectid = models.BigIntegerField()
geom = models.MultiPolygonField(srid=4326)
然后我尝试将我的形状文件导入此模型。我写了下面的剧本。
import os
from django.contrib.gis.utils import LayerMapping
from .models import BuildingAddress
no_address_mapping = {
'id' : 'ID',
'address' : 'Address',
'city' : 'City',
'zip' : 'ZIP',
'state' : 'State',
'primpgon' : 'PrimPgon',
'numpgons' : 'NumPgons',
'x' : 'X',
'y' : 'Y',
'censusbloc' : 'CensusBloc',
'objectid' : 'ObjectID',
}
no_address_shp = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'building/WestDV_CA_BF_NoAddress_region.shp'))
def run(verbose=True):
lm = LayerMapping(
BuildingAddress, no_address_shp, no_address_mapping,
transform=False, encoding='iso-8859-1')
lm.save(strict=True, verbose=verbose)
然后我在shell中运行这个文件。
当我尝试运行此文件时,我收到django.core.exceptions.FieldDoesNotExist: BuildingAddress has no field named 'False'
错误。我不明白为什么会发生这种错误。我没有创建任何字段名称为False。但它会抛出Field名称false不存在。
答案 0 :(得分:0)
您没有将映射添加到geom
字段中。假设您要在其中映射一些多面几何,则映射字典应如下所示:
no_address_mapping = {
'id' : 'ID',
'address' : 'Address',
'city' : 'City',
'zip' : 'ZIP',
'state' : 'State',
'primpgon' : 'PrimPgon',
'numpgons' : 'NumPgons',
'x' : 'X',
'y' : 'Y',
'censusbloc' : 'CensusBloc',
'objectid' : 'ObjectID',
'geom': 'MULTIPOLYGON'
}