Changes between Version 3 and Version 4 of UsersWikiQGIS


Ignore:
Timestamp:
Oct 30, 2013, 5:29:35 AM (11 years ago)
Author:
yjacolin
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiQGIS

    v3 v4  
    1616== Why use QGIS with PostGIS ==
    1717
    18  QGIS is an open source software with lot's of functionalities. PostGIS is natively integrated in it, and it works relatively well.
    19 Also QGis as an extension repository and is fully scriptable with Python, which makes it a cornerstone for working in GIS with Open Source software.
     18QGIS is an open source software with lot's of functionalities. PostGIS is natively integrated in it, and it works relatively well.
     19
     20Also QGIS has an extension repository and is fully scriptable with Python, which makes it a cornerstone for working in GIS with Open Source software.
    2021When using PostGIS you always end up to have to display some geometry, so better use the right tool for it.
    2122
    2223== Workflow ==
    2324
    24 The workflow is always identical. The first time, you have to define a connection to PostGIS database ((default values are : host:localhost , port:5432 , Database:postgres)). Then you will load a postgis table containing a geometry columns as a new QGIS layer. Then this layer can be edited, and you have access to all the other columns (if the type is known by QGIS, else cast to ::text), for example to use it as a color categories, or as proportion field, etc.
     25The workflow is always identical. The first time, you have to define a connection to PostGIS database ((default values are : host:localhost , port:5432 , Database:postgres)). Then you will load a postgis table containing a geometry column as a new QGIS layer. Then this layer can be edited, and you have access to all the other columns (if the type is known by QGIS, else cast to ::text), for example to use it as a color categories, or as proportion field, etc.
    2526 
    2627== QGIS limitations ==
    2728
    28 Every loaded PostGis geometry layer must have a Primary key! That is, a way of uniquely identifying every row of the table. In PostGIS it is usually done adding an gid column in table definiton, like this : `CREATE TABLE mytable AS (idauto SERIAL int, other_columns...)`. If you have no other option , you can always use a trick to generate on the fly a fake uid (see Tricks).
     29Every loaded PostGIS geometry layer must have a Primary key! That is, a way of uniquely identifying every row of the table. In PostGIS it is usually done adding a gid column in table definiton, like this : `CREATE TABLE mytable AS (idauto SERIAL int, other_columns...)`. If you have no other option , you can always use a trick to generate on the fly a fake uid (see Tricks).
    2930
    30  PostGIS srid are not supported, so you have to manually choose the right projection and coordinate system when adding a PostGis geometry layer.
    31  Mixed geometry are not supported ( neither are GeometryCollections). So when using mixed geometries, you have to load 3 times the table each time selecting a different type of geometry . Us St_CollectionExtract or ST_Dump to break GeometryCollection appart.
     31 PostGIS srid are not supported, so you have to manually choose the right projection and coordinate system when adding a PostGIS geometry layer.
     32 Mixed geometry are not supported ( neither are GeometryCollections). So when using mixed geometries, you have to load 3 times the table each time selecting a different type of geometry . Use St_CollectionExtract or ST_Dump to break GeometryCollection appart.
    3233 
    33  Loaded Postgis layers are intended for stable use. So when loading a layer from a postgis table, don't delete table or change table def, as it will crash QGIS. Reloading will discard bad postgis layer.
     34 Loaded Postgis layers are intended for stable use. So when loading a layer from a postgis table, don't delete table or change table def, as it will crash QGIS. Reloading will discard bad PostGIS layer.
    3435
    35  PostGis is made to display up to a few hundred thousand geometry with beautiful styling. More geometries than this is going to be slow, or will crash. You may want to clip you data to keep only a work set if working with massive data.
     36 PostGIS is made to display up to a few hundred thousand geometry with beautiful styling. More geometries than this is going to be slow, or will crash. You may want to clip you data to keep only a work set if working with massive data.
    3637
    3738 Funky type : QGIS works well with points, line , polygon. It will work to a certain extent with Multi, but will definitively not work with more subtle geometry type, like curve, mesh, tin, etc. Usually Postgis has function to convert to classical type (ST_CurveToLine for example)
     
    4950 * Select the DBManager in the DataBase menu, then browse to Postgis/your_connection. Now click on the "SQL WIndow" icon. This open a text editor where you can use any query you like. It is very useful when geometry are not directly accessible. For example, you have a table with id, X and Y columns, but no geometry column. You can use the following query `SELECT id, X, Y, ST_SetSRID(ST_MakePoint(X,Y), your_srid) AS geom FROM your_table`
    5051You can test query with F5. There is auto completion. CTE are allowed, but you need to be strict on query formatting (no leading spaces or tabs, neither at the end). When you are satisfied, you can click on the "load as a new layer" box and choose an id and geom column.
     52
    5153Remember each line must have an unique id (see tricks), uni-type geometry, and proper formatting.
    5254
     
    6769
    6870
    69  You can use QGis visualization settings to make the element appears dynamically.
     71 You can use QGIS visualization settings to make the element appears dynamically.
    7072This is better than just waiting with blank screen while objects are loading, at least when trying to define an interesting area.
    7173For this, open Option/Rendering, then put something superior to 1000 in the appropriated field.
     
    7476When you don't have a unique id for each row you want to display, you can create on on the fly using the SQL windows to load your geometries.
    7577Simply add in the select :
    76 `SELECT row_number() OVER() AS id_qgis` , and select id_qgis as the id column in the qgis list.
     78`SELECT row_number() OVER() AS id_qgis` , and select id_qgis as the id column in the QGIS list.