Geospatial Files

Introduction

This section describes the management of file-based data sources, as opposed to GIS data that originates from databases. Geocap supports mostly the same formats as the GDAL community library.

 

Shapefiles, CSV, GeoTIFF are examples of common geospatial file formats.



In this section:

Importing a geospatial file

To import a geospatial file:

  1. In the project toolbar, click the leftmost Add button and click Data Source
  2. Choose a connection name or click '+' to add a new one. This is optional, but makes it easy to find the connection parameters (the filename) next time.
  3. In the Datasource field select Geospatial File
  4. As Datatype select Vector Data or Raster, depending on the data type. Typical vector based file formats include Esri Shapefiles or CSV. 
  5. Select the file.
  6. Click Connect. 

If you opened a vector based or polygonal data file you will now see a new object of type Simple Features Datasource in the project manager. The term simple features indicates adherence to the Open Geoconsortium simple features specification. If you opened a raster file you will see an object of type Geospatial Raster File.

Exporting a geospatial file

The layers of a Simple Features Datasource can be exported as follows:

  1. Right-click the datasource object in the project manager and click Export.
  2. In the export wizard, select which layers to export. Click Next.
  3. Select export format. Click Next.
  4. Depending on the chosen format select output file or directory. Click Finish.

Displaying data from GIS files

  • To display data in a Simple Features Layer right-click on the Simple Features Layer object and click Display simple features. Right-click the layer object again and click Zoom to Data to ensure that the displayed is visible in the graphics window.
  • To display a geospatial raster right-click on the Geospatial Raster File object and click Display. Right-click the raster object again and click Zoom to Data to ensure that the displayed is visible in the graphics window.

When displaying a layer containing vector data some display options are available. To modify the display behaviour:

  1. Locate the Display simple features command object in the command view. This may be either an item command, a schema command or a shared command.
  2. Right-click the command object and click Edit.
  3. Modify the display parameters. To display attributes check the Labels options and select which attribute to display.

Viewing layer attributes

To view layer attributes:

  1. Right-click the Simple Features Layer object and click Open Attribute Table. This will open the attribute dialog.

In the attribute dialog you have several options for controlling which features to display. Some simple methods include:

  • To sort the features, click a column header.
  • To view only a subset of the attributes based on interactive selection: Use the mouse to select the attributes that you want to remain listed, then click View -> Selection Only.

We will now discuss more sophisticated filtering based on attribute filtering or geometric filtering.

Boundary region filtering

To list only attributes and geometries that are contain within a rectangular region:

  1. Ensure that the Boundary Rectangle tab is visible.
  2. Enter the boundary coordinates in the fields labeled Left, Top, etc.
  3. Click Execute. The attribute table will not list only features that are inside the boundary rectangle.

Geometric Filtering

You can also list features that have a certain geometrical relationship to a reference geometry in the clipboard. To perform this kind of filtering you will first need to locate the reference geometry in a layer and copy this to the clipboard. 

To perform geometric filtering:

  1. In the Geocap project locate the layer that contain the reference geometry
  2. Right-click the layer object and click Open Attribute Table
  3. In the attribute table, locate the feature containing the reference geometry. Select this feature and click the Copy Features button. Then click To Clipboard
  4. Close the attribute dialog and open instead the attribute dialog of the layer containg the geometry that you want to filter
  5. Click the Geometry filtering tab
  6. In the Filter features that... field select the comparison operation that you wish to employ
  7. Click Execute. The attribute table will now show only features that passed the geometrical filtering.

Attribute Filtering

You may filter features according to attribute values. To do this use the SQL WHERE editor to insert comparison statements that compares existing attribute values with values that you insert.

  1. In the attribute dialog, click the Attributes tab
  2. In the expression editor choose the layer column, comparison operator and value that you wish to use.
  3. Click the green check button to insert the statement into the editor.
  4. You can add more statements by separating them with the AND or OR operator.
  5. Click Execute to perform the filtering.

Viewing feature attributes

A single feature contains attributes such as attributes and geometry. To view feature attributes:

  1. Right-click a layer and click Open Attribute Table
  2. In the attribute table. Select a single attribute.
  3. Click Properties. The attribute information dialog will appear.

