Home    |    Concepts   |   API   |   Samples
Concepts > Schema Objects > Layers
Managing Spatial Columns
Spatial columns are added to tables to store geometric values for a feature. The spatial column has associated metadata maintained in the LAYERS (or SDE_layers) table. This information defines the type of geometric shapes that may be stored in a spatial column, the coordinate reference system, spatial index values, update privileges, and so on.

You access and update layer metadata through an opaque pointer to an SE_LAYERINFO object. Most characteristics are user-defined, but a few, such as the layer ID and creation date, are set by the ArcSDE software. Before working with a spatial column (or layer), you must initialize an SE_LAYERINFO object with SE_layerinfo_create.

Adding a new spatial column

Spatial columns are created by the SE_layer_create function. This function adds the new spatial column to the business table, adds a record to the LAYERS table, and creates the background tables that store the shape data and sets up the required database triggers if using a binary schema implementation. To add a spatial column to a table, you must be the owner of the table.

If an existing column is to be redefined as a spatial column, it must have the following characteristics:

* It must be an integer column.
* It cannot be defined as NOT NULL.
* It must not currently contain any non-NULL values.

The information required for layer creation is supplied through an SE_LAYERINFO opaque pointer. Before you call SE_layer_create, you must use SE_layerinfo_create to initialize the SE_LAYERINFO structure. Some of the layer information must be provided by the application, and some values are supplied by ArcSDE when the layer is created. The application can set the layer parameters with various SE_layerinfo_set_* functions.

Layer operations

Applications must be able to interact with the layer object. Possible operations include creating an ArcSDE layer by spatially enabling a table, deleting an ArcSDE layer by removing spatial data from a table, retrieving information about the layer including the types of features, and accessing layers by table name or number. In addition to layer administration functions, there are layer utility functions, such as a layer envelope calculation function.

In the following example, the cities table is spatially enabled by adding the boundary spatial column:

/* Create a coordinate reference system structure. */
rc = SE_coordref_create (&coordref);

/* See Error handling section for check_error function code. */
check_error(Connection, NULL, rc, "SE_coordref_create");

rc = SE_coordref_set_xy (coordref, 512.0, 280.0, 100.0);
check_error(Connection, NULL, rc, "SE_coordref_set_xy");

/* Initialize the layerinfo structure */
rc = SE_layerinfo_create(coordref, &layer);
check_error(Connection, NULL, rc, "SE_layerinfo_create");

/* Set the required parameters to create a layer: spatial column,
the shape entity types, and a spatial index grid size */
rc = SE_layerinfo_set_spatial_column (layer, "cities", "boundary");
check_error(Connection, NULL, rc, "SE_layerinfo_set_spatial_column");

rc = SE_layerinfo_set_shape_types (layer, SE_AREA_TYPE_MASK);
check_error(Connection, NULL, rc, "SE_layerinfo_set_shape_types");

rc = SE_layerinfo_set_grid_sizes (layer, 10000.0, 0.0, 0.0);
check_error(Connection, NULL, rc, "SE_layerinfo_set_grid_sizes");

/* Use the CITIES dbtune.sde configuration keyword to specify
DBMS storage parameters. This is optional. */
rc = SE_layerinfo_set_creation_keyword (layer, "CITIES");
check_error(Connection, NULL, rc, "SE_layerinfo_set_creation_keyword");

/* Create the layer */
rc = SE_layer_create (Connection, layer, 0, 0);
check_error(Connection, NULL, rc, "SE_layer_create");

Deleting a spatial column

Spatial columns are deleted using the SE_layer_delete function. This function deletes the spatial column entry in the LAYERS table, drops the feature and spatial index tables associated with the layer, and nullifies the contents of the spatial index column in the business table. Deleting a layer does not delete the business table, it just NULLS the spatial column.

This example deletes a spatial column named Boundary in a table named Parcels:

/* Delete the spatial column */

rc = SE_layer_delete(Connection, "Parcels", "Boundary");

check_error(Connection, NULL, rc, "SE_layer_delete");

You can retain the layer definition but remove the shape data with the SE_layer_truncate function.

/* Truncate the spatial column */

rc = SE_layer_truncate(Connection, "Parcels", "Boundary");

check_error(Connection, NULL, rc, "SE_layer_truncate");

feedback | privacy | legal