This page is an FDO Code Snippet. Visit the CodeSnippets page to view more!
Calculating Static Extents
Some providers require that you perform a SelectAggregates on a dataset to determine its extents, specifiying the SpatialExtents function as one of the properties to calculate.
C++ Example
FdoPtr<FdoISelectAggregates> agg = (FdoISelectAggregates*)con->CreateCommand(FdoCommandType_SelectAggregates); agg->SetFeatureClassName(L"MyFeatureClass"); FdoPtr<FdoIdentifierCollection> props = agg->GetPropertyNames(); FdoPtr<FdoExpression> exp = FdoExpression::Parse(L"SpatialExtents(GEOMETRY)"); FdoPtr<FdoComputedIdentifier> se = FdoComputedIdentifier::Create(L"Extents", exp); props->Add(se); FdoPtr<FdoIDataReader> extrdr = agg->Execute(); extrdr->ReadNext(); FdoPtr<FdoByteArray> ba = extrdr->GetGeometry(L"Extents"); //ba contains the extents polygon, in FGF array form, use FdoIGeometry APIs to get the numbers out of it.
C# Example
public IPolygon GetExtents()
{
IPolygon retpolygon;
ISelectAggregates pselagree = (ISelectAggregates)FDOConnection.CreateCommand(CommandType.CommandType_SelectAggregates);
pselagree.SetFeatureClassName(System.IO.Path.GetFileNameWithoutExtension(OpenedFile)); // Path and name of the shape file....
IdentifierCollection props = pselagree.PropertyNames;
Expression exp = Expression.Parse("SpatialExtents(Geometry)");
ComputedIdentifier se = new ComputedIdentifier("Extents", exp);
props.Add(se);
IDataReader FDOReader = pselagree.Execute();
FgfGeometryFactory GeoFac = new FgfGeometryFactory();
FDOReader.ReadNext();
Byte[] Tmppts = FDOReader.GetGeometry("Extents");
IGeometry Geo = GeoFac.CreateGeometryFromFgf(Tmppts);
retpolygon = (IPolygon)Geo;
return retpolygon;
}
Contributors
- Traian Stanev
- Shaik Esu
