Introduction
This paper presents a web application that was developed in the Python programming language using the Django web framework and the Django geographic module GeoDjango. The "nnm" application is a web application that can be used in the electricity distribution company to collect the necessary data about the low-voltage network.
This paper is divided into three parts. The first part will describe the technology used in the development of the application, followed by a description of the database itself, Admin, Frontend, and finally a conclusion describing the application, the possibilities of embedding.
HTML
HTML (HyperText Markup Language) is the code that web browsers, such as Chrome, Firefox or Safari, use to display a website or application to users.
HTML stands for HyperText Markup Language. HyperText means that it is a type of text that supports hyperlinks between pages. Markup means we've taken a document and marked it up with code to, in this case, tell the browser how to interpret the page.
CSS (Cascading Style Sheets) is a language used to describe the layout and formatting of a web application written in a markup language such as HTML. CSS is the foundational technology of the World Wide Web, along with HTML and JavaScript. CSS is designed to allow separation of presentation and content, including layout, colors, and fonts. CSS is a completely independent language, separate from HTML, but practically cannot do without it. It can be said that HTML and CSS cannot do without each other. While HTML document structures create page elements, CSS styles and edits these same elements to give them the desired shape and function. CSS design can often be said to be an application. That is not completely true, it is not far from the truth. Without CSS, modern websites would look very plain and could not be used adequately.
JavaScript
JavaScript is a scripting programming language for dynamically programming web pages to make them as interactive as possible. It is also executed in the Internet browser of the user browsing the pages. Its syntax resembles the programming language C and Java, but it is considered a functional programming language.
JavaScript allows direct manipulation of web page elements, thus making them more interactive. Nowadays, JavaScript is more and more important because there are a large number of existing libraries that are accessed with that language. JavaScript libraries facilitate the work itself and speed up programming due to many ready-made functions that are often used in the development of web applications.
PostgreSQL
PostgreSQL is an open-source object-relational database system. It uses SQL as a language for capturing data, and can also use most scripting programming languages such as Perl, Python, and Ruby. The already built-in language is PL/pgSQL which is similar to the procedural language PL/SQL used in Oracle databases.
It contains almost all the possibilities from the SQL:2008 standard and is therefore the most complete open-source relational database. PostgreSQL does not include support for managing spatial data, but the PostGIS add-on adds that capability.
PostGIS
PostGIS is a plugin that adds the ability to manage spatial data to the PostgreSQL database and can then be considered a spatial database. PostGIS functions comply with the OpenGIS specification "Simple Features Specification for SQL".
When PostGIS is installed in the PostgreSQL database tables, a "geometry" type field can be added, which can contain points, lines, polygons, or a collection of the specified objects. In order for it all to make sense, it is necessary to use PostGIS functions to manage that data. This is achieved by SQL queries that contain functions for manipulating geometric fields. There are several types of such functions such as:
- geometry constructors (for creating geometric fields),
- functions for retrieving properties or individual elements of geometric fields,
- functions for editing geometric fields,
- functions for converting geometric fields into some of the output formats (WKB, WKT,
GML, GeoJSON, KML, SVG, GeoHash) and
- Functions for measurement and relationships between geometric fields.
Python
The Python standard library is well adapted to writing web applications, but it does not include modules for direct communication with databases, but provides an API (Application programming interface) with which such modules can be created. Web applications most often use databases, so such modules outside the standard library are already available for all important databases (Oracle, MSSQL, PostgreSQL, MySQL).
One such module is psycopg2 for communication with the PostgreSQL database. It uses all the capabilities of the Python DB API and can be safely used in a multi-tree environment (trees can share the same connection to the database).
Python is a powerful, flexible programming language that can be used to develop web applications, create games, and more. Python is a high-level language that is very easy to read and write.
Python is also an interpreted language - which means that it is interpreted when the source "code" is directly executed with the help of an interpreter without the need to compile or translate it into an executable form.
Python is an Object Oriented language, users are allowed to manipulate data structures called objects, in order to write a program and execute a command at the end. The Python programming language was created in the early nineties of the last century. Its author is Guido van Rossum. He was employed at the Stiching Mathematish Centrum (CWI) in the Netherlands at the time of the language's creation.
Given the very name of the Python language, the author let us know that programming can be as fun as the series of the same name, after which the program was named "Monty Python's Flying Circus", or in English "Monty Python's Flying Circus".
Linux is the right environment for Python, however it can also be used on a Windows system, but its environment is simply made to adapt to Linux operating systems, which is good, considering the ways of programming and the speed of command execution.
Gdal
GDAL (Geospatial Data Abstraction Library) needs to be installed $ sudo apt install gdal-bin
GeoDjango
GeoDjango is a built-in application that is included as a contrib module in Django. It is actually a complete framework that can be used separately from Django. It provides a set of tools for building GIS web applications. GeoDjango also provides Python bindings for popular spatial libraries such as geos, gdal and can be used separately without Django in any Python application or directly in the shell. GeoDjango integrates very well with the Django framework and provides a set of geometry fields defined by the Open Geospatial Consortium (OGS), which can be used to map different types of geometries in geospatial databases:
- GeometryField, is the base class for all geometry fields in GeoDjang,
- PointField, is used to store GEOS point objects,
- PolygonField, is used to store GEOS polygon objects.
To be able to work with GeoDjang, two things are needed:
- spatial database and - geospatial library.
A spatial database is a database that is optimized for storing and querying data representing objects defined in geometric space. In order to fully enable all functions of GeoDjang, the following geospatial open source libraries were installed; geos, gdal, proj.4, psycopg2.
GeoDjango is a plugin for the Django environment that adds the ability to manage spatial data. The development of GeoDjang began in the fall of 2006 independently of Django, and in 2008 it became part of the Django environment. The GeoDjango plugin enables quick and easy creation of web applications that use spatial data. In that case, a spatial database must be used, and GeoDjango supports the following:
- PostgreSQL with PostGIS plugin
- MySQL
- Oracle
- SQLite with SpatialLite plugin
To create a GeoDjango application, it is necessary to choose the operating system on which the server software will be executed. This paper uses the Ubuntu distribution of the GNU/Linux operating system version 22.04.
The PostgreSQL spatial database with Postgis and psycopg2 extension was used during the creation of this project. The tool used Visual Studio Code as the development environment. Also, when creating this project, web technologies html, css and JavaScript were used.
The first version of the Ubuntu distribution was created in 2004, based on the Debian distribution. With
RedHat and Debian, the Ubuntu distribution is often used for web application use due to its simple operating system and easy installation and configuration of server software.
In a test environment, a Django application can run its test web software, and as a database it can use an SQlite database consisting of a file that the Django application accesses using the built-in function library. such a combination is not suitable for a production environment due to the poor performance of the embedded web software and the lack of spatial data management functions in the SQLite database. For the production environment, it is necessary to choose an independent web server and spatial database. The web server used in this work is Apache with the mod_wsgi plugin, and the spatial database is PostgreSQL with the PostGIS plugin.
Ubuntu is a distribution of the GNU/Linux operating system. Based on the Debian distribution,
Ubuntu pays the most attention to ease of use, freedom from all restrictions, regular release of new releases (every 6 months) and ease of installation. Ubuntu is sponsored by South African businessman Mark Shuttleworth's private enterprise, Canonical. The name of the distribution comes from the African ideology of ubuntu (roughly: "humanity towards others").
Django
Django is a set of tools and a foundation for creating web applications in the Python programming language. He is alone
Django is written in Python and was created to speed up and simplify the programming of web applications as much as possible. It contains ready-made tools for standard development procedures such as:
- object-relational data models, - automatic browser for administration, - elegant URL display.
Web application programming often involves repeating the same tasks over and over again. Such tasks are:
- creating an administrative browser,
- user authentication,
- user rights,
- creation of data entry forms, - validation of entered data and - internationalization of web applications.
In other programming languages and environments, such tasks are painstaking work. U
In the Django environment, the listed procedures are simplified and boil down to writing a few lines of Python code. The object-relational data model avoids writing the SQL queries that Django automatically generates.
With more complex web applications, it is necessary to isolate the logic of the application from the display part of the application. Django uses the MVC (model-view-controller) architecture where the model represents the data model in the database, the view represents the display part of the application (what the end user sees), while the controller is responsible for the logic of the application itself and connecting the model and reviews.
Django uses different names for MVC elements, which is a bit confusing. The Django view actually represents the controller, and the template represents the view from MVC, so the implementation of MVC in Django can be called MTV (model-template-view). When a user types the address of a Django application into their Internet browser, that address is first accepted by the URL forwarding module. This module consists of regular expressions according to which the view to be activated is selected. The view communicates with models that are responsible for communicating with the database. The model returns data from the database to the view, which is then sent to the template (usually HTML). The template generates HTML code according to the received data and sends it back to the user. If cache is used, or if data from the database is not needed, some of these steps can be bypassed.
Application creation in Django and installation
The application was developed in the Visual Studio Code editor, primarily because of the many extensions it offers, but it is also possible to use other program editors such as Sublime Text or Notepad ++.
Creating the application starts with the creation of the project, the terminal offered by Visual Studio Code is used for commands:U kreirani folder „static“ koji se nalazi u nasoj
aplikaciji stubovi kreiramo fajlove map.css
i map.js