Viewing geometry area

To view the area of a closed geometry:

  1. Open the feature attribute dialog as described in #Viewing feature attributes
  2. In the attribute dialog click the Geometry tab
  3. The area will be display in the Area field. In most cases this value is meaningful only for geometries in a projected coordinate system.

Geometric Operations

Using the Attribute Dialog you can perform geometric operations like union, difference, and intersection between geometries.

To perform a union:

  1. Open the Attribute Dialog for the layer containing the geometries that you wish to operate on
  2. If necessary, perform any filtering required to limit the set of features on which the union will operate.
  3. Click the Analysis button, then click Union
  4. Select a name for the result layer and click OK
  5. A new layer containing only the union of the input layer will now be visible in the project manager.

To perform a difference:

  1. Open the Attribute Dialog for the layer containing the geometries that you wish to operate on
  2. If necessary, perform any filtering required to limit the set of features on which the difference operation will operate.
  3. Click the Analysis button, then click Difference or Symmetric Difference
  4. Select a name for the result layer and click OK
  5. A new layer containing only the differences between the geometries of the input layer will now be visible in the project manager.

There are two ways to perform an intersection.

  1. The intersection will be performed only between the geometries in a single layer.
  2. The intersection will be performed the geometries of a layer and an external reference geometry.

We will now discuss each of these methods in turn.

To perform an intersection only between geometries in a single layer:

  1. Open the Attribute Dialog for the layer containing the geometries that you wish to operate on
  2. If necessary, perform any filtering required to limit the set of features on which the intersection will operate.
  3. Click the Analysis button, then click Intersection
  4. Select Intersect listed features and click OK
  5. Select a name for the result layer and click OK
  6. A new layer containing only the intersection of the input layer will now be visible in the project manager.

When performing an intersection using an external reference geometry the following operation is performed by Geocap:

  1. For each geometry in the layer an intersection between that geometry and the external reference geometry is performed.
  2. At the end of the operation each intersection result is merged toghether using a union. This is the geometry that is stored in the result layer.

To perform an intersection using an external reference geometry:

  1. Open the Attribute Dialog for the layer containing the geometries that you wish to operate on
  2. If necessary, perform any filtering required to limit the set of features on which the intersection will operate.
  3. Click the Analysis button, then click Intersection
  4. Select Intersect listed features with geometric filter and click OK
  5. Select a name for the result layer and click OK
  6. A new layer containing the union of the intersections between the input layer and the reference geometry will now be visible in the project manager.

Saving a layer

Using the Attribute Dialog you may at any time save the visible features in a new layer:

  1. Click the Copy Features button and click To New Layer
  2. In the dialog that follow choose either to save all features as one layer or have each feature saved as separate layers. In the latter case, you should decide which column to use as layer name.
  3. Browse the target folder or data source.
  4. Click OK

Importing or exporting the feature geometry

Given a feature you may export only the geometry for that feature:

  1. Open the Attribute Dialog and select the feature in question.
  2. Click the Geometry button and click Export
  3. In the file dialog select format and filename.
  4. Click OK

You can replace the current geometry for a feature as follow:

  1. Open the Attribute Dialog and select the feature in question.
  2. Click the Geometry button and click Import
  3. In the file dialog select file.
  4. Click OK

Attribute Editing

There are two ways to modify attributes in a layer: Modify an existing attribute value or add a column to the layer.

To modify an existing attribute value:

  1. In the Attribute Dialog double click in the cell containing the attribute that you want to modify
  2. In the resulting dialog enter the new value and click OK

To add a column to a layer:

  1. Right-click on the Simple Features Layer object in the project manager and click Properties
  2. In the properties dialog click Add Field
  3. Choose whether to add a column to only the select layer or multiple layers
  4. If you choose to add to selected layer fill in the attribute properties.
  5. Of you choose to add to multiple layers choose which layers to add the column too. The column will not be added to a layer if it already exists.
  6. Click OK

Coordinate Systems

GIS data will often, but not always, be georeferenced. There is frequently a need to re-project georeferenced data to a new coordinate system or assign a coordinate system to data that is not georeferenced.

