I have some existing tables (shapefiles) and I want to connect each table with a django model. I imported the tables with shp2pgsql tool:
shp2pgsql -I -s 2100 -W 'iso-8859-7' world.shp public.world | psql -h localhost -d django_db -U django_user
Then I ran:
python manage.py inspectdb
and I copied the model of that table in my models.py :
class World(models.Model):
aa = models.IntegerField()
yparith = models.CharField(max_length=254)
name = models.CharField(max_length=100)
dep = models.CharField(max_length=50)
arfakellou = models.CharField(max_length=50)
sxolia = models.CharField(max_length=250)
parakatath = models.CharField(max_length=250)
yp = models.CharField(max_length=20)
geom = models.MultiLineStringField(srid=2100)
objects = models.GeoManager()
class Meta:
managed = True
db_table = 'geoloc_world'
def __str__(self):
return self.name
def __unicode__(self):
return self.name
After that I ran:
python manage.py makemigrations
python manage.py migrate
Then when in django shell I type:
World.objects.all()
the output is an empty list.
I tried to use LayerMapping data import utility but it raises the following error:
LayerMapError: Could not retrieve geometry from feature.
My load.py:
import os
from django.contrib.gis.utils import LayerMapping
from .models import World
geoloc_mapping = {
'aa' : 'aa',
'yparith' : 'YpArith',
'name' : 'Name',
'dep' : 'Dep',
'arfakellou' : 'ArFakellou',
'sxolia' : 'Sxolia',
'parakatath' : 'Parakatath',
'yp' : 'Yp',
'geom' : 'MULTILINESTRING',
}
geoloc_shp = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'data', 'world.shp'),
)
def run(verbose=True):
lm = LayerMapping(
World, geoloc_shp,
geoloc_mapping, transform=False,
encoding='iso-8859-7',
)
lm.save(strict=True, verbose=verbose)
Any suggestions ?