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

The MgAgfReaderWriter class is used to translate an MgGeometry object into into an MgByteReader object and to do the reverse translation. More...

+ Inheritance diagram for MgAgfReaderWriter:

List of all members.

Public Member Functions

 MgAgfReaderWriter ()
 Creates an MgAgfReaderWriter object.
virtual MgGeometryRead (MgByteReader *agf)
 Translates an MgByteReader object into an MgGeometry object. The contents of the MgByteReader is in Autodesk Geometry Format (AGF).
virtual MgGeometryRead (MgByteReader *agf, MgTransform *transform)
 Reads a geometry object from a stream of bytes in AGF format applying the specified transform during the read.
virtual MgByteReaderWrite (MgGeometry *geometry)
 Translates an MgGeometry object into a stream of bytes in AGF (Autodesk Geometry Format).
virtual MgByteReaderWrite (MgGeometry *geometry, MgTransform *transform)
 Writes a geometry object to a stream of bytes in AGF format applying the specified transform during the write.

Detailed Description

The MgAgfReaderWriter class is used to translate an MgGeometry object into into an MgByteReader object and to do the reverse translation.

Remarks:
The MgGeometry object to be translated is obtained from an MgWktReaderWriter or MgGeometryFactory object. The resulting MgByteReader object is then used to create an MgGeometryProperty object for an insert features operation.
In the reverse direction an MgByteReader object from an MgFeatureReader object is translated into an MgGeometry object. The MgFeatureReader object is obtained from a select features operation, and the MgByteReader object is returned by a call to the GetGeometry() method on the MgFeatureReader object.
The stream of bytes contained in this MgByteReader object is in Autodesk Geometry Format (AGF).
Example (PHP)
 $wktReaderWriter = new MgWktReaderWriter();
 $agfReaderWriter = new MgAgfReaderWriter();
 $geometryFactory = new MgGeometryFactory();

 # In the MgGeometry to MgGeometryProperty direction:
 # get the geometry from MgWktReaderWriter
 $agfTextPoint = "POINT XY (0 0)";
 $pointGeometryFromWkt = $wktReaderWriter->Read($agfTextPoint);
 # or get the geometry from MgGeometryFactory
 $coordinateXY = $geometryFactory->CreateCoordinateXY(0, 0);
 $pointGeometryFromFactory = $geometryFactory->CreatePoint($coordinateXY);

 # translate the MgGeometry object into an MgByteReader object
 $byteReader = $agfReaderWriter->Write($pointGeometryFromWkt);
 $byteReader = $agfReaderWriter->Write($pointGeometryFromFactory);

 # create an MgGeometryProperty object from the byte reader
 $geometryProperty = new MgGeometryProperty("geomPropName", $byteReader);

 # In the MgFeatureReader to MgGeometry direction:
 $byteReader = $featureReader->GetGeometry("geomPropName");
 $pointGeometry = $agfReaderWriter->Read($byteReader);
 $agfTextPoint = $wktReaderWriter->Write($pointGeometry);
 # print "POINT XY (0 0)" to screen
 echo "$agfTextPoint\n";
Example (C#)
 using OSGeo.MapGuide;
 private MgAgfReaderWriter agfReaderWriter;
 private MgWktReaderWriter wktReaderWriter;
 private MgGeometryFactory geometryFactory;
 private MgPoint pt11;
 private MgPoint pt11FromText;
 private String pt11TextSpec = "POINT XY ( 1 1 )";
 private MgByteReader byteReader;
 private MgGeometryProperty point11Prop;
 private MgFeatureQueryOptions containsPoint11QryOpt;
 private MgFeatureService featureService;
 private MgResourceIdentifier resourceId;
 private String className;
 private MgFeatureReader featureReader;
 private MgGeometry geometry;
 private String geometryText;

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

 public MgPoint CreateAPointXY(double x, double y)
 {
     MgCoordinate coord = geometryFactory.CreateCoordinateXY(x, y);
     return geometryFactory.CreatePoint(coord);
 }

 className = "featureClassName";
 agfReaderWriter = new MgAgfReaderWriter();
 wktReaderWriter = new MgWktReaderWriter();
 geometryFactory = new MgGeometryFactory();
 // In the MgGeometry to MgGeometryProperty direction:
 // get the geometry from the MgWktReaderWriter
 pt11FromText = wktReaderWriter.Read(pt11TextSpec) as MgPoint;
 // or get the geometry from the geometry factory
 pt11 = CreateAPointXY(1, 1);

 // translate the MgGeometry object into an MgByteReader object
 byteReader = agfReaderWriter.Write(pt11);
 byteReader = agfReaderWriter.Write(pt11FromText);

 // create an MgGeometryProperty object from the byte reader
 point11Prop = new MgGeometryProperty("theFeatureGeometry", byteReader);

 // In the MgFeatureReader to MgGeometry direction:
 containsPoint11QryOpt = new MgFeatureQueryOptions();
 containsPoint11QryOpt.SetFilter("theFeatureGeometry CONTAINS GEOMFROMTEXT( 'POINT(1 1)' )");
 // the MgResourceIdentifier object, resourceId, is the feature source being queried
 featureReader = featureService.SelectFeatures(resourceId, className, containsPoint11QryOpt);
 while (featureReader.ReadNext())
 {
     byteReader = featureReader.GetGeometry("theFeatureGeometry");
     geometry = agfReaderWriter.Read(byteReader);
     geometryText = wktReaderWriter.Write(geometry);
     // geometryText now contains the text representation of the geometry
 }