qgis: database · motivation: qgis, is an excellent replacement of traditional gis(geographic...

25
Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of features usually included in the cited Software: 1) Versioning: Provides data versioning for tables stored in Postgres. 2) Security defined by an administrator, administered in the server's database (client- server architecture): i.e., the ability to manage users with different levels of access. Implementing the figure of "System administrator". 3) Centralization: provide the ability to centralize not only the data of the company but also the projects (style). I.e. data and how to display versioned data. Centralization, allows to maintain the scheme of safety, integrity and strategy of crash recovery, backup of data, etc. Qgis: Qgis, is a GIS (geographic information system); It is a great tool, currently considered the most used open source GIS. Provides a Python language development environment. Through the years, Qgis has gain wide acceptance, and build up a set of plugins of importance. Within the data sources that Qgis can work with, there is a set of relational databases with spatial support, such as postgres with postgis extension. Database: Postgres: It is an open source relational database server. https://www.postgresql.org/ PostGIS: It is an extension to the PostgreSQL database to support spatial data. It adds support for geographic objects . https://postgis.net/ Both postgres, and the postgis extension are free and open source.

Upload: nguyenmien

Post on 04-Jun-2019

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of features usually included in the cited Software: 1) Versioning: Provides data versioning for tables stored in Postgres. 2) Security defined by an administrator, administered in the server's database (client-server architecture): i.e., the ability to manage users with different levels of access. Implementing the figure of "System administrator". 3) Centralization: provide the ability to centralize not only the data of the company but also the projects (style). I.e. data and how to display versioned data. Centralization, allows to maintain the scheme of safety, integrity and strategy of crash recovery, backup of data, etc.

Qgis: Qgis, is a GIS (geographic information system); It is a great tool, currently considered the most used open source GIS. Provides a Python language development environment. Through the years, Qgis has gain wide acceptance, and build up a set of plugins of importance. Within the data sources that Qgis can work with, there is a set of relational databases with spatial support, such as postgres with postgis extension.

Database: Postgres: It is an open source relational database server. https://www.postgresql.org/ PostGIS: It is an extension to the PostgreSQL database to support spatial data. It adds support for geographic objects . https://postgis.net/ Both postgres, and the postgis extension are free and open source.

Page 2: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Versioning: A version (trunk Version, alternative Version, or sub alternative Version) is analogous to a paper plane in which features can be inserted, deleted, and modified, and it does not affect in any way, any other Version. The concept of Version, is similar to the concept that has of a paper plane. The creation of a version is analogous to the process of making a photocopy of the main version. But, once the copy is created, the modifications in the original are not transferred to the copy and vice versa. The only way to transfer the changes between two different versions is through the "POST" function. The ability of versioning is very important, since it not only allows to create a timeline showing the evolution of spatial data, but also allows the existence of a set of alternatives, to represent tests, or possible projected changes in the spatial data. This plugin provides the ability of versioning as well as administration of users with security access, and projects.

What is FastVersion?

Is a plugin that integrates into Qgis, to handle vector data, creating an environment for security administration, versioning and project management. It is multi-user, and most of the functionality is stored in the Postgres database. The architecture is client-server, and the connection of Qgis is direct to the database server.

Page 3: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Installation of the PlugIn: The FastVersion PlugIn is in the experimental stage, but it will soon be ready as a stable plugin. To enable display, and install experimental plugins, you must check plugins - > Settings - > Show also experimental plugins.

Then find the plugin by name, i.e. "FastVersion" and install it.

Once installed the Plugin, the following icons will be visible in Qgis.

Page 4: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of
Page 5: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Installation of the FastVersion infrastructure in a Postgres database:

When the user tries to login to a database that, does not contain a schema named "versioned", the system will offer to install the plugin in the database. For the installation of the plugin the user, needs to be superuser. Important: Postgres version must be 9.6 or higher.

If "OK” is pressed, the schema "versioned" will be created. Within this schema a set of tables and functions will be created, to be used further by the plugin.

After FastVersion has installed the infrastructure in this database, the administrator needs to import database users in the system, to be able to associate them with versions, projects, etc. Apart from the administrator, new FastVersion users have to be created, on the database server with login permission only. And then import the into the system.

Note: If any error appears in the installation process, the “versioned” schema could

have been created, if that’s the case, it must be deleted (drop cascade), in order to make

a clean installation.

Page 6: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Login :