In this documentation the terms coordinate system and spatial reference system (SRS) are used interchangeably.

To view the existing coordinate system of geospatial vector files:

  1. Right-click on the Simple Features Layer object in the project manager and click Properties
  2. Select the Spatial Reference pane. This will list a well-known text representation of the spatial reference.

Coordinate system transformation

A layer that already has a coordinate system may be transformed to a new coordinate system as follows:

  1. Right-click on the Simple Features Layer object in the project manager and click Transform. The transformation wizard will appear.
  2. Choose Reproject and click Next
  3. The current coordinate system will be displayed.
  4. Insert any 3 or 7 to-wgs84 transformation parameters. If your transformation involves a datum shift Geocap will use these. You can ignore this if your transformation keeps the current datum. Click Next
  5. Define the target spatial reference. This can be done in one of several ways.
    1. You can select by browsing one of the existing coordinate systems. Simply Click the Browse button.
    2. You can choose one of the well-known coordinate system like WGS84 or NAD83 using the selection combo.
    3. You can define your own coordinate system by selecting WKT or Proj4 in the selection combo. You can then paste a WKT or Proj4 representation of the coordinate system into the text editor.
  6. For future use, you may want to assign ToWGS84 datum shift parameters to the target SRS. Doing so will not impact this transformation, but will be used for subsequent transformations involving datum shifts.
  7. Click Next
  8. Enter the name of the transformed result layer
  9. Click Finish
  10. The transformed layer will appear as a new layer in the data source.

To assign a coordinate system to a dataset that has no existing spatial reference:

  1. Right-click on the Simple Features Layer object in the project manager and click Transform. The transformation wizard will appear.
  2. Choose Assign without reprojecting and click Next
  3. The Source SRS page will be empty since no current SRS exists. You should also ignore the ToWGS84 datum shift parameters on this page. Click Next
  4. Define the target spatial reference. This can be done in one of several ways.
    1. You can select by browsing one of the existing coordinate systems. Simply Click the Browse button.
    2. You can choose one of the well-known coordinate system like WGS84 or NAD83 using the selection combo.
    3. You can define your own coordinate system by selecting WKT or Proj4 in the selection combo. You can then paste a WKT or Proj4 representation of the coordinate system into the text editor.
  5. For future use, you may want to assign ToWGS84 datum shift parameters to the target SRS. These parameters will be used for subsequent transformations involving datum shifts.
  6. Click Next
  7. Enter the name of the newly assigned result layer
  8. Click Finish
  9. The new layer will appear as a new layer in the data source.

SQL Queries

A Simple Feature Datasource is stored in Geocap as a SQLite database. Each layer in the data source corresponds to a table in the database. This allows you to manipulate the data using SQL statements. This section describes how to use SQL and the query wizard to create queries that operate on a Simple Feature Datasource.

Please consult the  SQLite SQL documentation for further details on SQL as understood by SQLite. Also used is the OGR dialect, which is documented here : The OGR SQL dialect

Executing a SQL Query

To perform a SQL query:

  1. Right-click on the Simple Features Datasource object in the project manager. Click SQL Query. The SQL editor will appear.
  2. Use the SQL dialog option to decide whether to use the restricted OGR-SQL dialect or native SQLite. Click the Help button on the right for more information on these dialects.
  3. Enter the SQL expression in the text editor and click Execute
  4. If the SQL query was a SELECT statement that returned a layer or a table the result will be listed.

Simple SELECT and COMPOUND SELECT

The SQL Wizard makes it easy to create SQL SELECT statement. There are two different types of SELECT statements that you can make using the wizard: Simple SELECT or compound select. Compound SELECT is not supported by the OGR-SQL dialect.

A simple SELECT statement contains a single SELECT like "SELECT ....".

SELECT name, area from table1

A compound SELECT contains two SELECT expressions joined by a UNION, INTERSECT or EXCEPT keyword. Each SELECT sub-clause returns a table. The two tables are then merged, intersected or subtracted depending on which keyword was used. Here is a short explanation of the types of compound SELECTs that you can create:

UNION or UNION ALL

A UNION compound SELECT expression will append the table resulting from the second SELECT expression to the table resulting from the first SELECT. It looks like this:

