Skip to main content

Django APP to automate GeoDjango shapefile importations and management without affecting migrations.

Project description

# Django-shapefileimport

GeoDjango includes a helper function to import ESRI shapefiles to PostGIS enabled DB: [LayerMapping] It works as intended but it’s still a boring process. Moreover, the usual importing procedure means creating new migrations for each imported shapefile. This is problably OK for sparse importings of a couple of shapefiles. But as I needed to manage many shapefiles and/or keep adding/deleting them it doesn’t sounded to me very sane to keep afecting migration files (and migration history). This APP proposes an alternative to manage such shapefiles: - Adds shapefile ZIP import option in admin page. Imports will include feature fields. - Loads shapefiles by name on demand without touching migrations (so you can use all nice GeoDjango API features) - Delete shapefiles from admin panel - Option to keep or discard uploaded ZIP files while importing to DB

## Installation Clone this repo: `sh git clone https://github.com/Rodrigo-NH/django-shapefileimport ` Enter the ‘django-shapefileimport’ directory, install de dependencies, enter shell and start a new project (For simplicity I reccomend keeping the ending dot at the django-admin startproject command, it makes project folder to be created at same level as the APP [not nested]) `sh pipenv install pipenv shell django-admin startproject mysite . ` edit ‘./mysite/settings.py’ and add to INSTALLED_APPS: `sh 'django.contrib.gis', 'shapefileimport' ` Still at ‘./mysite/settings.py’, configure the database connection: `py DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'shapeimportsDB', 'USER': 'geo', 'HOST': '192.168.0.40', 'PORT': '5432', 'PASSWORD': 'dbpassword', #'CONN_MAX_AGE': 0, }, } ` Run migrations, create superuser and start the APP: `sh python manage.py makemigrations python manage.py migrate python manage.py createsuperuser python manage.py runserver ` It must be done at this point. Enter admin panel and start importing your shapefiles. After importing, use ‘loadShape()’ function to load the shapefile and use. Example: `sh from shapefileimport.shapetasks import loadShape from django.core.serializers import serialize ds = loadShape('MyShapeName') ff = serialize('geojson', ds.objects.all(), geometry_field='geom',) `

## Notes - You must have a propper GeoDjango setup environment, refer to https://docs.djangoproject.com/en/3.2/ref/contrib/gis/ - You must have PostGIS enabled, refer to https://postgis.net/install/ - This APP uses GeoDjango’s LayerMapping helper to extract fields among other operations - Only tested against PostreSQL

[LayerMapping]: https://docs.djangoproject.com/en/3.2/ref/contrib/gis/layermapping/

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-shapefileimport-1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

django_shapefileimport-1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file django-shapefileimport-1.0.tar.gz.

File metadata

  • Download URL: django-shapefileimport-1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for django-shapefileimport-1.0.tar.gz
Algorithm Hash digest
SHA256 7838753de94bbed4c08f0e0919412998e6fb303312750b6481a9bcc244f9f98a
MD5 37881f1b3049ada7df0e59f44e66ea42
BLAKE2b-256 881d4eefe6e7ab25bf2029281d59bb39b54fcc888c37603aeeba51288c1e3a7e

See more details on using hashes here.

File details

Details for the file django_shapefileimport-1.0-py3-none-any.whl.

File metadata

  • Download URL: django_shapefileimport-1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for django_shapefileimport-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b07f0100b7f3bcdd93443165a600a9b8af243093688af8f5414f50ce79ef5e2a
MD5 e0b0c628cb2de7cba54adc78f7ebe3d3
BLAKE2b-256 c1b4472efcf186b144065468079753432ecd33392e6cc061c3a509bea657080b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page