\parpic[l]{\includegraphics{qgis_user_guide_images/addshapefile}}To load a
shapefile, start QGIS and click on the \textit{Add a vector layer} toolbar bar
button\index{shapefile!loading}. This same tool can be used to load any of the formats supported by the OGR library.
Clicking on the tool brings up a standard open file dialog (Figure \ref{fig:openshapefile}) which allows you to navigate the file system and load a shapefile (or other supported data source).
\begin{figure}[h]
\begin{center}
\caption{Open OGR Data Source Dialog}\label{fig:openshapefile}\smallskip
\qgistip{When you add a layer to the map, it is assigned a random color. When adding more than one layer at a time, different colors are assigned to each. }
\end{Tip}
Once loaded, you can zoom around the shapefile using the map navigation tools. To change the symbology of a layer, open the layer properties dialog by double clicking on the layer name or by right-clicking on the name in the legend and choosing \textsl{Properties} from the popup menu. See Section \ref{sec:symbology} for more information on setting symbology of vector layers.
\subsection{Loading a MapInfo Layer}
To load a MapInfo layer, click on the \textit{Add a vector layer}
toolbar bar button and change the file type filter to \textit{MapInfo (*.mif
*.tab *.MIF *.TAB)} and select the layer you want to load.
\subsection{Loading an ArcInfo Coverage}
Loading an an ArcInfo coverage is done using the same method as with a
shapefiles and MapInfo layers. Click on the \textit{Add a vector layer} toolbar
button to open the layer dialog. Navigate to the coverage directory and select
one of the following files (if present in your coverage)
\begin{compactenum}
\item .lab - to load a label layer (polygon labels, or standing points
\item .cnt - to load a polygon centroid layer
\item .arc - to load an arc (line) layer
\item .pal - to load a polygon layer
\end{compactenum}
\section{PostGIS Layers}\index{PostGIS!layers}
PostGIS layers are stored in a PostgreSQL database. The advantage of PostGIS is the spatial indexing, filtering, and query capability. Using PostGIS, vector functions such as select and identify work more accurately than with OGR layers in QGIS.
To use PostGIS layers you must:\index{PostgreSQL!loading layers}
\begin{compactenum}
\item Create a stored connection in QGIS to the PostgreSQL database (if one is
not already defined)\index{PostgreSQL!connection}
\item Connect to the database
\item Select the layer to add to the map
\item Optionally provide a SQL \textit{where} clause to define which features to load from the layer
\item Load the layer
\end{compactenum}
\subsection{Creating a Stored Connection}\index{PostgreSQL!connection}
\parpic[l]{\includegraphics{qgis_user_guide_images/addpostgis}}The first time
you use a PostGIS data source, you must create a connection to the PostgreSQL
database that contains the data. Begin by clicking on the \textit{Add a PostGIS
Layer} toolbar button. The \textsl{Add PostGIS Table(s)} dialog will be
displayed. To access the connection manager\index{PostgreSQL!connection
manager}, click on the \textsl{New} button to
display the \textsl{Create a New PostGIS Connection} dialog. The parameters
required for a connection are shown in Table \ref{tab:postgis_connection_parms}.
\hline Name & A name for this connection. Can be the same as \textsl{Database}
\\
\hline Host \index{PostgreSQL!host}
& Name of the database host. This must be a resolvable host name the same as would be used to open a telnet connection or ping the host \\
\hline Database \index{PostgreSQL!database}& Name of the database \\
\hline Port \index{PostgreSQL!port}& Port number the PostgreSQL database server listens on. The default port is 5432.\\
\hline Username \index{PostgreSQL!username}& User name used to login to the database \\
\hline Password \index{PostgreSQL!password}& password used with \textsl{Username} to connect to the database\\
\hline
\end{tabular}
\end{table}
Once the parameters have been filled in, you can test the connection by clicking
on the \textsl{Test Connection} button\index{PostgreSQL!connection!testing}. To save the password with the connection information, check the \textsl{Save Password} option.
\begin{Tip}\caption{\textsc{QGIS User Settings and
Security}}\index{settings}\index{security}
\qgistip{Your customized settings for QGIS are stored based on the operating system. On Linux/Unix, the settings are stored in your home directory in .qt/qgisrc. On Windows, the settings are stored in the registry. Depending on your computing environment, storing passwords in your QGIS settings may be a security risk.
}
\end{Tip}
\subsection{Loading a PostGIS Layer}\index{PostgreSQL!loading layers}
\parpic[l]{\includegraphics{qgis_user_guide_images/addpostgis}}Once you have one or more connections defined, you can load layers from the PostgreSQL database. Of course this requires having data in PostgreSQL. See Section \ref{sec:loading_postgis_data} for a discussion on importing data into the database.
To load a layer from PostGIS, perform the following steps:
\begin{compactenum}
\item If the PostGIS layer dialog is not already open, click on the \textit{Add a PostGIS Layer} toolbar button
\item Choose the connection from the drop-down list and click \textsl{Connect}
\item Find the layer you wish to add in the list of available layers
\item Select it by clicking on it. You can select multiple layers by holding down the shift key while clicking. See Section \ref{sec:query_builder} for information on using the PostgreSQL Query Builder to further define the layer.
\item Click on the \textsl{Add} button to add the layer to the map
\subsection{Importing Data into PostgreSQL}\label{sec:loading_postgis_data}
\index{SPIT!importing data}
Data can be imported into PostgreSQL using a number of methods. PostGIS includes a utility called shp2pgsql that can be used to import shapefiles into a PostGIS enabled database.
\parpic[l]{\includegraphics{qgis_user_guide_images/spiticon}}QGIS comes with a
plugin named SPIT (Shapefile to PostGIS Import Tool)\index{SPIT}.
SPIT can be used to load mutliple shapefiles at one time and includes support
for schemas. To use SPIT, open the Plugin Manager from the Tools menu and load
the plugin by checking the box next to the SPIT plugin and click Ok. The SPIT
icon will be added to the plugin toolbar\index{SPIT!loading}.
To import a shapefile, click on the SPIT tool in the toolbar to open the dialog.
You can add one or more files to the queue by clicking on the \textsl{Add}
button. To process the files, click on the Import button. The progress of the
import as well as any errors/warnings will be displayed as each shapefile is
In its current implementation the attributes dialog box does not check that the
data matches the type expected, so make sure of this before
pressing \textit{Ok}.
To delete a feature, select it using the selection tool and choose
\textit{Delete selection} from the editing tools.
Once you have finished adding features, choose \textit{Stop Editing} from the
layer's context menu. Choosing \textit{Yes} will save the changes to disk, while
choosing \textit{No} at this point will cause them to be discarded.
\index{editing!saving changes}
%Note that QGIS does not yet provide any way to delete an individual feature.
\subsection{Creating a New Layer}\index{editing!creating a new layer}
In its current incarnation, the editing of attributes associated with spatial
features is extremely basic and subsequently some of the procedures explained
below involve some extra steps which will later no longer be necessary as
the editing tools mature.
To create a new layer, choose \textit{New Vector Layer} from the \textit{Layer}
menu. You will be prompted for the layer type - either point, line or polygon.
Note QGIS that
does not yet support creation of 2.5D features (i.e. features with X,Y,Z
coordinates) or measure features. At this time, only shapefiles can be
created. In a future version of QGIS, creation of any OGR or PostgreSQL layer type will be supported.
Having selected the layer type, you will be prompted for the filename for your
new layer. QGIS will automatically add a .shp extension to the name you specify.
Once the layer has been created, you edit it in the same way as described in
Section \ref{sec:edit_existing_layer} above. When the shapefile is created,
only one attribute field called "dummy" is added.
In order to add additional fields you need to
take a few extra steps as referred to earlier \footnote{These
limitations will be removed in the next version of QGIS.}.
Immediately after creating the new shape file,\index{editing!adding attribute
fields} remove it from the legend. Then in a bash or MSDOS shell, use the
shapelib\footnote{shapelib is available from
\url{http://shapelib.maptools.org/}} `dbfcreate' tool to create a new copy of
the associated .dbf file. Here is an example:
\begin{verbatim}
# dbfcreate timtest.dbf -s taxon_name 255, -n lat 3 5, -n long 3 5, -s notes 255
# dbfdump -h timtest.dbf
Field 0: Type=String, Title=`taxon_name', Width=255, Decimals=0
Field 1: Type=Double, Title=`lat', Width=3, Decimals=5
Field 2: Type=Double, Title=`long', Width=3, Decimals=5
Field 3: Type=String, Title=`notes', Width=255, Decimals=0
\end{verbatim}
Having modified the .dbf file to your needs you can now go ahead and digitise features using the same procedure as described in Section \ref{sec:edit_existing_layer}.