Monday, March 19, 2012

Use the GeoMedia Math Service to get the range of any geometry object

It is useful to be able to programmatically determine the coordinate ranges of any GeoMedia geometry object, e.g. polygon, point, line, etc. The example C# code snippet below is from part of a 'driving GeoMedia application' that illustrates how to get the geometry range coordinates.


// ...etc...
using GeoMedia = Intergraph.GeoMedia.GeoMedia;
using GeoMath = Intergraph.GeoMedia.GeoMathSvc;
using PBasic = Intergraph.GeoMedia.PBasic;
// ...etc...
 
// Create a new instance of the GeoMedia application framework
private GeoMedia.Application _application = (GeoMedia.Application)Activator.CreateInstance(GeoMediaType);
//...etc..
 
// pass in any geometry object as objGeom and read the min range from loRange and the max range from hiRange
public void GetAnyGeometryRange(object objGeom, out PBasic.point lowRange, out PBasic.point highRange)
{
GeoMath.GeoMathService geoMathSvc;    //the GeoMedia Math Service object
GeoMath.point lowerLeftPoint, upperRightPoint;    //the lower left and upper right GeoMedia point objects
 
//Use the GeoMedia application to create the GeoMedia point objects for storing the min and max range points
lowerLeftPoint = (GeoMath.point)_application.CreateService("GeoMedia.point");
upperRightPoint = (GeoMath.point)_application.CreateService("GeoMedia.point");
 
//Create the GeoMedia Math Service
geoMathSvc = (GeoMath.GeoMathService)_application.CreateService("GeoMedia.GeoMathService");

//Use the GeoMedia Math Service to calculate the geometry range
geoMathSvc.GetRange(objGeom, lowerLeftPoint, upperRightPoint);
 
//Store the range points for passing back the values to the calling function
lowRange = (PBasic.point) lowerLeftPoint;
highRange = (PBasic.point) upperRightPoint;
 
//finally free up the memory used by the GeoMedia Math Service COM object
if (geoMathSvc != null) 
Marshal.FinalReleaseComObject(geoMathSvc);
}

No comments: