Database Query

This page presents a general view of relational databases emphasizing the relationship between SPRING and a relational database management system (RDBMS) such as CODEBASE, ACCESS, MYSQL, POSTGRESQL and ORACLE.

When a database is first created in SPRING, the user should define which DBMS he will be using. For CODEBASE, the tables are compatible with DBase 4 format, extensions*.dbf. For ACCESS (Microsoft), all tables are kept in a single "spring.mdb" file. For MYSQL, POSTGRESQL and ORACLE, the tables are stored inside its manager and the user must have permission to create and update his own tables.

To better understand the application of tables in each data category and object, the user must be familiar with the SPRING Conceptual Model .



Spatial Analysis


Relational Databases

The principles of the relational structure were first presented by Codd in 1972, who realized that the discipline and
rigour of mathematics could be used in the field of database management. The relational structure is based on the mathematical set theory of relations and predicate calculus. Intuitively we can understand a relationship such as attributes associated to entities of the real world. For instance, for describing an Urban Cadastre we can use the relationship:

<lot id, owner, address, area, tax >

A relationship can be represented using a table. Check the example below where a table shows the relationship of an urban cadastre with its attributes and values:

lot id

owner

address

area (m2)

tax(R$)

195689

Guimarães , M.

Clóvis Bevilacqua, 768

900

350

Codd suggested a set of operations over the relationships called relational algebra which included operations of projection, selection, union, intersection and cartesian product. He also showed that these operations were closed, i.e., the application of one of them always generates another relationship.

The relational model has proved to be very useful to deal with commercial and administrative applications. Nowadays it is a wide known technology whose strict formulation has allowed the definition of a standard language for queries called SQL (Structured Query Language).

In the IBM-PC environment, most database management systems also follow this relational standard, including DBASE, ORACLE and ACCESS.


Database Query - index


Geo-Relational Data Model

The RDBMS (Relational Database Management System) is the link between a geographic information system and a relational database. It is also called a geo-relational model where the spatial and descriptive components of the
geographic object are stored separately. The conventional attributes are stored on the database (as tables) and the spatial data are handled by a dedicated system. The link is done using object identifiers ( id). To retrieve an object the user must search both subsystems and the answer will be a composition of results. This architecture is described on the figure below:


Figure - Geo-relational data model

Database Query - index


Relational DBMS and SPRING

SPRING has been conceived as a geographic database and was, since the beginning, projected to operate efficiently with a DBMS, using a geo-relational data model (as described above).

We define here a geographic database as a repository of GIS data, storing geographic data in different geometries (images, vectors, grids) as well as descriptive information (non-spatial attributes) that are stored in tables inside the database.

