wiki:CodeSnippets/GetStaticExtents

Version 1 (modified by jbirch, 16 years ago) ( diff )

--

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));
    IFeatureReader FDOReader = pselagree.Execute();
    FgfGeometryFactory GeoFac = new FgfGeometryFactory();

    Byte[] Tmppts = FDOReader.GetGeometry("Geometry");

    IGeometry Geo = GeoFac.CreateGeometryFromFgf(Tmppts);

    retpolygon = (IPolygon)Geo;

    return retpolygon;

  }

Contributors

  • Traian Stanev
  • Shaik Esu
Note: See TracWiki for help on using the wiki.