MSSQL Spatial and MSSQL Azure Spatial Writer: Format Parameters
To access format parameters, open the Feature Type Properties dialog by clicking the properties button on a feature type in the workspace. These parameters are applicable only to the selected feature type.
Table Settings: General
This parameter lets the user specify how features will be written into the destination table. Supported feature operations are:
- Insert: Append rows onto the destination table using attributes on features.
- Update: Update existing table columns using attributes on features. A selection method must be specified in the Row Selection group.
- Delete: Delete existing table rows. A selection method must be specified in the Row Selection group.
- fme_db_operation: The feature operation will be determined by the attribute fme_db_operation on each input feature. A selection method must be specified in the Row Selection group. The value of fme_db_operation will be processed as follows:
- If the value is null, empty, or missing, it will be treated as Insert.
- The value will next be matched to Insert, Update, and Delete, case insensitively.
- If there is no match, the feature will be rejected.
- If there is a match, the matched feature operation will be performed on the feature.
Tip: Unlike in previous versions of FME, the fme_db_operation attribute will now cause feature rejection when Feature Operation is set to Insert, Update, or Delete. This behavior differs from previous versions of FME.
More information on Feature Operations.
Controls how the feature type handles destination tables or lists. These options are available:
- Use Existing: If destination table/list does not exist, the translation will fail.
- Create If Needed: Create destination table/list if it does not exist.
- Drop and Create: Drop destination table/list if it exists, and then create it.
- Truncate Existing: If destination table/list does not exist, the translation will fail. Otherwise, delete all rows from existing table or list. This option is not available for all formats.
When updating features, users have a choice to update, or skip, their spatial column(s). Possible options are:
- Yes: The spatial column(s) specified by the user will be updated. IFMENulls will be written as null values and replace existing spatial values.
- No: No spatial columns will be updated.
Row Selection
When inserting into a table, Row Selection is ignored. When updating and deleting from a table, a condition needs to be specified for selecting which rows to operate on. This parameter group offers two methods to construct the selection condition:
The columns specified in the corresponding column picker dialog will be used for matching destination rows. All matching rows will be selected for update or delete. If any feature attributes corresponding to the specified match columns contain null or missing values, the feature will be rejected.
The corresponding WHERE Clause Builder lets you construct a WHERE clause. You can also type in a WHERE clause inline, without launching the WHERE Clause Builder. It is optional to start the clause with the keyword WHERE.
The WHERE Clause Builder makes it easy for users to reference feature attribute values, destination table columns, and invoke FME functions. The WHERE clause is first evaluated as an FME expression, before being passed onto the destination database.
If the WHERE clause is incorrect or if its evaluation results in failure, translation will fail. Otherwise, if the WHERE clause passes FME evaluation but it is SQL invalid, the feature will be rejected or the translation will fail.
For advanced users, conditional FME expressions created through the Conditional Value editor can be used to create WHERE clauses.
Tip: You can set the WHERE Clause to an attribute. This supports workspace migration and existing workflows involving fme_where. (Direct support for fme_where has been deprecated.) To advanced users who are accustomed to using fme_where, if Feature Operation is set to Update, Delete, or fme_db_operation, an fme_where attribute that conflicts with Match Columns or WHERE Clause will result in feature rejection.
Table Creation Parameters
Note: The parameters in this section take effect only when FME creates a table.
This parameter specifies how a spatial index is to be created for the specified Spatial Column.
- None: No spatial index will be created for this table.
- Manual: The SQL statement specified for the Spatial Index Creation SQL parameter will be executed.
- Auto: A spatial index will be created automatically for geographies, and semi-automatically for geometries. This automation is available only on SQL Server 2012 and later with database compatibility mode of SQL Server 2012 or higher.
- Geographies: No other information is required. A bounding box can be optionally specified.
- Geometries: A bounding box is required for spatial index creation. The bounding box is specified in Bounding Box (Geometry Only).
Note: If you are using a SQL (Azure) Server whose database compatibility level is set to 2012 or higher, consider setting Spatial Index Type to Auto to avoid specifying a custom SQL. See Spatial Index Type above for details.
Due to the complexity of spatial index creation, FME lets the user specify a SQL statement to create an index on a specific spatial column in a Microsoft SQL Server Spatial table. Normally, this table would be the destination table specified by the feature type.
In the example below, a default spatial index is created on geometry column GEOM of table my_table:
CREATE SPATIAL INDEX SIDX_GEOM ON my_table(GEOM) WITH (BOUNDING_BOX = (-200, -200, 200, 200))
In the example below, a spatial index is created on geography spatial column GEOG of my_table:
CREATE SPATIAL INDEX [SIDX_GEOG] ON my_table(GEOG) USING GEOGRAPHY_GRID WITH (GRIDS = (LOW, MEDIUM, HIGH, HIGH), CELLS_PER_OBJECT = 32)
Tip: To recreate a spatial index on an existing table, execute a SQL statement inside a SQLCreator Workbench transformer. Using the above example, the SQL statement would look like:
CREATE SPATIAL INDEX [SIDX_GEOG] ON my_table(GEOG) USING GEOGRAPHY_GRID WITH (GRIDS = (LOW, MEDIUM, HIGH, HIGH), CELLS_PER_OBJECT = 32, DROP_EXISTING=ON)
See the MSDN article CREATE SPATIAL INDEX (Transact-SQL) for more information and examples.
These parameters together specify a bounding box for geometries, and
optionally for geographies, for spatial index creation.
- Minimum X: The x-coordinate of the bottom left corner of the bounding box.
- Minimum Y: The y-coordinate of the bottom left corner of the bounding box.
- Maximum X: The x-coordinate of the top right corner of the bounding box.
- Maximum Y: The y-coordinate of the top right corner of the bounding box.
Table Settings: Spatial
This parameter determines whether the column specified by Spatial Column contains Geometry or Geography values. Inherit From Writer causes the feature type to retrieve the value of Spatial Type from the writer parameter Spatial Type.
This parameter specifies the name of a spatial column. If this parameter is left empty, it will inherit from the writer parameter Spatial Column.
Table Settings: Advanced
This parameter determines how FME aggregates and multi's will be interpreted and handled. Because there is not a one to one mapping between FME collections and SQL Server collections, care should be taken when input features contain spatial collections.
The option Preserve Collection Types will interpret FME multi's as OGC multi's when such an interpretation is geometrically lossless, and as OGC GeometryCollections otherwise. This option preserves the collection type only. It does not promise that the resulting OGC multi or GeometryCollection will be simple or valid.
The option Simplify Collection Types will interpret homogeneous FME collections as OGC multi's when such an interpretation is geometrically lossless, and GeometryCollections otherwise. It does not promise that the resulting OGC multi or OGC GeometryCollection will be simple or valid. Homogeneous FME collections refer to IFMEMulti's, and single level IFMEAggregates that can be converted into IFMEMulti's without loss of geometry.
The option Simplify To Valid Collection Types will interpret homogeneous FME collections as OGC multi's when such an interpretation is geometrically lossless, and additionally when these OGC multi’s are SQL Server valid. FME collections that are SQL Server invalid are interpreted as GeometryCollections. Further:
- This option will have the effect of repairing some homogeneous collections that are SQL Server invalid. For example, if an IFMEMultiArea contains overlapping polygons that are individually SQL Server valid, then interpreting such an IFMEMultiArea as a GeometryCollection will remove the invalidity.
- This option is unable to repair homogeneous FME collections whose parts are individually SQL Server invalid.
- This option considers destination spatial column types. An FME collection that is SQL Server valid as a geometry may not be SQL Server valid as a geography, and vice-versa.
All three options are recursive; they apply to nested FME collections.
When the writer parameter Handle Multiple Spatial is set to No, Multiple Geometries are treated as FME collections. When Handle Multiple Spatial is set to Yes, the parts of a top-level Multiple Geometry are interpreted as distinct spatial columns, and each of these parts are handled separately.
When inserting features, this parameter determines whether or not identity columns are auto-populated.
Identity columns are columns whose values are automatically populated by the database server in sequence. This parameter allows you to override this behavior and provide the values.
There can be, at most, one identity column specified per table.
- If an identity column has been specified, the option Yes populates the destination identity column with values from the feature attribute that corresponds to the identity column.
- The option No causes the destination identity column to be auto-populated by the database server.
This parameter does not affect other feature operations.
Note: Note: Only one feature type may have this option enabled for a given MSSQL connection; all feature types within a writer share a connection, and connections may be shared between writers if they use the same connection parameters.
For more information on Identity Columns, see the Microsoft Developer Network topic IDENTITY (Property) (Transact-SQL).