Nowadays, the native databases management systems available are: CODEBASE (compatible with DBASE IV), ACCESS (Microsoft - it is necessary to have the manager installed or the JET drives (3.4 or 4.0 - required libraries so SPRING can create a *.mdb database), MYSQL, POSTGRESQL and ORACLE (these three must be provided by the user - installed remotely or locally). The MYSQL, POSTGRESQL and ORACLE database manager must be purchased separately by the user. The use of the DBMS is controlled from the creation of a database on SPRING.

NOTE 1: The Access manager is available only for the SPRING Windows version.

NOTE 2: The POSTGRESQL manager is available for the SPRING Windows and Linux version.  



Check
here how to manipulate a Database in the SPRING System.


Database Query - index


Geo-Fields and Geo-Objects Attributes

In SPRING, each category of geographic data is associated to a table, that contains attributes describing the data types. Each geo-object and geo-field receives a unique identifier (the "geoid"), which is maintained by the system and should not be changed by the user.

The current RDBMS (defined when the database is created inside SPRING) is used to store all descriptive attributes and tables and can be visualized externally using the appropriate management system.

Database Query - index


Input of Geographic Data Attributes

The definition of geographic data attributes is described in detail at SPRING Conceptual Model. Generally, each category can be associated to a relationship expressed in a table. The button "Attributes..." (after choosing the option File - Data Model on the main menu) allows the input of attributes from the associated table.

In case of Thematic Maps, each thematic class (geo-class) can be associated to a relationship (table).

To include an external table in the SPRING database, you have to create or import it to a non-spatial model and then associate it to an object table. See how to edit non-spatial data and how to link tables.

The next examples illustrate the association of attributes to geo-fields and geo-objects in SPRING.

Image Attributes - Example

We can associate attributes to categories coming from IMAGES, to create, for example, a satellites image catalog of your institution. Then, we can associate to each image, information such as: satellite, sensor, date, orbit/point ("World Reference System" - WRS) and correction. The table below presents this set of attributes:

 

geoid

satellite

sensor

data_pass

orbit

point

correction

001

LANDSAT5

TM

25/01/86

228

78

S

002

LANDSAT3

MSS

19/06/82

234

66

P

Thematic Maps Attributes - Example

Consider a thematic map that contains a category called SoilsMap that contains the maps of soil from a national database. Then, the specialist might want to associate to each map, some information such as: survey date, person in charge and institution:

geoid

survey_date

responsible

institution

001

29/05/85

Damião Carneiro

FUNCEME

Note that this table is related to maps from the category SoilsMap and it can be used to store information related to the maps as spatial entities. SPRING also allows the association of tables to classes that are associated to thematic maps. It is possible to have a single table for all classes.

Considering the example above, we might want to determine properties that are common to all thematic classes such as: ph, Aluminum proportion, Nitrogen, Potassium and humidity. The table below shows and example of attributes for the classes associated to the category SoilsMaps.

IL

description

humidity

ph

Aluminum

potassium

Le

latossolo

60%

7.6

80

70

 

Cadastral Maps Attributes - Example

To illustrate cadastral maps and geo-objects let's consider an example of a map of lots in a city. Suppose we create two categories: Lots (Object) and LotsMap (Cadastral).

In the case of lots, the associated information could be: registration number, owner name, lot size and tax paid. Since we are dealing with a geo-object that has geographic location, SPRING automatically associates to each table input a unique identifier for each geographic object.

Example of attributes for "Lots"

geoid

regist

owner

address

area (m2)

tax(R$)

154

195689

Guimarães , M.

R.Bevilacqua , 768

900

350

The elements for LotsMap category could have the following attributes: map number, region of the city, map scale and survey date as shown below:

geoid

number

label

scale

year

345

273

Jardim Esplanada

2000

1986

 

Network Maps Attributes - Example

A network map is similar to a cadastral map since they both deal with objects, however in the form of lines and points. Let's take an example of a map of roads in a city and suppose the creation of two categories: Roads (Object) and RoadsMap (Cadastral).

For Roads, the associated information could be: registered number, number of tracks, width, type of asphalt, value in meters. Since we are dealing with a geo-object that has geographic location, SPRING automatically associates to each table input a unique identifier for each geographic object.

Example of Attributes for "Roads"

geoid

number

tracks

width

type_asph

value(R$)

154

L0023

2

5,45

3A

350

NOTE: The definition of flow parameters (impedance) and demand for each network segment must be done when the map is being edited.

Database Query - index


Geo-Objects Attributes

In SPRING, the geo-objects are defined independently from their graphic representation and if you want to link them to their representations you have to execute some step:

1. On the main menu, click on File - Data Model... ( atalho_esquema.gif - 992 Bytes) to define a category derived from an object category (in the previous example, the category Lots) and associate the attributes.

2- In " Categories" define the attributes associated to the Lots table.

3. Define a category of Cadastral model (Name: Urban_Cadastre).

4. Choose on the main menu Edit - Infolayer... and create an IL (for example Lots_Map), from the category Urban_Cadastre. Digitize the lines (see how to digitize) that contain the boundaries, adjust the lines and create the polygons.

5. Associate, by pointing, the polygons of the objects map (Cadastral Objects Identification). In our example, we need to associate polygons of the Lots Map (see figure below).

6. Fill in the objects attributes (lot) at the window " Attributes Values" that can be accessed when you click on Attributes..., "Object Edition" window (Edit - Object... on the main menu). Check How to edit objects.


Figure - Association of geo-objects to geometric representations.

NOTE: Check next how to perform query on cadastral objects from attributes defined by the user.

Database Query - index


Cadastral Objects Query

For map visualization the user should use the options available at the "Control Panel" (see more details on how to operate the Control Panel). There the user will find some options for controlling the exhibition of images, thematic maps and digital terrain models. However when we have object maps (cadastral or network), the "Control Panel" only controls the selection of IL and all objects inside them, not allowing the objects analysis in terms of attributes and spatial relationship.

In SPRING, the resources for query on cadastral and network maps go beyond the simple presentation of objects category. It is possible to perform a query considering the descriptive attributes of objects (for instance, "Show all high schools that have more than 1500 students" - the attributes school level and number of students are inside the table of the object school) or spatial relationship (for instance, "Which schools are inside the Ipiranga district and are located 2000 meters far from the police station" - the comparison is done with a map of objects districts and another object that represents the police stations).

The manipulation of the geo-objects table might become slow when the data volume is high. To solve this problem, you can create an objects collection by extracting from the table only the objects of interest and creating an auxiliary table. For example, the user can create a collection of polygons (Lots) with tax value greater than R$1500, and from this new table perform other queries.


NOTE:
Check here some examples on how to use cadastral maps in SPRING.

Query Models

The query on a map of objects starts with a selection on the "Control Panel" followed by the creation of an Object Collection and Visualization Control. From the Visualization Control, you can access the modules Query, Spatial Query, Grouping and Table. With the objects on the Visualization Screen, you can process a query on the Attributes/Images/URL module. Using the Table module you will be able to save its content, generate other collections or thematic plans. The figure below shows the relationships among these modules, as well as the possible paths you can follow when processing a query on its objects.

Observe that there is a dependency and an order to be followed in the query modules.



The figure above shows the dependency of the query modules – they need to be processed in a sequence (see the query examples at the end of this class). Next, we will describe how to use each one of these modules:

  1. In the “ Control Panel”, you must define which ILs will be presented on the drawing area specially activating the cadastral or network IL to be queried;
  2. On the active chosen IL, you must pick an object category to be queried. It is possible to work with all objects (option ALL) present on the map. However , if you wish, you can create a collection;
  3. The purpose of the Objects Visualization module is to command the visualization of the object categories inside a cadastral or network IL. If one collection is defined and applied, only the corresponding objects category will be available in this module. Basically, the control is over how and which objects will be visualized. Besides these controls, this module organizes the exhibition of legends and controls the sequencing of the graphical presentation determining which object category must be queried, grouped or visualized in table format. This module also determines which object category is active to be analyzed on the screen.
  4. The modules Query, Spatial Query, Grouping and Table change the graphical presentation of the queried object. Notice on the figure above that all modules reflect a display on the screen, either coming from the objects collection or from a pre-selection by other module. The sequence of operations is important for obtaining the desired result.

Query: selects objects satisfying a condition imposed by you, based on its descriptive attributes which may be combined on the same expression. The selected objects are presented on the display and table module, and might be further used on the grouping or spatial query modules
Spatial Query: select objects based on their relationship (topological, metric or directional) with other objects, from the same category or same IL. The selected objects are presented on the display and table module and might be used by the grouping or attributes query modules.
Grouping: create groups of geographical objects according to their descriptive attributes, starting from objects defined in the collection or pre-selected by an attribute query, a spatial query or both. The result is presented only on the display with the color code defined for each group. You can also generate pie chart and histograms for each object.
Table: displays all the attributes of an object category even from a non-spatial table that has been previously related. Each line of the table presents the set of objects defined by the collection or later selected by an attribute query or spatial query. If you click on the object on the display its corresponding line will be highlighted on the table, and vice-versa. It is possible to define graphical and statistical analysis on the numerical attributes. It is also possible to save the table contents into text files, generate an object collection or a thematic IL of the objects listed on the table.
Objects Attribute (Attributes, Photo, Multimedia and URL): only displays conventional attributes from the selected object, besides attributes in the form of files. SPRING stores the place where the files (JPG, GIF, TIF, DOC, PDF, MOV, MP3, etc.) are located so they can be visualized.

 


First Steps to perform a query on a cadastral map

Visualizing an objects map:

  • select on the "Control Panel" an IL of cadastral category cadastral;
  • click on the representations Lines and Objects of the selected IL and then Execute - Draw on the active screen;
  • click on Query... to define the collection, and then on Apply at the window " Generating and Selecting Collections";
  • the windows " Visualizing Objects" and Table are presented;
  • select one of more objects categories and click on the respective square button (it will be highlighted). To deselect, click on the button again;


Check how to operate each module in detail:


Cleaning previous queries

After exiting SPRING, the system always stores the last query performed. It is possible to clean all modules or select a specific one.

The options are the following:

  • All Operations
  • Table Colors
  • Grouping
  • Bars and Pie Charts
  • Queries


Cleaning queries on objects maps:

  • select the screen where you want to clean the query;
  • click on Execute - Clean and choose one of he options;


Database Query - index