AutoCAD Map 3D 2009 Geospatial Platform Reference

AutoCAD Map 3D Geospatial Platform API

MgSpatialContextReader Class Reference
[MgSpatialContextReader]

Inherits MgSerializable.

List of all members.


Detailed Description

Provides forward-only, read-only functionality for enumerating spatial context information retrieved from a feature source.

Remarks:
You must call MgSpatialContextReader::ReadNext before you can access any data.
Example (PHP)
 <?php
 function printSpatialContextReader($spatialContextReader)
 {
    global $agfReaderWriter;
    global $logFileHandle;
    while ($spatialContextReader->ReadNext())
    {
       $name = $spatialContextReader->GetName();
       if ($name == NULL)
           $name = "null";

       fwrite($logFileHandle, "Spatial Context Name: "$name"n");
       $description = $spatialContextReader->GetDescription();
       if ($description == NULL)
           $description = "null";

       fwrite($logFileHandle, "Description: "$description"n");
       $coordSysName = $spatialContextReader->GetCoordinateSystem();
       if ($coordSysName == NULL)
           $coordSysName = "null";

       fwrite($logFileHandle, "Coordinate System Name: "$coordSysName"n");
       $coordSysWkt = $spatialContextReader->GetCoordinateSystemWkt();
       if ($coordSysWkt == NULL)
           $coordSysWkt = "null";

       fwrite($logFileHandle, "Coordinate System WKT: "$coordSysWkt"n");
       $extentType = $spatialContextReader->GetExtentType();
       fwrite($logFileHandle, "Extent Type: " . printExtentType($extentType) . "n");
       $extentByteReader = $spatialContextReader->GetExtent();
       if ($extentByteReader == NULL)
       {
          fwrite($logFileHandle, "MgSpatialContextReader::GetExtent() returned a NULL objectn");
       }
       else
       {
          $extentGeometry = $agfReaderWriter->Read($extentByteReader);
          printAGeometry($extentGeometry);
       }
       $XYTolerance = $spatialContextReader->GetXYTolerance();
       fwrite($logFileHandle, "XY Tolerance: $XYTolerancen");
       $ZTolerance = $spatialContextReader->GetZTolerance();
       fwrite($logFileHandle, "Z Tolerance: $ZTolerancen");
       $isActive = $spatialContextReader->IsActive();
       fwrite($logFileHandle, "Is Active: " . prtBool($isActive) . "n");
    }
 }
 ?>

Note:
See the FdoSpatialContextList XML schema for the specification of the contents of the information about a spatial context.
Example (C#)

The DescSpatialContexts method formats the contents of the MgSpatialContextReader as a string for testing purposes. The CoordSysWktToTypeAndName method extracts the coordinate system name and type from the well-known text specification of the coordinate system. The MgByteReaderToWktText method converts the geometry representing the extent of the spatial context from a binary to a textual format. The MgSpatialContextExtentTypeToStr method converts the extent type from an enumeration constant to a textual format.

 using OSGeo.MapGuide;
 private void DescSpatialContexts(MgSpatialContextReader reader)
 {
     String CoordSys;
     String CoordSysType;
     String CoordSysName;
     String OgcSrsWkt;
     String spatialContextInfo;
     String spatialContextName;
     MgByteReader byteReader;
     String Extent;
     testSpatialContexts = new ListDictionary();
     coordSysNameToWkt = new ListDictionary();
     while (reader.ReadNext())
     {
         CoordSys = reader.GetCoordinateSystem();
         OgcSrsWkt = reader.GetCoordinateSystemWkt();
         if (CoordSys == null)
         {
             CoordSys = "null";
         }
         else if (CoordSys == "")
         {
             CoordSys = "emptyString";
         }
         else if (CoordSys == OgcSrsWkt)
         {
             CoordSys = "duplicate of GetCoordinateSystemWkt()";
         }
         CoordSysWktToTypeAndName(OgcSrsWkt, out CoordSysType, out CoordSysName);
         coordSysNameToWkt.Add(CoordSysName, OgcSrsWkt);
         // byteReader contains FGF binary
         byteReader = reader.GetExtent();
         if (byteReader.GetLength() == 0)
         {
             Extent = "is empty";
         }
         else
         {
             Extent = MgByteReaderToWktText(byteReader);
         }
         spatialContextName = reader.GetName();
         spatialContextInfo = "SpatialContextName=" + spatialContextName + ';' +
             "GetCoordinateSystem()=" + CoordSys + ';' +
             "CoordSysType=" + CoordSysType + ';' +
             "CoordSysName=" + CoordSysName + ';' +
             "GetCoordinateSystemWkt()=" + OgcSrsWkt + ';' +
             "ExtentType=" + MgSpatialContextExtentTypeToStr(reader.GetExtentType()) + ';' +
             "Extent=" + Extent + ';' +
             "XYTolerance=" + reader.GetXYTolerance() + ';' +
             "ZTolerance=" + reader.GetZTolerance() + ';' +
             "Active=" + reader.IsActive() + ';';
         testSpatialContexts.Add(spatialContextName, spatialContextInfo);
     }
 }

 private String MgByteReaderToWktText(MgByteReader byteReader)
 {
     String wktText = null;
     MgGeometry geometry = agfReaderWriter.Read(byteReader);
     wktText = wktReaderWriter.Write(geometry);
     return wktText;
 }

 private void CoordSysWktToTypeAndName(String coordSysWkt,
     out String coordSysType, out String coordSysName)
 {
     String interim;
     String pattern = @"^([A-Z_]+)\[([^\,]+)";
     Regex r = new Regex(pattern);
     Match m = r.Match(coordSysWkt);
     GroupCollection gc = m.Groups;
     coordSysType = gc[1].Value;
     interim = gc[2].Value;
     coordSysName = interim.Trim('"');
 }

 String MgSpatialContextExtentTypeToStr(Int32 extentType)
 {
     switch (extentType)
     {
         case 0: return "Static";
         case 1: return "Dynamic";
         default: return "InvalidMgSpatialContextExtentType: " + extentType;
     }
 }

 private MgAgfReaderWriter agfReaderWriter;
 private MgWktReaderWriter wktReaderWriter;
 private MgSpatialContextReader spatialContextReader;
 private MgFeatureService featureService;
 private ListDictionary testSpatialContexts;
 private ListDictionary coordSysNameToWkt;

 agfReaderWriter = new MgAgfReaderWriter();
 wktReaderWriter = new MgWktReaderWriter();
 // see the MgFeatureService sample code
 spatialContextReader = featureService.GetSpatialContexts(resourceId, false);
 DescSpatialContexts(spatialContextReader);


Public Member Functions

void Close ()
 Closes the SpatialContextReader object, freeing any resources it may be holding.
STRING GetCoordinateSystem ()
 
STRING GetCoordinateSystemWkt ()
 
STRING GetDescription ()
 
MgByteReaderGetExtent ()
 
INT32 GetExtentType ()
 
STRING GetName ()
 Gets the name of the spatial context currently being read.
double GetXYTolerance ()
 
double GetZTolerance ()
 
bool IsActive ()
 
bool ReadNext ()
 Advances the reader to the next spatial context.
void Reset ()
 Resets the SpatialContextReader object to the beginning just.