.
QGIS uses the OGR library to read and write vector data formats,including ESRI shapefiles, MapInfo and MicroStation file formats, AutoCAD DXF,PostGIS, SpatiaLite, Oracle Spatial and MSSQL Spatial databases, and many more.GRASS vector and PostgreSQL support is supplied by native QGIS data providerplugins. Vector data can also be loaded in read mode from zip and gzip archivesinto QGIS. As of the date of this document, 69 vector formats are supported bythe OGR library (see OGR-SOFTWARE-SUITE in Literature and Web References). Thecomplete list is available at http://www.gdal.org/ogr/ogr_formats.html.
Note
Not all of the listed formats may work in QGIS for various reasons. Forexample, some require external commercial libraries, or the GDAL/OGRinstallation of your OS may not have been built to support the format youwant to use. Only those formats that have been well tested will appear inthe list of file types when loading a vector into QGIS. Other untestedformats can be loaded by selecting *.*.
Working with GRASS vector data is described in Section GRASS GIS Integration.
Welcome to the wonderful world of Geographical Information Systems (GIS)! Quantum GIS (QGIS) is an Open Source Geographic Information System. The project was born in May of 2002 and was established as a project on SourceForge in June of the same year. We’ve worked hard to make GIS software (which.
This section describes how to work with several common formats: ESRIshapefiles, PostGIS layers, SpatiaLite layers, OpenStreetMap vectors, and CommaSeparated data (CSV). Many of the features available in QGIS work the same,regardless of the vector data source. This is by design, and it includes theidentify, select, labeling and attributes functions.
ESRI Shapefiles¶
The standard vector file format used in QGIS is the ESRI shapefile. Support isprovided by the OGR Simple Feature Library (http://www.gdal.org/ogr/).
A shapefile actually consists of several files. The following three arerequired:
Shapefiles also can include a file with a .prj suffix, which containsthe projection information. While it is very useful to have a projection file,it is not mandatory. A shapefile dataset can contain additional files. Forfurther details, see the ESRI technical specification athttp://www.esri.com/library/whitepapers/pdfs/shapefile.pdf.
Loading a Shapefile¶
To load a shapefile, start QGIS and click on the Add Vector Layer toolbar button, or simply press Ctrl+Shift+V.This will bring up a new window (see figure_vector_1).
Figure Vector 1:
From the available options check File. Click on[Browse]. That will bring up a standard open file dialog(see figure_vector_2), which allows you to navigate the file system and load ashapefile or other supported data source. The selection box Filter allows you to preselect some OGR-supported file formats.
You can also select the encoding for the shapefile if desired.
Figure Vector 2:
Open an OGR Supported Vector Layer Dialog
Selecting a shapefile from the list and clicking [Open] loads it into QGIS.Figure_vector_3 shows QGIS after loading the alaska.shp file.
Figure Vector 3:
Tip
Layer Colors
When you add a layer to the map, it is assigned a random color. When addingmore than one layer at a time, different colors are assigned to each layer.
Once a shapefile is loaded, you can zoom around it using the map navigation tools.To change the style of a layer, open the Layer Properties dialogby double clicking on the layer name or by right-clicking on the name in thelegend and choosing Properties from the context menu. Seesection Style Menu for more information on setting symbology ofvector layers.
Tip
Load layer and project from mounted external drives on OS X
On OS X, portable drives that are mounted beside the primary hard drivedo not show up as expected under File ‣ Open Project.We are working on a more OSX-native open/save dialog to fix this.As a workaround, you can type /Volumes in the File name boxand press Enter. Then you can navigate to external drives and networkmounts.
Improving Performance for Shapefiles¶
To improve the performance of drawing a shapefile, you can create a spatialindex. A spatial index will improve the speed of both zooming and panning.Spatial indexes used by QGIS have a .qix extension.
Use these steps to create the index:
Problem loading a shape .prj file¶
If you load a shapefile with a .prj file and QGIS is not able to read thecoordinate reference system from that file, you will need to define the properprojection manually within the General tab of theLayer Properties dialog of the layer by clicking the[Specify..] button. This is due to the fact that .prj filesoften do not provide the complete projection parameters as used in QGIS andlisted in the CRS dialog.
For the same reason, if you create a new shapefile with QGIS, two differentprojection files are created: a .prj file with limited projectionparameters, compatible with ESRI software, and a .qpj file, providingthe complete parameters of the used CRS. Whenever QGIS finds a .qpjfile, it will be used instead of the .prj.
Loading a MapInfo Layer¶
To load a MapInfo layer, click on the Add Vector Layer toolbar button; or type Ctrl+Shift+V, change thefile type filter Files of type: to‘Mapinfo File [OGR] (*.mif *.tab *.MIF *.TAB)’ and select the MapInfo layer youwant to load.
Loading an ArcInfo Binary Coverage¶
To load an ArcInfo Binary Coverage, click on theAdd Vector Layer toolbar button or pressCtrl+Shift+V to open the Add Vector Layer dialog. Select Directory as Source type. Change thefile type filter Files of type to‘Arc/Info Binary Coverage’. Navigate to the directory that contains thecoverage file, and select it.
Similarly, you can load directory-based vector files in the UK National TransferFormat, as well as the raw TIGER Format of the US Census Bureau.
Delimited Text Files¶
Tabular data is a very common and widely used format because of its simplicityand readability – data can be viewed and edited even in a plain text editor.A delimited text file is an attribute table with each column separated by adefined character and each row separated by a line break. The first row usuallycontains the column names. A common type of delimited text file is a CSV(Comma Separated Values), with each column separated by a comma.
Such data files can also contain positional information in two main forms:
QGIS allows you to load a delimited text file as a layer or ordinal table. Butfirst check that the file meets the following requirements:
As an example of a valid text file, we import the elevation point data fileelevp.csv that comes with the QGIS sample dataset (see sectionSample Data):
Some items to note about the text file:
Loading a delimited text file¶
Click the toolbar icon Add Delimited Text Layer in theManage layers toolbar to open the Create a Layer from aDelimited Text File dialog, as shown in figure_delimited_text_1.
Figure Delimited Text 1:
First, select the file to import (e.g., qgis_sample_data/csv/elevp.csv)by clicking on the [Browse] button. Once the file is selected, QGISattempts to parse the file with the most recently used delimiter. To enable QGIS to properly parse thefile, it is important to select the correct delimiter. You can specify adelimiter by activating Custom delimiters, or by activating Regular expression delimiter and enteringtext into the Expression field. For example, tochange the delimiter to tab, use t (this is a regular expression for thetab character).
Once the file is parsed, set Geometry definition toPoint coordinates and choose the X and Yfields from the dropdown lists. If the coordinates are defined asdegrees/minutes/seconds, activate the DMS coordinatescheckbox.
Finally, enter a layer name (e.g., elevp), as shown infigure_delimited_text_1. To add the layer to the map, click [OK]. Thedelimited text file now behaves as any other map layer in QGIS.
There is also a helper option that allows you to trim leading and trailingspaces from fields — Trim fields. Also, it is possibleto Discard empty fields. If necessary, you can force a commato be the decimal separator by activating Decimal separator iscomma.
If spatial information is represented by WKT, activate the Well Known Text option and select the field with the WKT definition forpoint, line or polygon objects. If the file contains non-spatial data, activate No geometry (attribute only table) and it will beloaded as an ordinal table.
Additionaly, you can enable:
OpenStreetMap data¶
In recent years, the OpenStreetMap project has gained popularity because in manycountries no free geodata such as digital road maps are available. The objectiveof the OSM project is to create a free editable map of the world from GPS data,aerial photography or local knowledge. To support this objective, QGISprovides suppport for OSM data.
Loading OpenStreetMap Vectors¶
QGIS integrates OpenStreetMap import as a core functionality.
PostGIS Layers¶
PostGIS layers are stored in a PostgreSQL database. The advantages of PostGISare the spatial indexing, filtering and query capabilities it provides. UsingPostGIS, vector functions such as select and identify work more accurately than they dowith OGR layers in QGIS.
Creating a stored Connection¶
The first time you use a PostGIS data source, you mustcreate a connection to the PostgreSQL database that contains the data. Begin byclicking on the Add PostGIS Layer toolbarbutton, selecting the Add PostGIS Layer..option from the Layer menu, or typing Ctrl+Shift+D. Youcan also open the Add Vector Layer dialog and select Database. The Add PostGIS Table(s)dialog will be displayed. To access the connection manager, click on the[New] button to display the Create a New PostGIS Connectiondialog. The parameters required for a connection are:
Qgis 3 Rc For Os X 4
Optionally, you can activate the following checkboxes:
Once all parameters and options are set, you can test the connectionby clicking on the [Test Connect] button.
Loading a PostGIS Layer¶
Once you have one or more connections defined, you canload layers from the PostgreSQL database. Of course, this requires having data inPostgreSQL. See section Importing Data into PostgreSQL for a discussion onimporting data into the database.
To load a layer from PostGIS, perform the following steps:
Tip
PostGIS Layers
Normally, a PostGIS layer is defined by an entry in the geometry_columnstable. From version 0.9.0 on, QGIS can load layers that do not have anentry in the geometry_columns table. This includes both tables and views.Defining a spatial view provides a powerful means to visualize your data.Refer to your PostgreSQL manual for information on creating views.
Some details about PostgreSQL layers¶
This section contains some details on how QGIS accesses PostgreSQL layers.Most of the time, QGIS should simply provide you with a list of databasetables that can be loaded, and it will load them on request. However, if you havetrouble loading a PostgreSQL table into QGIS, the information below mayhelp you understand any QGIS messages and give you direction on changingthe PostgreSQL table or view definition to allow QGIS to load it.
QGIS requires that PostgreSQL layers contain a column that can be usedas a unique key for the layer. For tables, this usually means that the tableneeds a primary key, or a column with a unique constraint on it. In QGIS,this column needs to be of type int4 (an integer of size 4 bytes).Alternatively, the ctid column can be used as primary key. If a table lacksthese items, the oid column will be used instead. Performance will beimproved if the column is indexed (note that primary keys are automaticallyindexed in PostgreSQL).
If the PostgreSQL layer is a view, the same requirement exists, but viewsdo not have primary keys or columns with unique constraints on them. You have todefine a primary key field (has to be integer) in the QGIS dialog before youcan load the view. If a suitable column does not exist in the view, QGISwill not load the layer. https://supernalcenters422.weebly.com/blog/canon-scanner-drivers-for-mac-os-mojave. If this occurs, the solution is to alter the view sothat it does include a suitable column (a type of integer and either a primarykey or with a unique constraint, preferably indexed).
QGIS offers a checkbox Select at id that is activated by default. Thisoption gets the ids without the attributes which is faster in most cases. Itcan make sense to disable this option when you use expensive views.
Tip
Backup of PostGIS database with layers saved by QGIS
If you want to make a backup of your PostGIS database using the pg_dump andpg_restore commands the default layer styles as saved by QGIS are failing torestore afterwards. You need to set the XML option to DOCUMENT and therestore will work.
Importing Data into PostgreSQL¶
Data can be imported into PostgreSQL/PostGIS using several tools, including theSPIT plugin and the command line tools shp2pgsql and ogr2ogr.
DB Manager¶
QGIS comes with a core plugin named DB Manager. It canbe used to load shapefiles and other data formats, and it includes support forschemas. See section DB Manager Plugin for more information.
shp2pgsql¶
PostGIS includes an utility called shp2pgsql that can be used to importshapefiles into a PostGIS-enabled database. For example, to import ashapefile named lakes.shp into a PostgreSQL database namedgis_data, use the following command: Landscape utility for mac os x.
This creates a new layer named lakes_new in the gis_data database.The new layer will have a spatial reference identifier (SRID) of 2964.See section Working with Projections for more information on spatialreference systems and projections.
Tip
Exporting datasets from PostGIS
Like the import tool shp2pgsql, there is also a tool to exportPostGIS datasets as shapefiles: pgsql2shp. This is shipped withinyour PostGIS distribution.
ogr2ogr¶
Besides shp2pgsql and DB Manager, there is another tool for feeding geodatain PostGIS: ogr2ogr. This is part of your GDAL installation.
To import a shapefile into PostGIS, do the following:
This will import the shapefile alaska.shp into the PostGIS databasepostgis using the user postgres with the password topsecret on hostserver myhost.de.
Note that OGR must be built with PostgreSQL to support PostGIS.You can verify this by typing (in )
If you prefer to use PostgreSQL’s COPY command instead of the defaultINSERT INTO method, you can export the following environment variable(at least available on and ):
ogr2ogr does not create spatial indexes like shp2pgsl does. Youneed to create them manually, using the normal SQL command CREATE INDEXafterwards as an extra step (as described in the next sectionImproving Performance).
Improving Performance¶
Retrieving features from a PostgreSQL database can be time-consuming, especiallyover a network. You can improve the drawing performance of PostgreSQL layers byensuring that a PostGIS spatial index exists on each layer in thedatabase. PostGIS supports creation of a GiST (Generalized Search Tree)index to speed up spatial searches of the data (GiST index information is takenfrom the PostGIS documentation available at http://postgis.refractions.net).
The syntax for creating a GiST index is:
Note that for large tables, creating the index can take a long time. Once theindex is created, you should perform a VACUUMANALYZE. See the PostGISdocumentation (POSTGIS-PROJECT Literature and Web References) for more information.
The following is an example of creating a GiST index:
Vector layers crossing 180° longitude¶
Many GIS packages don’t wrap vector maps with a geographic reference system(lat/lon) crossing the 180 degrees longitude line(http://postgis.refractions.net/documentation/manual-2.0/ST_Shift_Longitude.html).As result, if we open such a map in QGIS, we will see two far, distinct locations,that should appear near each other. In Figure_vector_4, the tiny point on the farleft of the map canvas (Chatham Islands) should be within the grid, to the right of theNew Zealand main islands.
Figure Vector 4:
A work-around is to transform the longitude values using PostGIS and theST_Shift_Longitude function. This function reads every point/vertex in everycomponent of every feature in a geometry, and if the longitude coordinate is< 0°, it adds 360° to it. The result is a 0° - 360°version of the data to be plotted in a 180°-centric map.
Figure Vector 5:
Crossing 180° longitude applying the ST_Shift_Longitudefunction
Usage¶
Qgis 3 Rc For Os X DownloadSpatiaLite Layers¶
The first time you load data from a SpatiaLitedatabase, begin by clicking on the Add SpatiaLite Layer toolbar button, or by selecting theAdd SpatiaLite Layer.. optionfrom the Layer menu, or by typing Ctrl+Shift+L.This will bring up a window that will allow you either to connect to aSpatiaLite database already known to QGIS, which you can choose from thedrop-down menu, or to define a new connection to a new database. To define anew connection, click on [New] and use the file browser to point toyour SpatiaLite database, which is a file with a .sqlite extension.
If you want to save a vector layer to SpatiaLite format, you can do this byright clicking the layer in the legend. Then, click on Save as.,define the name of the output file, and select ‘SpatiaLite’ as format and the CRS.Also, you can select ‘SQLite’ as format and then add SPATIALITE=YES in theOGR data source creation option field. This tells OGR to create a SpatiaLitedatabase. See also http://www.gdal.org/ogr/drv_sqlite.html.
QGIS also supports editable views in SpatiaLite.
Creating a new SpatiaLite layer¶
If you want to create a new SpatiaLite layer, please refer to sectionCreating a new SpatiaLite layer.
Tip
SpatiaLite data management Plugins
For SpatiaLite data management, you can also use several Python plugins:QSpatiaLite, SpatiaLite Manager or DB Manager (core plugin, recommended).If necessary, they can be downloaded and installed with the Plugin Installer.
MSSQL Spatial Layers¶
QGIS also provides native MS SQL 2008 support. The firsttime you load MSSQL Spatial data, begin by clicking on theAdd MSSQL Spatial Layer toolbar button or byselecting the Add MSSQL Spatial Layer..option from the Layer menu, or by typing Ctrl+Shift+M.
Oracle Spatial Layers¶
The spatial features in Oracle Spatial aid users in managing geographic andlocation data in a native type within an Oracle database. QGIS now hassupport for such layers.
Creating a stored Connection¶
The first time you use an Oracle Spatial data source,you must create a connection to the database that contains the data. Begin byclicking on the Add Orcale Spatial Layer toolbarbutton, selecting the Add OrcaleSpatial Layer.. option from the Layer menu, or typingCtrl+Shift+O. To access the connection manager, click on the [New]button to display the Create a New Oracle Spatial Connection dialog.The parameters required for a connection are:
Optionally, you can activate following checkboxes:
Once all parameters and options are set, you can test the connection byclicking on the [Test Connect] button.
Tip
QGIS User Settings and Security
Depending on your computing environment, storing passwords in your QGISsettings may be a security risk. Passwords are saved in clear text in thesystem configuration and in the project files!Your customized settings for QGIS are stored based on the operating system:
Loading an Oracle Spatial Layer¶
Once you have one or more connections defined, you canload layers from the Oracle database. Of course, this requires having data inOracle.
To load a layer from Oracle Spatial, perform the following steps:
Tip
Oracle Spatial Layers
Normally, an Oracle Spatial layer is defined by an entry in theUSER_SDO_METADATA table.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2020
Categories |