Qgis has its own autenticación system (via Qgis master password https://docs.qgis.org/2.18/en/docs/user_manual/auth_system/auth_overview.html), which stored in a local database, sqlite, as encrypted, a set of keys. FastVersion, uses this, to store user security information. The system of authentication built into Qgis natively only requires a key. If the Qgis master password was already established before, you will need it, to create the connection.

System administrator:

Administrator functions: Convert a table to versioned. Import users from database. Version owner management. Permission to create versions. Permission to create projects. Read and Write permissions management for each version and user.

Administration:

Page 7: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Users: The administrator can give users, permission to create versions and projects. The "Save" button must be pressed to save changes.

Page 8: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Import of Postgres users: Already existing in the postgres database roles should be incorporated within the FastVersion system to be used. The common sequence to add new users, involves the creation of the user in the postgres database, with login permission. Then this user is imported to FastVersion.

Page 9: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Version Owner: Each version is owned by only one user. Typically, the user that created the version. By default, the version owner of the version, has right to read and write on it The system administrator can change the owner of any version.

Note: The user "postgres", is a superuser in the database, and so, this user should not own any version. The users(version owners) should be created in the Postgres

database with only the "CanLogin" permission.The user "postgres" is usually the administrator of the system, and so it has access to all the database. The user "postgres", is a superuser in the database, and so, this user should not own any version.

Page 10: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

User-Version Permissions: It allows you to manage permissions for each version with respect to each user. By default, the version owner of the version, has right to read and write on it.

Page 11: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Convert a table with geometry in a versioned table: Each table that wants to be versioned must be "versioned" schema of the database. When a table is versioned, a set of fields are added (to provide versioning capability). The table to be versioned must meet the following requirements: 1 Must have a field named 'id' bigint type and that is a primary key. 2 Must have a field with name "geom" of the geometry type. 3. The system reserves the following field names, which must not exist before versioning the table:"entity","version","alternative","subalternative","review","deleted"." These fields will be created by plugin. Note: If a table is versioned with existing data, identification field must be named 'id' should be unique, not null, and primary key. Important: Once versioned, the “id” field is filled in automatically by the system. Warning: direct access to the versioned table could damage the system of versioning. Once a table is versioned, it must be handled only by the pluign, which creates a view for each version with the name and code of the version.

Page 12: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Safety test: Performs queries to the database, advising that there must be only one superuser in addition to the FastVersion role system administrator that is automatically created when you install the plugin.

Additionally; there are some situations that must be carefully handled:

For example:

The system administrator could be tempted to make a connection with the QGis-

PostgresSQL tool, with the superuser “user” and “password”.

We recommend no to do so, because this connection will be saved and any other

user with access to this machine will have access to any element of the database,

and could manipulate sensible data, that should only be managed by the plugin

for consistency reasons.

Never use the Qgis integrated Postgres-Postgis tool to make a connection.

Page 13: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

To import a shape file into Postgis, use “PostGIS import/export Manager” that is

installed with the Postgis extension. This is to avoid leaving an open Postgis

connection in a Qgis instance, that is a potential flaw to security.

Page 14: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

“Version Manager”:

Create Trunk Version or Alternative Version: Father: Trunk Version Has Trunk Version sons? No -> Option to create Trunk Version or Alternative Version

Yes -> Option to create Alternative Version

Page 15: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Create Sub-alternative Version: Father: Alternative Version Option to create Sub-Alternative Version

Open Version (Trunk Version, Alternative Version or Sub-alternative Version): Each time a version is opened, a view is created to access it, with its rules and restrictions, the table should not be accessed directly, but through the views created by the plugin, by means of version -> "open"). The views and therefore the name of the layer created for the version, are displayed. They have the following structure [version name] _ [version] _ [alternative] _ [subalternative] The set of layers is grouped into a group that identifies the version.

Rename a Version (Trunk Version, Alternative Version or Sub alternative Version): Any version can be renamed. In the version tree it is the first part of the text that precedes the version code of the version.

Page 16: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Delete a Version: There are restrictions to remove a Version: • It should not have child versions, or lower brothers. • It should not have elements that refer to that version (even deleted elements).

If Box is checked, when you click on "open" version, the system only retrieves the elements within the "window" or "box". This box limits are taken from the extension of the canvas of the visible map. This option is usually used when the table has millions of elements that produce a delay when you edit. Note: When a version is opened with the “box” option checked, any element inserted outside the box won’t be visible, but in fact is stored in the version, to view all the elements of the version , the “box” option must be unchecked. The “box” option behaves as a geographic filter.

