This is a continuation of a project that was started at a Data Jam session at the 2018 National Planning Conference in New Orleans, where the main topic was climate change and stormwater management in New Orleans. This is the main software repository for that DataJam.
The project is written in GeoDjango, a geospatial extension to the Django web framework.
Create a virtual environment using your preferred method. There is a Pipfile
, so if you have pipenv installed, you could do:
$ pipenv --three
$ pipenv install
to create and activate a virtual environment and install required Python packages. Most shell commands listed in this README from here on assume you have the virtual environment activated and all dependencies successfully installed.
The project uses PostGIS as the database. Installing PostGIS locally can be tricky, but if you have Docker installed and running, you can start a PostGIS container:
$ docker run --name nola-postgis \
-e POSTGRES_USER=nola \
-e POSTGRES_DATABASE=nola \
-e POSTGRES_PASSWORD=nola \
-p 5432:5432 \
mdillon/postgis:10
If all goes well, you should have a PostGIS instance accessible on your localhost
at port 5432 and should be able to connect to it with the parameters specified above. These are also the default in flood_impact/settings.py
, so you now should be able to run database migrations. Change into the flood_impact
directory and type:
$ python manage.py migrate
The project requires several datasets from NOLA Open Data, specifically:
The project includes an app called etl
that should handle this for you (please open an issue if it does not!). This will eventually be turned into a Django management command, but until then you'll have to do it from an interactive shell:
$ python manage.py shell
>>> from myimpact.load import load_all
>>> load_all()
It could take several minutes to finish, depending on your internet connection speed and computer processing power.
If you are re-running the data load you will need to purge the db first:
>>> from myimpact.models import *
>>> SiteAddressPoint.objects.all().delete()
>>> BuildingFootprint.objects.all().delete()
>>> Parcel.objects.all().delete()
>>> ZoningDistrict.objects.all().delete()
TODO: write more of these - Not currently functional. Uses outdated endpoints.
$ python manage.py test
$ python manage.py runserver
You should now be able to access the proof-of-concept web form at http://localhost:8000/myimpact/ . That is the default, but you could change port or IP binding. For example, if you wanted to make it available to any device on your network on port 8181:
$ python manage.py runserver 0.0.0.0:8181
- Nov. 2024: Django and all packages updated. ETL changed to accomodate new nola.gov format (csv, no longer offering shapefiles).
- The autocomplete address dropdown datalist that suggests addresses as the user types could use some performance optimization. It uses the
full_address
field on theSiteAddressPoint
model, which contains condominium units, if present, in one building. Those are unnecessary given that we only need the parcel and the building footprint. Using a combination of theaddress_number
andfull_name
fields would reduce the amount of rows the ORM has to search with PostgreSQL full text search
- The address entered in the search form must be an exact match to a
full_address
value inSiteAddressPoint
- there is no fuzzy string matching or ranking. That is one reason for the autosuggset drop down. A user could enter a valid address, but if thefull_address
has "South" for an address direction and the user simply enters "S" it would not match - Speaking of, the front-end currently does not display any error message if there is no exact match, it simply does nothing.
- CSRF protection was disabled on the view for
/myimpact/address
, as Django was occasionally not setting adocument.cookie
during development, making it impossible to include a CSRF token with thePOST
request. - The Mapbox access token is exposed. It's a public, read-only token associated with an account on the free tier, limited to 50,000 views per month
- Speaking of security, it is highly recommended to go through the Django deployment checklist before even considering deploying this on a public-facing site.