Important

Translation is a community effort you can join. This page is currently translated at 66.04%.

16.2. Lesson: Modelul Entității Simple

Cum putem să stocăm și să reprezentăm entitățile geografice într-o bază de date? În această lecție vom detalia una dintre abordări, Simple Feature Model, așa cum este definită de către OGC.

Scopul acestei lecții: De a afla ce este Modelul SFS și cum să-l folosiți.

16.2.1. Ce este OGC

Open Geospatial Consortium (OGC), o organizație internațională de voluntariat, dedicată stabilirii unor standarde, înființată în 1994. În OGC, mai mult de 370+ organizații comerciale, guvernamentale, non-profit și de cercetare la nivel mondial, colaborează într-un proces consensual deschis, încurajând dezvoltarea și implementarea standardelor pentru conținut și servicii geospațiale, prelucrarea și schimbul de date GIS. - Wikipedia

16.2.2. Ce este Modelul SFS

The Simple Feature for SQL (SFS) Model is a non-topological way to store geospatial data in a database and defines functions for accessing, operating, and constructing these data.

../../../_images/ogc_sfs.png

Modelul definește date geospațiale din tipurile Point, Linestring, și Polygon (și agregări ale acestora în obiecte Multi).

For further information, have a look at the OGC Simple Feature for SQL standard.

16.2.3. Adăugați un câmp geometric la tabelă

Let’s add a point field to our people table:

alter table people add column the_geom geometry;

16.2.4. Adăugați o constrângere bazată pe tipul geometriei

You will notice that the geometry field type does not implicitly specify what type of geometry for the field - for that we need a constraint:

alter table people
add constraint people_geom_point_chk
    check(st_geometrytype(the_geom) = 'ST_Point'::text
          OR the_geom IS NULL);

Aceasta adaugă o constrângere la tabelă, astfel încât ea va accepta doar o geometrie de tip punct sau o valoare nulă.

16.2.5. Try Yourself hard

Create a new table called cities and give it some appropriate columns, including a geometry field for storing polygons (the city boundaries). Make sure it has a constraint enforcing geometries to be polygons.

16.2.6. Popularea tabelei geometry_columns

At this point you should also add an entry into the geometry_columns table:

insert into geometry_columns values
  ('','public','people','the_geom',2,4326,'POINT');

Why? geometry_columns is used by certain applications to be aware of which tables in the database contain geometry data.

Notă

If the above INSERT statement causes an error, run this query first:

select * from geometry_columns;

If the column f_table_name contains the value people, then this table has already been registered and you don’t need to do anything more.

The value 2 refers to the number of dimensions; in this case, two: X and Y.

The value 4326 refers to the projection we are using; in this case, WGS 84, which is referred to by the number 4326 (refer to the earlier discussion about the EPSG).

Try Yourself basic

Adăugați o intrare geometry_columns adecvată pentru noul strat al orașelor

16.2.7. Adăugați o înregistare geometrică la tabelă, utilizând SQL

Now that our tables are geo-enabled, we can store geometries in them:

insert into people (name,house_no, street_id, phone_no, the_geom)
        values ('Fault Towers',
                 34,
                 3,
                 '072 812 31 28',
                 'SRID=4326;POINT(33 -33)');

Notă

In the new entry above, you will need to specify which projection (SRID) you want to use. This is because you entered the geometry of the new point using a plain string of text, which does not automatically add the correct projection information. Obviously, the new point needs to use the same SRID as the data-set it is being added to, so you need to specify it.

If at this point you were using a graphical interface, for example, specifying the projection for each point would be automatic. In other words, you usually won’t need to worry about using the correct projection for every point you want to add if you’ve already specified it for that data-set, as we did earlier.

Now is probably a good time to open QGIS and try to view your people table. Also, we should try editing / adding / deleting records and then performing select queries in the database to see how the data has changed.

Pentru a încărca un strat PostGIS în QGIS, utilizați opțiunea de meniu Layer ► Add PostGIS Layers sau butonul corespunzător din bara de instrumente:

addPostgisLayer

Se va deschide acest dialog:

../../../_images/add_postgis_layer_dialog.png

Clic pe butonul New pentru a deschide acest dialog:

../../../_images/new_postgis_connection.png

Apoi definiți o nouă conexiune, de exemplu.:

Name: myPG
Service:
Host: localhost
Port: 5432
Database: address
User:
Password:

To see whether QGIS has found the address database and that your username and password are correct, click Test Connect. If it works, check the boxes next to Save Username and Save Password. Then click OK to create this connection.

Înapoi în dialogul Add PostGIS Layers, faceți clic pe Connect, apoi adăugați straturile pentru proiectul dumneavoastră, ca de obicei.

Try Yourself moderate

Formulați o interogare care arată numele unei persoane, numele străzii și poziția (din coloana the_geom) sub formă de text simplu.

16.2.8. In Conclusion

Ați văzut cum să adăugați obiecte spațiale în baza de date, și cum să le puteți viziona în aplicația GIS.

16.2.9. What’s Next?

Mai departe, veți vedea cum se importă și se exportă datele în/din baza de date.