Changes between Version 4 and Version 5 of UsersWikiQGIS
- Timestamp:
- 10/30/13 05:34:29 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UsersWikiQGIS
v4 v5 11 11 * Workflow 12 12 * QGIS limitations 13 * 4 ways to display a postgisgeometry in QGIS13 * 4 ways to display a PostGIS geometry in QGIS 14 14 * Tricks 15 15 … … 23 23 == Workflow == 24 24 25 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 postgistable 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.25 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 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. 26 26 27 27 == QGIS limitations == … … 32 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. 33 33 34 Loaded Post gis layers are intended for stable use. So when loading a layer from a postgistable, 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. 35 35 36 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. 37 37 38 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 Post gishas function to convert to classical type (ST_CurveToLine for example)38 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) 39 39 40 == 5 ways to display a postgisgeometry in QGIS ==40 == 5 ways to display a PostGIS geometry in QGIS == 41 41 42 42 From easiest to most complicated and powerful … … 44 44 * Load the "QuickWKT" Extension. It should add a button "WKT". This open a text field where you can past WKT geometries. Warning : doesn't support curve or mixed type, but does support EWKT (you can specidy srid). This adds a layer to QGIS, you can add as many layers as you want. This should be used only for small tests. 45 45 46 * Select the "Add a PostG is Layer" in the "Layer" menu. This open a windows where you have to define a new connection to your postgisserver (default values are : host:localhost , port:5432 , Database:postgres). You have several options you can try afterward by clicking on the edit button to edit the connection. When connected to a database, you can browse to your table and select it to display it in QGIS. You can select multiple table. A same time will appear X times if it has X geometry columns. If your table doesn't show, it is probably not registered in the public.geometry_columns PostGIS view. You have other option to display content.46 * Select the "Add a PostGIS Layer" in the "Layer" menu. This open a windows where you have to define a new connection to your PostGIS server (default values are : host:localhost , port:5432 , Database:postgres). You have several options you can try afterward by clicking on the edit button to edit the connection. When connected to a database, you can browse to your table and select it to display it in QGIS. You can select multiple table. A same time will appear X times if it has X geometry columns. If your table doesn't show, it is probably not registered in the public.geometry_columns PostGIS view. You have other option to display content. 47 47 48 * Select the DBManager in the menu Database. In the left panel, browse to your connection, then choose a table with geometry. You can right click on this table and chose "Add as a QGIS layer". This will load table even if geometry column is not listed in P OstGIS view public.geometry_columns. This is useful if you create your table with queries like `CREATE TABLE my_table AS SELECT geom ...`.48 * Select the DBManager in the menu Database. In the left panel, browse to your connection, then choose a table with geometry. You can right click on this table and chose "Add as a QGIS layer". This will load table even if geometry column is not listed in PostGIS view public.geometry_columns. This is useful if you create your table with queries like `CREATE TABLE my_table AS SELECT geom ...`. 49 49 50 * Select the DBManager in the DataBase menu, then browse to Post gis/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`50 * 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` 51 51 You 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 52 53 53 Remember each line must have an unique id (see tricks), uni-type geometry, and proper formatting. 54 54 55 * If you prefer, there are various QGIS extensions allowing sql windows /and/or specific Post gismanagement.55 * If you prefer, there are various QGIS extensions allowing sql windows /and/or specific PostGIS management. 56 56 57 57 == Tricks == … … 63 63 See http://www.postgresql.org/docs/9.3/static/sql-creatematerializedview.html 64 64 65 If you have a *very* recent QGIS version you can just add view like any other Post gistable. Else, you have to create a simple view querying you materilized view.65 If you have a *very* recent QGIS version you can just add view like any other PostGIS table. Else, you have to create a simple view querying you materilized view. 66 66 For example : 67 67 `CREATE VIEW my_proxy_view AS SELECT * FROM my_materialized_view`