A spatial context specifies a coordinate system and an extent for a set of geometries. The spatial context object has a Name property. The value of the Name property is assigned to the SpatialContextAssociation property of the GeometricPropertyDefinition object that defines a feature or non-feature geometry belonging to a feature class. In this way a coordinate system and extent is associated with geometry values inserted into the data store as part of instances of the class. Example code showing this association is contained in the Basic Schema Operations
It is worth emphasizing that each geometric property definiton in a feature class definition can have a different spatial context. This mechanism replaces that of the active spatial context.
The data stores created by the Oracle, Sql Server, MySQL, and optionally, the SQL Server Spatial providers contain metadata that supports the assignment of a default spatial context to a Geometric Property Definition during schema creation in the event that the user has not explicitly assigned one. The attribute values of the default spatial context are set out in the following table.
| Attribute | Value |
|---|---|
| Name | Default |
| CoordinateSystem | <no value> |
| CoordinateSystemWkt | <no value> |
| ExtentType | SpatialContextExtentType_Static |
| Extent | POLYGON((-2000000 -2000000, 2000000 -2000000, 2000000 2000000, -2000000 2000000, -2000000 -2000000)) |
The code samples show how to create a spatial context and how to get the spatial contexts from a data store.
The following namespaces are used:
// get the spatial contexts from a data store
IGetSpatialContexts getSpatialContexts = connection.CreateCommand(CommandType.CommandType_GetSpatialContexts) as IGetSpatialContexts;
ISpatialContextReader reader = getSpatialContexts.Execute();
string name = null;
string coordSys = null;
string wellKnownText = null;
string desc = null;
FgfGeometryFactory geomFactory = new FgfGeometryFactory();
IGeometry geom = null;
string extent = null;
SpatialContextExtentType extentType;
double xyTolerance;
double zTolerance;
while (reader.ReadNext())
{
name = reader.GetName();
coordSys = reader.GetCoordinateSystem();
wellKnownText = reader.GetCoordinateSystemWkt();
desc = reader.GetDescription();
geom = geomFactory.CreateGeometryFromFgf(reader.GetExtent());
extent = geom.Text;
extentType = reader.GetExtentType();
xyTolerance = reader.GetXYTolerance();
zTolerance = reader.GetZTolerance();
}
reader.Dispose();
// create a spatial context whose coordinate system is WGS84 and whose extent is the maximum // create the extent DirectPositionImpl lowerLeft = new DirectPositionImpl(); lowerLeft.X = -180.0; lowerLeft.Y = -90.0; DirectPositionImpl upperRight = new DirectPositionImpl(); upperRight.X = 180.0; upperRight.Y = 90.0; IEnvelope envelope = geomFactory.CreateEnvelope(lowerLeft, upperRight); IGeometry geom = geomFactory.CreateGeometry(envelope); byte[] extent = geomFactory.GetFgf(geom); ICreateSpatialContext createSpatialContext = connection.CreateCommand(CommandType.CommandType_CreateSpatialContext) as ICreateSpatialContext; createSpatialContext.CoordinateSystem = ""; createSpatialContext.CoordinateSystemWkt = wgs84Wkt; createSpatialContext.Description = "This Coordinate System is used for GPS."; // a static extent is defined once and never changed // a dynamic extent grows to accommodate the geometries added to the data store createSpatialContext.ExtentType = SpatialContextExtentType.SpatialContextExtentType_Static; createSpatialContext.Extent = extent; // the value of Name is assigned to the SpatialContextAssociation attribute of a GeometricPropertyDefinition object during the creation of the logical feature schema // in this way a coordinate system and extent is associated with the geoemtries createSpatialContext.Name = "WGS84 Spatial Context"; createSpatialContext.Execute();