MapGuide API Reference
 All Classes Functions Variables Enumerations Enumerator Friends
MgFeatureReader Class Reference

Provides a forward-only, read-only iterator for reading features selected from the FDO Provider by the MgFeatureService::SelectFeatures() method call. More...

+ Inheritance diagram for MgFeatureReader:

List of all members.

Public Member Functions

virtual MgClassDefinitionGetClassDefinition ()=0
 Gets the class definition of the object currently being read. If the user has requested only a subset of the class properties (as specified in the filter text), the class definition reflects what the user has requested, rather than the full class definition.
virtual MgFeatureReaderGetFeatureObject (CREFSTRING propertyName)=0
 Use this method to obtain the values of the properties belonging to an object contained in the feature class instance. Such an object is a property of the feature class instance with a type of MgPropertyType::Feature.
virtual MgFeatureReaderGetFeatureObject (INT32 index)=0
 Use this method to obtain the values of the properties belonging to an object contained in the feature class instance. Such an object is a property of the feature class instance with a type of MgPropertyType::Feature.

Detailed Description

Provides a forward-only, read-only iterator for reading features selected from the FDO Provider by the MgFeatureService::SelectFeatures() method call.

Remarks:
You must call ReadNext() before you can access the data. Call GetProperties() to get the property values for the feature. For each property, determine the property type and then call the appropriate Get<type>() method to get the value of the property. With one exception the Get<type> methods belong to the MgReader base class. The exception is MgFeatureReader::GetFeatureObject(). Obtain the next feature by calling the ReadNext() method.
Example (PHP)
 // each ReadNext() gets a "row" object, that is,
 // an instantiation of a class with properties
 // returns number of features in reader
 function printFeatureReader($featureReader)
 {
    global $logFileHandle;
    $i = 0;
    while ($featureReader->ReadNext())
    {
       fwrite($logFileHandle, "Printing a feature.n");
       $i++;
       $propCount = $featureReader->GetPropertyCount();
       for($j=0; $j<$propCount; $j++)
       {
           $propertyName = $featureReader->GetPropertyName($j);
           $boolVal = $featureReader->IsNull($propertyName);
           if ($boolVal)
              continue;
           $propertyType = $featureReader->GetPropertyType($propertyName);
           printPropertyValueFromFeatReader($featureReader, $propertyType, $propertyName);
       }
    }
    return $i;
 }

 function printPropertyValueFromFeatReader($featureReader, $propertyType, $propertyName)
 {
    global $logFileHandle;
    global $agfReaderWriter;
    global $wktReaderWriter;
    switch ($propertyType)
    {
       case MgPropertyType::Null :
              fwrite($logFileHandle, "$propertyName is a null propertyn");
              break;
       case MgPropertyType::Boolean :
              $val = $featureReader->GetBoolean($propertyName);
              $valStr = printBoolean($val);
              fwrite($logFileHandle, "$propertyName is boolean "$valStr"n");
              break;
       case MgPropertyType::Byte :
              $val = $featureReader->GetByte($propertyName);
              fwrite($logFileHandle, "$propertyName has a byte value of "$val"n");
              break;
       case MgPropertyType::DateTime :
              $val = $featureReader->GetDateTime($propertyName);
              $valStr = printDateTime($val);
              fwrite($logFileHandle, "DateTime is "$valStr"n");
              break;
       case MgPropertyType::Single :
              $val = $featureReader->GetSingle($propertyName);
              fwrite($logFileHandle, "$propertyName is single "$val"n");
              break;
       case MgPropertyType::Double :
              $val = $featureReader->GetDouble($propertyName);
              fwrite($logFileHandle, "$propertyName is double "$val"n");
              break;
       case MgPropertyType::Int16 :
              $val = $featureReader->GetInt16($propertyName);
              fwrite($logFileHandle, "$propertyName is int16 "$val"n");
              break;
       case MgPropertyType::Int32 :
              $val = $featureReader->GetInt32($propertyName);
              fwrite($logFileHandle, "$propertyName is int32 "$val"n");
              break;
       case MgPropertyType::Int64 :
              $val = $featureReader->GetInt64($propertyName);
              fwrite($logFileHandle, "$propertyName is int64 "$val"n");
              break;
       case MgPropertyType::String :
              $val = $featureReader->GetString($propertyName);
              fwrite($logFileHandle, "$propertyName is string "$val"n");
              break;
       case MgPropertyType::Blob :
              fwrite($logFileHandle, "$propertyName is blobn");
              break;
       case MgPropertyType::Clob :
              fwrite($logFileHandle, "$propertyName is clobn");
              break;
       case MgPropertyType::Feature :
              $val = $featureReader->GetFeatureObject($propertyName);
             if ($val != NULL)
             {
                  fwrite($logFileHandle, "$propertyName is a featuren");
                  printFeatureReader($val);
             }
             break;
       case MgPropertyType::Geometry :
              fwrite($logFileHandle, "$propertyName is a geometryn");
              $val = $featureReader->GetGeometry($propertyName);
              if ($val != NULL)
              {
                 $aGeometry = $agfReaderWriter->Read($val);
                 $wktRepresentation = $wktReaderWriter->Write($aGeometry);
                 fwrite($logFileHandle, "WKT Representation: "$wktRepresentation"n");
              }
              else
              {
                 fwrite($logFileHandle, "This geometry property is nulln");
              }
              break;
       case MgPropertyType::Raster :
              $val = $featureReader->GetRaster($propertyName);
              fwrite($logFileHandle, "$propertyName is a rastern");
              break;
       default : fwrite($logFileHandle, "Unknown property typen");
    }
 }
