Wednesday, October 22, 2008

Convert Latitude/Longitude to Easting/Northing Coordinates

The CoordSystem object in GeoMedia can perform among other things, coordinate conversion from latitude and longitude to easting and northing using its TransformPoint method. What is not clear from the GeoMedia Object Reference developer documentation is that the latitude and longitude coordinates must be passed in as radians, not degrees; there was no mention of the units at all. I was at a loss for a while wondering why the converted values were incorrect until I found some example code from the Intergraph web site showing the correct usage. In fact, there is also a UnitAndFormatSpec object that comes with the Coordinate System Services (PCSS) that can help you perform the latitude, longitude conversion to radians. Example C# code listing is shown below.

PCSS.CoordSystemsMgr coordSysMgr = null;
PCSS.CoordSystem coordSys = null;
PCSS.UnitAndFormatSpec spec = null;
bool isValid = false;
double x = 104.0, y = 4.0, z = 0.0;
double[] point = { 0, 0, 0 }; //the output easting, northing, height values

//Get a reference to the Coordinate Systems Manager class
//of the GeoMedia workspace

coordSysMgr = (PCSS.CoordSystemsMgr) this._document.CoordSystemsMgr;

//Create an instance of the UnitAndFormatSpec class
spec = (PCSS.UnitAndFormatSpec)this._application.CreateService("UnitAndFormatSpec");

//Convert the longitude to radians
spec.ParseValueString(Intergraph.GeoMedia.PCSS.CSValueStringConstants.csvsLongitude, lng.ToString(), out x);


//Convert the latitude to radians
spec.ParseValueString(Intergraph.GeoMedia.PCSS.CSValueStringConstants.csvsLatitude, lat.ToString(), out y);

//Get a reference to the coordinate system class
coordSys = coordSysMgr.CoordSystem;

//Check first to see if the conversion from latitude, longitude to
// easting, northing is valid
coordSys.IsTransformationValid(Intergraph.GeoMedia.PCSS.CSPointConstants.cspLLU, 1, Intergraph.GeoMedia.PCSS.CSPointConstants.cspENU, 1, out isValid);

//If the conversion is valid, then perform the actual conversion
//from latitude, longitude to easting, northing.
if (isValid == true)
{
coordSys.TransformPoint(Intergraph.GeoMedia.PCSS.CSPointConstants.cspLLU, 1, Intergraph.GeoMedia.PCSS.CSPointConstants.cspENU, 1, ref x, ref y, ref z);
point[0] = x;
point[1] = y;
point[2] = z;
}

2 comments:

Anonymous said...

I have a problem and I wan´t to see if you can help me. I use Geomedia objects to read a shape file. I open shape files and read them with no problem, but I don't know how can I transform or change the projection. My geometries are in Datum 73 and the shape file that I'm reading is in PT-TM06-ETRS89. I could use Molodensky transformation formulas to convert, but I think that Geomedia can do this for me. The only thing I don't know is how ?

d0min0c said...

Yup, if you have defined your coordinate systems properly the GeoMedia application can do the transformation automatically for you. However, you've got to do a lot more work if you using GeoMedia objects. In your code, you've got to check your source dataset and your destination coordinate system. If they are not the same, then you have to use a GeoMedia transformation service object to reproject your feature recordsets.

Related Posts with Thumbnails