SELECT name, area from table1 UNION SELECT name, area from table2

In this example all rows from table1 and table2 will be merged to form a new table. Note that the number of columns of both SELECT expressions need to be the same. 

A UNION will discard duplicate rows, while a UNION ALL will keeps all rows including duplicates. 

INTERSECT

A compound SELECT using INTERSECT will keep all rows that are present in both tables:

SELECT name,  area from table1 INTERSECT SELECT name, area from table2

The table that result from this statement will contain only rows that are present in both table1 and table2. Again, both SELECT expression need to extract the same number of columns.

EXCEPT

A compound expression using EXCEPT is conceptually similar to subtracting one table from another. For example, the following statement will subtract the rows of table2 from table1:

SELECT name,  area from table1 EXCEPT SELECT name, area from table2

Using the SQL Wizard

To create a simple SELECT using the SQL Wizard:

  1. Open the SQL query editor
  2. Click the SQL Wizard button and click SELECT. The SQL Wizard will appear.
  3. Choose Simple SELECT and click Next
  4. In the SQL dialect page, choose the native SQLite dialect. Click Next.
  5. For each table to use as input: Select the table using the mouse, then click Add. Double click in the Alias column to use a table alias instead of the real name. Click Next when you have added all the tables that you wish to use in the query.
  6. Select the columns that will appear in the result table. Double-click in the Alias column to enter a column alias. Click Next when you're done.
  7. The WHERE page allows you to restrict the row extraction based on comparison of table values. Using a WHERE clause is optional. If you omit a WHERE clause all rows will be read from the tables. Choose the column and value to compare along with the comparison operator. Click the green check button to add the clause to the editor. You can have several clauses separated by AND or OR. Click *Next when you are done.
  8. The rows of the result table can be ordered using one or more sort columns. If you have more than one sort column the extra columns will be used for secondary sorting if two or more rows in the previous column contains the same value. Using sort columns is optional.
  9. In the last page of the wizard you may verify or modify the resulting SQL expression. Click Finish.
  10. The SQL expression created by the wizard will now be inserted in the SQL query editor. You may make any modifications that you wish before executing the statement using the Execute button.

To create a compound SELECT using the SQL Wizard:

  1. Open the SQL query editor
  2. Click the SQL Wizard button and click SELECT. The SQL Wizard will appear.
  3. Choose Compound SELECT and choose the type of compound express you wish to use (UNION, INTERSECT or EXCEPT).
  4. In the SQL dialect page click Next.
  5. On the table selection page, choose the tables for will be used in each select clause. Each SELECT can have more than one table as input. Click Next.
  6. Select the columns that will appear in the result table. Double-click in the Alias column to enter a column alias. The number of columns in each SELECT need to be the same. Click Next when you're done.
  7. The wizard will now present pages where you can define a WHERE clause for the first and second SELECT. The WHERE page allows you to restrict the row extraction based on comparison of table values. Using a WHERE clause is optional. If you omit a WHERE clause all rows will be read from the tables. Choose the column and value to compare along with the comparison operator. Click the green check button to add the clause to the editor. You can have several clauses separated by AND or *OR.
  8. In the last page of the wizard you may verify or modify the resulting SQL expression. Click Finish.
  9. The SQL expression created by the wizard will now be inserted in the SQL query editor. You may make any modifications that you wish before executing the statement using the Execute button.

Comparing tables

Compound SELECTs make it easy to compare two tables or layers. You can choose to compare attribute values, geometry or both. The table comparison wizard lets you interactively set up which tables to compare.

To compare two tables:

  1. Open the SQL query editor
  2. Click the SQL Wizard button and click Compare Tables. The welcome page of the table comparison will appear. Click Next.
  3. Select the two tables that you wish to compare.
  4. In the report page, select whether to compare attributes, geometry or features IDs (FID).
  5. In the operation selector you can select which tables will constitute the operands of the comparison expression. Note that the EXCEPT operator is not symmetrical: table1 EXCEPT table2 is generally not the same as table2 EXCEPT table1.
  6. Click Finish
  7. Make any final modifications to the SQL statement in the SQL query editor
  8. Click Execute. The result table will be listed in the editor.

Â