Example (C#)
 using OSGeo.MapGuide;
 private StringBuilder sb;
 private const int sbLength = 512;

 public int PrintFeatureReader(MgFeatureReader featureReader, out String propertiesToStr)
 {
     int featureCount = 0;
     int propertyCount;
     String propertyName;
     int propertyType;
     sb = new StringBuilder(sbLength);
     while (featureReader.ReadNext())
     {
         featureCount++;
         propertyCount = featureReader.GetPropertyCount();
         for (int i = 0; i < propertyCount; i++)
         {
             propertyName = featureReader.GetPropertyName(i);
             propertyType = featureReader.GetPropertyType(propertyName);
             PrintPropertyValueFromReader(featureReader, propertyType, propertyName, ref sb);
         }
     }
     propertiesToStr = sb.ToString();
     return featureCount;
 }

 private void PrintPropertyValueFromReader(MgReader reader,
     int propertyType, String propertyName, ref StringBuilder sb)
 {
     Boolean isNull = reader.IsNull(propertyName);
     if (propertyType == MgPropertyType.Blob)
     {
         sb.Append(propertyName + "=Blob(" + (isNull ? "null" : "notNull") + ");");
     }
     else if (propertyType == MgPropertyType.Boolean)
     {
         sb.Append(propertyName + "=Boolean(" + (isNull ? "null" : reader.GetBoolean(propertyName).ToString()) + ");");
     }
     else if (propertyType == MgPropertyType.Byte)
     {
         sb.Append(propertyName + "=Byte(" + (isNull ? "null" : reader.GetByte(propertyName).ToString()) + ");");
     }
     else if (propertyType == MgPropertyType.Clob)
     {
         sb.Append(propertyName + "=Clob(" + (isNull ? "null" : "notNull") + ");");
     }
     else if (propertyType == MgPropertyType.DateTime)
     {
         String dateTimeStr = null;
         if (!isNull)
         {
             MgDateTime aDateTime = reader.GetDateTime(propertyName);
             dateTimeStr = aDateTime.Month.ToString() + '.'
                 + aDateTime.Day.ToString() + '.' + aDateTime.Year.ToString()
                 + ':' + aDateTime.Hour.ToString() + ':' + aDateTime.Minute.ToString()
                 + ':' + aDateTime.Second.ToString();
         }
         sb.Append(propertyName + "=DateTime(" + (isNull ? "null" : dateTimeStr) + ");");
     }
     else if (propertyType == MgPropertyType.Double)
     {
         sb.Append(propertyName + "=Double(" + (isNull ? "null" : reader.GetDouble(propertyName).ToString()) + ");");
     }
     else if (propertyType == MgPropertyType.Feature)
     {
         sb.Append(propertyName + "=Feature(" + (isNull ? "null" : "notNull") + ");");
     }
     else if (propertyType == MgPropertyType.Geometry)
     {
         sb.Append(propertyName + "=Geometry(" + (isNull ? "null" : geometryServices.MgByteReaderToWktText(reader.GetGeometry(propertyName))) + ");");
     }
     else if (propertyType == MgPropertyType.Int16)
     {
         sb.Append(propertyName + "=Int16(" + (isNull ? "null" : reader.GetInt16(propertyName).ToString()) + ");");
     }
     else if (propertyType == MgPropertyType.Int32)
     {
         sb.Append(propertyName + "=Int32(" + (isNull ? "null" : reader.GetInt32(propertyName).ToString()) + ");");
     }
     else if (propertyType == MgPropertyType.Int64)
     {
         sb.Append(propertyName + "=Int64(" + (isNull ? "null" : reader.GetInt64(propertyName).ToString()) + ");");
     }
     else if (propertyType == MgPropertyType.Raster)
     {
         sb.Append(propertyName + "=Raster(" + (isNull ? "null" : "notNull") + ");");
     }
     else if (propertyType == MgPropertyType.Single)
     {
         sb.Append(propertyName + "=Single(" + (isNull ? "null" : reader.GetSingle(propertyName).ToString()) + ");");
     }
     else if (propertyType == MgPropertyType.String)
     {
         sb.Append(propertyName + "=String(" + (isNull ? "null" : reader.GetString(propertyName)) + ");");
     }
     else
     {
         sb.Append(propertyName + "=Unknown(" + propertyType.ToString() + ");");
     }
 }