Reader Directives
The directives that are processed by the PostGIS reader are listed below. The suffixes shown are prefixed by the current <ReaderKeyword>_ in a mapping file. By default, the <ReaderKeyword> for the PostGIS reader is POSTGIS_IN.
DATASET/DATABASE
This directive specifies the name of the PostGIS-enabled PostgreSQL database. The database must exist in the ORDBMS.
Required/Optional
Required
Mapping File Syntax
POSTGIS_DATASET testdb
Workbench Parameter
Source PostGIS Dataset
HOST
This directive specifies the machine running the PostGIS/PostgreSQL ORDBMS as either an IP address or host name. The database must have proper permissions and be set up to accept TCP/IP connections if connecting from a remote machine.
Required/Optional
Required
Mapping File Syntax
POSTGIS_IN_HOST myserver
Workbench Parameter
Host
PORT
When connecting remotely, this directive specifies the TCP/IP port on which to connect to the ORDBMS service.
The default port is 5432.
Required/Optional
Required
Mapping File Syntax
POSTGIS_IN_PORT 5432
Workbench Parameter
Port
USER_NAME
The name of user who will access the database. The named user must exist with appropriate PostgreSQL permissions.
The default user name is postgres
.
Required/Optional
Required
Mapping File Syntax
POSTGIS_IN_USER_NAME postgres
Workbench Parameter
Username
PASSWORD
The password of the user accessing the database. This directive is optional when using a trusted connection.
Other authentication types such as password or MD5 require this parameter to be set.
Required/Optional
Optional
Mapping File Syntax
POSTGIS_IN_PASSWORD secret
Workbench Parameter
Password
DEF
The syntax of the definition is:
POSTGIS_DEF <tableName> \ [postgis_where_clause <whereClause>] \ [<fieldName> <fieldType>] +
OR
POSTGIS_DEF <queryName> \ [postgis_sql_statement <sqlQuery>]
The <tableName> must match a PostGIS table in the database. This will be used as the feature type of all the features read from the table. The exception to this rule is when using the sql_statement directive. In this case, the DEF name may be any valid alphabetic identifier; it does not have to be an existing table name – rather, it is an identifier for the custom SQL query. The feature type of all the features returned from the SQL query are given the query name.
The <fieldType> of each field must be given, but it is not verified against the database definition for the field. In effect, it is ignored.
The exception to this is the geometry field type which is not placed in the DEF. This is stored separately in the geometry_columns table of the PostgreSQL database which maps geometry information to the database and table name.
The definition allows specification of separate search parameters for each table. If any of the configuration parameters are given, they will override, for that table, whatever global values have been specified by the reader directives listed above. If any of these parameters is not specified, the global values will be used.
The following table summarizes the definition line configuration parameters:
Parameter |
Contents |
where_clause |
This specifies the SQL WHERE clause applied to the attributes of the layer’s features to limit the set of features returned. If this is not specified, then all the tuples are returned. This directive will be ignored if the sql_statement is present. |
sql_statement |
This specifies an SQL SELECT query to be used as the source for the results. If this is specified, the PostGIS reader will execute the query, and use the resulting rows as the features instead of reading from the table <queryName>. All returned features will have a feature type of <queryName>, and attributes for all columns selected by the query. All parameters that specify a spatial constraint are ignored if an sql_statement is supplied. If selecting a geometry column from a PostGIS table, avoid the use of geometry column format modifiers such as AsBinary(), AsText(), AsWKT(), or ASWKB() since this obscures the fact that we have a geometry column and not just some text or byte attribute column. |
If no <whereClause>
is specified, all rows in the table will be read and returned as individual features. If a <whereClause>
is specified, only those rows that are selected by the clause will be read. Note that the <whereClause> does not include the word “where”.
The PostGIS reader allows one to use the sql_statement parameter to specify an arbitrary SQL SELECT query on the DEF line. If this is specified, FME will execute the query, and use each row of data returned from the query to define a feature. Each of these features will be given the feature type named in the DEF line, and will contain attributes for every column returned by the SELECT. In this case, all DEF line parameters regarding a WHERE clause or spatial querying are ignored, as it is possible to embed this information directly in the text of the <sqlQuery>.
The following example selects rows from the table ROADS, placing the resulting data into FME features with a feature type of MYROADS. Imagine that ROADS defines the geometry for the roads, and has a numeric field named ID, a text field named NAME and a geometry column named GEOM.
POSTGIS_DEF MYROADS \ sql_statement ‘SELECT id, name, geom FROM ROADS’
Required/Optional
Required
IDs
This optional specification is used to limit the available and defined database tables files that will be read. If no IDs are specified, then no tables are read. The syntax of the IDs directive is:
POSTGIS_IDs <featureType1> \ <featureType2> \ <featureTypeN>
The feature types must match those used in DEF lines.
The example below selects only the ROADS table for input during a translation:
POSTGIS_IDs ROADS
Required/Optional
Optional
MINX, MINY, MAXX, MAXY
These directives when used together specify the spatial extent of the feature retrieval. Only features that interact with the bounding box defined by these directive values are returned.
If this is not supplied, all features will be returned. If either min value is greater than the corresponding max value, the values will be swapped. If less than the entire set of four values are supplied, the supplied values will be ignored and all features will be returned.
The syntax of the directives is:
POSTGIS_IN_MINX <minX> POSTGIS_IN_MINY <minY> POSTGIS_IN_MAXX <maxX> POSTGIS_IN_MAXY <maxY>
The example below selects a small area for extraction:
POSTGIS_IN_MINX 25.6 POSTGIS_IN_MINY 59.0 POSTGIS_IN_MAXX 79.2 POSTGIS_IN_MAXY 124.5
Required/Optional
Optional
SEARCH_ENVELOPE
Using the minimum and maximum x and y parameters, define a bounding box that will be used to filter the input features. Only features that interact with the bounding box are returned.
If all four coordinates of the search envelope are specified as 0, the search envelope will be disabled.
Mapping File Syntax
<ReaderKeyword>_SEARCH_ENVELOPE <minX> <minY> <maxX> <maxY>
Note: If all four coordinates of the search envelope are specified as zero, the search envelope will be disabled.
Required/Optional
Optional
Workbench Parameter
Minimum X, Minimum Y, Maximum X, Maximum Y
SEARCH_ENVELOPE_COORDINATE_SYSTEM
This directive specifies the coordinate system of the search envelope if it is different than the coordinate system of the data.
The COORDINATE_SYSTEM
directive, which specifies the coordinate system associated with the data to be read, must always be set if the SEARCH_ENVELOPE_COORDINATE_SYSTEM
directive is set.
If this directive is set, the minimum and maximum points of the search envelope are reprojected from the SEARCH_ENVELOPE_COORDINATE_SYSTEM
to the reader COORDINATE_SYSTEM
prior to applying the envelope.
Required/Optional
Optional
Mapping File Syntax
<ReaderKeyword>_SEARCH_ENVELOPE_COORDINATE_SYSTEM <coordinate system>
Workbench Parameter
Search Envelope Coordinate System
CLIP_TO_ENVELOPE
This directive specifies whether or not FME should clip features to the envelope specified in the SEARCH_ENVELOPE
directive.
Values
YES | NO (default)
Mapping File Syntax
<ReaderKeyword>_CLIP_TO_ENVELOPE [yes | no]
Workbench Parameter
Clip To Envelope
SEARCH_METHOD
This directive is used to specify the spatial relationship between the provided bounding box and the geometries in the geometry column of the table.
There are two types of operation:
- Maximum Bounding Rectangle (MBR) operations determine adherence to a given spatial relationship using only the bounding box of the geometry.
- Full spatial operations will use the actual geometry itself.
Full spatial relationship comparisons are only available if GEOS is enabled on the PostGIS server. If not, all envelope comparisons will be made using the default MBR operation MBR_OVERLAPS
.
Required/Optional
Optional
Mapping File Syntax
POSTGIS_IN_SEARCH_METHOD <spatial_relationship>
Workbench Parameter
Search Method
FEATURES_PER_FETCH
To avoid loading all the features in memory at once when reading a large dataset, cursors are used to retrieve the rows from the database. This optional directive specifies the number or rows to be read at one time from the cursor for a given query.
The default is 10000 rows and should be sufficient in most cases. However this may need to be lowered or raised depending on the capabilities of the specific hardware in use and the data being read.
Required/Optional
Optional
Mapping File Syntax
The example below selects a small set of features per extraction:
POSTGIS_IN_FEATURES_PER_FETCH 5000
Workbench Parameter
Number of Records to Fetch at a Time
RETRIEVE_ALL_SCHEMAS
This parameter is applicable only when generating a mapping file, generating a workspace, or when retrieving schemas in an FME Objects application.
When set to yes, schemas for all of the tables and feature classes in the database are returned.
When set to no (or missing), and if RETRIEVE_ALL_TABLE_NAMES
is similarly set to no (or missing), only schemas requested by the IDs parameter are returned.
Required/Optional
Optional
Values
YES | NO (default)
NO: The reader will return the schemas for the feature types specified in the IDs. If no features are specified in IDs, then:
- for Enterprise Geodatabases, FME will not return any schema features;
- for Personal and File Geodatabases, FME returns the schema features for all the tables.
If this value is not specified, then it is assumed to be No.
YES: Indicates to the reader to return all the schemas of the tables in the database.
Mapping File Syntax
Not applicable.
FME Objects applications would include RETRIEVE_ALL_SCHEMAS
followed by “YES” in the parameters array passed to IFMEUniversalReader::open()
.
Workbench Parameter
Not applicable
RETRIEVE_ALL_TABLE_NAMES
This parameter is only applicable when generating a mapping file, generating a workspace or when retrieving schemas in an FME Objects application.
When set to yes, and if RETRIEVE_ALL_SCHEMAS
is set to no (or missing), names for all of the tables and feature classes in the database are returned. When set to no (or missing), and if RETRIEVE_ALL_SCHEMAS
is similarly set to no (or missing), the schemas requested by the IDs directive are returned.
Note: If RETRIEVE_ALL_SCHEMAS is also set to Yes, then RETRIEVE_ALL_SCHEMAS takes precedence.
Required/Optional
Optional
Values
YES | NO (default)
Mapping File Syntax
Not applicable.
FME Objects applications would include RETRIEVE_ALL_TABLE_NAMES
followed by “YES” in the parameters array passed to IFMEUniversalReader::open()
.
Workbench Parameter
Not applicable (used when you browse a Table List)
Required/Optional
Optional
Values
YES | NO
If this value is not specified, then it is assumed to be No.
Required/Optional
Optional
Mapping File Syntax
POSTGIS_RETRIEVE_ALL_TABLE_NAMES Yes
DISABLE_COLLECTION_SPLITTING
Specifies that the reader should not split single item multis or geometrycollections with any number of parts.
If geometrycollections are split, each part is tagged with postgis_collection_id and postgis_collection_part_id attributes.
Required/Optional
Optional
Values
YES (default) | NO
Not setting this directive is equivalent to setting it to NO.
Mapping File Syntax
POSTGIS_DISABLE_COLLECTION_SPLITTING Yes
USE_TRUE_POSTGIS_TYPES
Required/Optional
Optional
Values
YES (default) | NO
If not present or not set to YES, only the legacy postgis types (postgis_point, postgis_line, postgis_area, postgis_geometrycollection) will be attached to features.
If set to YES postgis_line is replaced by postgis_linestring, postgis_area is replaced by postgis_polygon, and types representing curve supporting geometries are also available.
Mapping File Syntax
POSTGIS_USE_TRUE_POSTGIS_TYPES Yes
EXPOSED_ATTRS
This directive allows the selection of format attributes to be explicitly added to the reader feature type.
This is similar to exposing format attributes on a reader feature type once it has been generated; however, it is even more powerful because it enables schema-driven applications other than Workbench to access and leverage these attributes as if they were explicitly on the schema as user attributes.
The result of picking a list of attributes is a comma-separated list of attribute names and types that will be added to the schema features. Currently all reader feature types will receive the same set of additional schema attributes for a given instance of the reader.
Required/Optional
Optional
Mapping File Syntax
Not applicable.
While it is possible for FME Objects applications to invoke this directive, the required format is not documented.
This directive is intended for use in our GUI applications (for example, Workbench) only.
Workbench Parameter
Additional Attributes to Expose