Page 17: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of
Page 18: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Projects: Qgis stores a set of styles to display the underlying Data. The style, or the set of styles are stored with the project in the postgres database associated with a version and the user who created the project. Projects are associated with a user and version. A project is: a selection of layers in a unique version with a set of defined styles, the data is defined by the version data.

Create Select a name for the project, a description, and a date, also the set of tables to be represented as layers.

Open,

When a project is open, the tables of the project in this version is represented and the style is retrieved from database. If the project is opened twice an error message will be displayed.

Page 19: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Delete, It allows to delete the selected project

Edit, It allows to edit the selected project, change date to add or subtract the project tables and change its description or name.

Save All projects (parameters of the projects and the changes made to the style) are saved. Even the default style of the project is saved. If the project is not saved every change made in the styles of it will be lost.

Page 20: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Post Post:

The Post function allows to move the work done from one version to another. This function defines two versions: The target version is the version that will be modified (insertion, deletion or modification). The source version is the version from which the information to affect the target version will be obtained. The source version is not affected in any way.

1) The first page indicates the entities existing in the origin, and nonexistent in the objective. 2) The second page indicates the entities that exist in the target, and none existent in the origin. 3) The third page indicates the entities that exist in the source and target, but that a

Page 21: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

modification has been detected. To do this, it uses a "revision" marker(field), that indicates with a sequential number (beginning with zero) by entity, when it has been modified. That is to say that, when an entity has the same revision number there is no modification conflict.

The selected rows are highlighted by using Qgis "zoom to selection" tool.(remember to first select the correct layer)

There are three situations called conflicts, and the user can decide what action to take based in the information provided.

This functionality is not a Merge process, or consolidation between two versions but a post action, where only the target version is affected.

Page 22: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Multiple rows can be selected(use Ctrl-click), and with the respective buttons turn True, or False the modification. It is also important to check Ready when all the decisions have been taken. To commit the post all three ready check boxes in the three pages must be checked.

After the commit:

To see the effects of the commit, it is necesary to zoom-in, zoom-out, or refresh, to load the changes from database.

Page 23: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Generation of the version code “trunk version-alternative-subalternative”: The system will generate a view for each version, every time the version is opened, the view is recreated

Version-The base version is 0.0.0, in the trunk version the next will be 1.0.0, 2.0.0 and

so on.

Alternative-The alternative field has a minimum value of 1, ie the first alternative of version 0.0.0 will be 0.1.1 Versions 0.0.1 or 1.0.1, etc. are impossible. The 1st alternative is 1. The subalternative number for an alternative is always 1.

Subalternative- The subalternative field has a minimum value of 2, ie the first subalternative of alternative 0.1.1 will be 0.1.2 The first sub-alternative is 2. That is, versions 0.1.1, 1.1.1, 2.1.1, 3.1.1. are alternatives and not subalternatives. Versions 0.0.1 or 0.1.0 or 1.0.1, etc. are impossible.

Page 24: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

General rule:

For all notation v(trunk), a(alternative), s(sub alternative): If a = 0 is a trunk version. ( ?_0_? ) If s = 1 is an alternative Version.( ?_?_1 ) If s> 1 is a subalternative Version.( ?_?_2 )... ( ?_?_3 )... ( ?_?_73 ) The views and therefore the name of the layer created for the version display has the following structure [version name] _ [trunk version] _ [alternative] _ [subalternative]

Database:

The plugin was developed to work with a postgis server(Postgres 9.6 or higher). The system creates one table (the Version table), but also creates a set of functions, views and rules in an schema named ”versioned” to make everything work, they should only be manipulated by the versioning system. When the versioning system is created, version 0.0.0 is automatically created.

Page 25: Qgis: Database · Motivation: Qgis, is an excellent replacement of traditional GIS(Geographic Information System) like: Arcgis or GE Smallworld, this Qgis pulgin provides a set of

Common errors with table in postgis:

If the table is showed twice in QGis postgis source form, is because the srid is not set.

This is an example to set the srid:

ALTER TABLE schema.table

ALTER COLUMN geom type Geometry(MULTILINESTRING, 4326) USING geom::Geometry(MULTILINESTRING, 4326)

Sometimes it is necessary to truncate the table and re insert elements