Professional Documents
Culture Documents
Grupo 3 BUILDING GEOSPATIAL WEB APPLICATIONS IN PYTHON VIA DJANGO FRAMEWORK
Grupo 3 BUILDING GEOSPATIAL WEB APPLICATIONS IN PYTHON VIA DJANGO FRAMEWORK
Open in app
Search
Get unlimited access to the best of Medium for less than $1/week. Become a member
Django
The web framework for perfectionists with deadlines.
docs.djangoproject.com
For this tutorial, I will be using Atom IDE to create a simple geospatial application
together with Python and the django web framework. You can access and
download the application here (check their official website for newer versions):
Atom
Download the latest version of Atom for Windows. The
comprehensive text editor for programmers, created by GitHub…
atom.en.uptodown.com
1 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
The link to the github repository with the whole code and data for this tutorial
can be accessed at. You may clone and impliment your functionalities too:
GitHub - KimutaiLawrence/Geodjangoapp
Contribute to KimutaiLawrence/Geodjangoapp development by
creating an account on GitHub.
github.com
Open your Anaconda prompt (terminal), go to where you want your project to be
created and install Django ,Folium and geopandas . This will first install the
necessary packages we will use. You then type “django-admin startproject geo”.
This will then start a project by creating a “geo” folder with all the necessary
things in it:
2 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
You can always check out what is contained within your directory by typing out
“dir” and we can see we have a geo folder created in our working directory:
geo folder
3 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
cd geo
We then type the following command which will then create another “geoApp”
folder with some components/ files including a “migrations” folder among
others(In Django, migrations are a way to manage changes to your database
schema over time. They allow you to evolve your database structure as you make
changes to your models without manually modifying the database.):
We then go ahead to create a new file called urls.py inside the geoApp and type
the following code:
urlpatterns = [
path('',views.home, name='home')
]
We then also go to the previous urls.py file in the main ‘geo’ folder and add the
following lines of code. Yes, there is some code in the file already provided for
you( NB: This is how weregister our “geoApp/urls.py” inside “geo/urls.py”):
urlpatterns = [
4 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
path("admin/", admin.site.urls),
path('', include('geoApp.urls')),#this line is what we add
]
We then create a templates folder inside the geoApp folder called “templates” and
another folder within the templates folder called “geoApp”, with where we will
place our html file.
We then go to the settings.py file, add some code and add some static files and
root as follows(note: there is already some code provided within the file):
import os
MEDIA_URL = "media/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static')
]
We save and then add 2 new folders to the root “static” and “media”
5 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
You then follow the following link to download important files with which you
will extract, then copy and paste boostrap and jquery folders into the static folder.
The files contain bootstrap and jquery files with which we will use :
geo.zip
Edit description
drive.google.com
https://github.com/KimutaiLawrence/Geodjangoapp/blob/master/geo.zip
We then go to setting.py and add our app otherwise django won’t recognize our
app is in the project:
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
6 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"geoApp",
]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(BASE_DIR, 'geoApp', 'templates')
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
7 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no
<meta name="description" content="">
<meta name="author" content="">
<title>GeospatialIntelligence</title>
.lead {
color: #FF3366; /* Custom color for lead text */
}
</style>
</head>
<body>
8 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
</nav>
<ul class="list-unstyled">
<li>Developed by Lawrence Kimutai</li>
<li>2023</li>
<li>Contact: +254759629059</li>
</ul>
</div>
</div>
</div>
</body>
</html>
We then run our app. We type the following into the terminal:
9 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
Migration files
On running the “python manage.py runserver” command you should see a link in
the terminal with which you can copy and paste on your browser from where you
can see your application:
10 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
skeleton application
We then go ahead and copy the and paste shapefile folder from the zipped folder i
shared into the media folder we had created.
11 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
Kenya_county_dd_geojson = Kenya_county_dd.to_crs("EPSG:4326").to_json()
folium.LayerControl().add_to(m)
m = m._repr_html_()
context = {'my_map': m}
return render(request, 'geoApp/home.html', context)
{{ my_map|safe }}
{% load static %}
<!DOCTYPE html>
<html lang="en">
12 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no
<meta name="description" content="">
<meta name="author" content="">
<title>GeoGida</title>
.lead {
color: #FF3366; /* Custom color for lead text */
}
</style>
</head>
<body>
13 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
{{ my_map|safe }}
<ul class="list-unstyled">
<li>Developed by Lawrence Kimutai</li>
<li>2023</li>
<li>Contact: +254759629059</li>
</ul>
</div>
</div>
</div>
</body>
</html>
14 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
And there we have our Geo App with Kenya data(shapefiles) overlaid!
This can be a foundation to many other geospatial applications you may think of.
Just impliment the functionalities and how you envision it to be!
Thank you!
You can also follow the following link to try and understand where you have any
issue:
Youtube @geospatialprimetech997
My contacts:
Twitter: https://twitter.com/lawrence_kim_?t=IgTw9ewUp1oQoKdcEirS5Q&s=09
LinkedIn: https://www.linkedin.com/in/lawrence-kimutai-6184541ba
My Github: https://github.com/KimutaiLawrence
Fiverr: https://www.fiverr.com/s/3E14NB
15 de 23 6/06/24, 17:35
BUILDING GEOSPATIAL WEB APPLICATIONS IN P... https://medium.com/@kimutai.lawrence19/building-g...
Upwork: https://www.upwork.com/freelancers/~01e0e9da97646e56f2
Email: geospatialprime@gmail.com
Follow
Geospatial Data Science, Python, Java, AI, ML, GIS. Email: geospatialprime@gmail.com and my Portfolio
Website: https://lawrence65.carrd.co/com +254759629059
16 de 23 6/06/24, 17:35