<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Windows-1252">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6618.4">
<TITLE>RE: [mapguide-dev] area calculation conversion to meters</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>
<P><FONT SIZE=2>Right, I forgot about state planes. Those would have a central meridian that's closer to the data.<BR>
<BR>
For distance computations, MapGuide has great circle distance functions. Another resource for great circle I've used is here:<BR>
<BR>
<A HREF="http://www.codeguru.com/Cpp/Cpp/algorithms/article.php/c5115">http://www.codeguru.com/Cpp/Cpp/algorithms/article.php/c5115</A><BR>
<BR>
<BR>
The relevant section about a very accurate distance approximation on the ellipsoid is at the bottom of the page:<BR>
<BR>
==================================================<BR>
double ApproxDistance(double lat1, double lon1, double lat2,<BR>
double lon2)<BR>
{<BR>
lat1 = GEO::DE2RA * lat1;<BR>
lon1 = -GEO::DE2RA * lon1;<BR>
lat2 = GEO::DE2RA * lat2;<BR>
lon2 = -GEO::DE2RA * lon2;<BR>
<BR>
double F = (lat1 + lat2) / 2.0;<BR>
double G = (lat1 - lat2) / 2.0;<BR>
double L = (lon1 - lon2) / 2.0;<BR>
<BR>
double sing = sin(G);<BR>
double cosl = cos(L);<BR>
double cosf = cos(F);<BR>
double sinl = sin(L);<BR>
double sinf = sin(F);<BR>
double cosg = cos(G);<BR>
<BR>
double S = sing*sing*cosl*cosl + cosf*cosf*sinl*sinl;<BR>
double C = cosg*cosg*cosl*cosl + sinf*sinf*sinl*sinl;<BR>
double W = atan2(sqrt(S),sqrt(C));<BR>
double R = sqrt((S*C))/W;<BR>
double H1 = (3 * R - 1.0) / (2.0 * C);<BR>
double H2 = (3 * R + 1.0) / (2.0 * S);<BR>
double D = 2 * W * GEO::ERAD;<BR>
return (D * (1 + GEO::FLATTENING * H1 * sinf*sinf*cosg*cosg -<BR>
GEO::FLATTENING*H2*cosf*cosf*sing*sing));<BR>
}<BR>
=======================================<BR>
<BR>
<BR>
Traian<BR>
<BR>
-----Original Message-----<BR>
From: Orest Halustchak<BR>
Sent: Sun 12/3/2006 2:33 PM<BR>
To: dev@mapguide.osgeo.org<BR>
Cc: <BR>
Subject: RE: [mapguide-dev] area calculation conversion to meters<BR>
<BR>
Hi,<BR>
<BR>
Yes, converting to a UTM zone would work. However, if the original data is in the US, e.g. Sheboygan, you could project to the corresponding State Plane zone. Then you could do length and area calculations more accurately.<BR>
<BR>
For UTM, central meridian = zone*6 -183.<BR>
<BR>
For lat/long data, the correct way to compute length is on the spheroid. Libraries such as Proj4 or Mentor include distance calculation functions based on a particular spheroid. Most libraries unfortunately do not include an area calculation on the spheroid.<BR>
<BR>
Orest.<BR>
<BR>
-----Original Message-----<BR>
From: Paul Spencer (External)<BR>
Sent: Sun 12/3/2006 2:11 PM<BR>
To: dev@mapguide.osgeo.org<BR>
Cc:<BR>
Subject: Re: [mapguide-dev] area calculation conversion to meters<BR>
<BR>
<BR>
<BR>
Thanks Traian, it hurts my head too! All calculations will be <BR>
advertised as approximate, but I'd like them to be close to reality.<BR>
<BR>
How can I construct a UTM coordinate system definition centered <BR>
around the meridian that crosses the centroid of the feature? Or <BR>
find the UTM Zone projection that contains the centroid of a feature <BR>
(I manually found it for the Sheboygan data and it gave decent <BR>
results)? Would I need to manually build an array of UTM Zone -> LL <BR>
mappings?<BR>
<BR>
Cheers<BR>
<BR>
Paul<BR>
<BR>
<BR>
On 3-Dec-06, at 12:58 PM, Traian Stanev wrote:<BR>
<BR>
> I'm far from an expert either, but here is what makes sense to me...<BR>
><BR>
> The simplest solution to me seems to transform to the nearest UTM <BR>
> Zone projection in meters and compute the area of the resulting <BR>
> geometry. I think this will be accurate enough for what you are <BR>
> doing, since it is very likely that the original data (for <BR>
> Sheboygan) was measured in that UTM zone and then converted to <BR>
> LatLon after the fact anyway. That's why it seems to me that this <BR>
> approach will give you exact results, even though in theory it is <BR>
> not exact (since the data can be far away from the UTM Zone's <BR>
> central meridian).<BR>
><BR>
> Another, more generic approach, that would be good for small <BR>
> features, would be to construct a UTM coordinate system definition <BR>
> centered around the meridian that crosses the centroid of the <BR>
> feature. This will give you an LL-UTM transformation with the least <BR>
> distortion for the feature at hand.<BR>
><BR>
> My hunch is that computing an exact area on the ellipsoid without <BR>
> projection involves elliptical integrals, since even the area of a <BR>
> whole ellipsoid involves those. Elliptic integrals have no closed <BR>
> form solution so you would need a numerical integration approach, <BR>
> which hurts my head even thinking about it.<BR>
><BR>
><BR>
> Traian<BR>
><BR>
><BR>
><BR>
><BR>
> -----Original Message-----<BR>
> From: Paul Spencer (External)<BR>
> Sent: Sat 12/2/2006 12:04 PM<BR>
> To: dev@mapguide.osgeo.org<BR>
> Cc:<BR>
> Subject: Re: [mapguide-dev] area calculation conversion to meters<BR>
><BR>
> Trevor,<BR>
><BR>
> That would work for GetLength() but I wonder if you need to adjust<BR>
> for latitude as well ... and it doesn't work for area. I pondered<BR>
> doing this for the square root of the area and then squaring the<BR>
> result ... I think that would work, but again it would have to be<BR>
> adjusted for the latitude ... or am I over-engineering this?<BR>
><BR>
> Paul<BR>
><BR>
> On 1-Dec-06, at 4:10 PM, Trevor Wekel wrote:<BR>
><BR>
> > Hi Paul,<BR>
> ><BR>
> > For the most general case, I think you're on the right track. <BR>
> Most of<BR>
> > the geometry classes support the Transform() operation. The<BR>
> > MgCoordinateSystemTransform allows transformation from one <BR>
> coordinate<BR>
> > system to another. I'm not a coordinate system expert but from <BR>
> what I<BR>
> > understand most coordinate systems projections have an accurate <BR>
> sweet<BR>
> > spot in the center and become more inaccurate around the edges. I<BR>
> > wonder if there is a programmatic way to determine the <BR>
> appropriateness<BR>
> > of the target system? Possibly based on center point of the<BR>
> > projection?<BR>
> ><BR>
> > But if your target system is in decimal degrees, doesn't that <BR>
> imply a<BR>
> > direct mapping to the world space? Isn't a decimal degree some <BR>
> number<BR>
> > of meters? Could you just use<BR>
> > MgCoordinateSystem::ConvertCoordinateSystemUnitsToMeters(double <BR>
> units)<BR>
> > as the conversion factor? I suspect this may also work in the sweet<BR>
> > spot of projected systems as well.<BR>
> ><BR>
> > Thanks,<BR>
> > Trevor<BR>
> ><BR>
> > -----Original Message-----<BR>
> > From: Paul Spencer (External)<BR>
> > Sent: Thursday, November 30, 2006 3:03 PM<BR>
> > To: dev@mapguide.osgeo.org<BR>
> > Subject: [mapguide-dev] area calculation conversion to meters<BR>
> ><BR>
> > Hi all,<BR>
> ><BR>
> > I'm measuring the area and length of features using<BR>
> > MgGeometricEntity::GetArea() and GetLength() in the Sheboygan data.<BR>
> > This returns values in the units of the projection, which happens<BR>
> > to be<BR>
> > decimal degrees. Not so useful. I'd like the result to be in <BR>
> meters.<BR>
> ><BR>
> > Since this code needs to be generic, I've implemented some stuff to<BR>
> > transform the geometry into a coordinate system that supports <BR>
> meters.<BR>
> > This is not too accurate since I arbitrarily picked a World LCC<BR>
> > projection wkt :)<BR>
> ><BR>
> > What is the recommended way of doing this calculation?<BR>
> ><BR>
> > Cheers<BR>
> ><BR>
> > Paul<BR>
> ><BR>
> > +-----------------------------------------------------------------+<BR>
> > |Paul Spencer pspencer@dmsolutions.ca |<BR>
> > +-----------------------------------------------------------------+<BR>
> > |Chief Technology Officer |<BR>
> > |DM Solutions Group Inc <A HREF="http://www.dmsolutions.ca/">http://www.dmsolutions.ca/</A> |<BR>
> > +-----------------------------------------------------------------+<BR>
> ><BR>
> ><BR>
> ><BR>
> ><BR>
> ><BR>
> > <BR>
> ---------------------------------------------------------------------<BR>
> > To unsubscribe, e-mail: dev-unsubscribe@mapguide.osgeo.org<BR>
> > For additional commands, e-mail: dev-help@mapguide.osgeo.org<BR>
> ><BR>
> ><BR>
> ><BR>
> > <BR>
> ---------------------------------------------------------------------<BR>
> > To unsubscribe, e-mail: dev-unsubscribe@mapguide.osgeo.org<BR>
> > For additional commands, e-mail: dev-help@mapguide.osgeo.org<BR>
> ><BR>
><BR>
> +-----------------------------------------------------------------+<BR>
> |Paul Spencer pspencer@dmsolutions.ca |<BR>
> +-----------------------------------------------------------------+<BR>
> |Chief Technology Officer |<BR>
> |DM Solutions Group Inc <A HREF="http://www.dmsolutions.ca/">http://www.dmsolutions.ca/</A> |<BR>
> +-----------------------------------------------------------------+<BR>
><BR>
><BR>
><BR>
><BR>
><BR>
> ---------------------------------------------------------------------<BR>
> To unsubscribe, e-mail: dev-unsubscribe@mapguide.osgeo.org<BR>
> For additional commands, e-mail: dev-help@mapguide.osgeo.org<BR>
><BR>
><BR>
<BR>
+-----------------------------------------------------------------+<BR>
|Paul Spencer pspencer@dmsolutions.ca |<BR>
+-----------------------------------------------------------------+<BR>
|Chief Technology Officer |<BR>
|DM Solutions Group Inc <A HREF="http://www.dmsolutions.ca/">http://www.dmsolutions.ca/</A> |<BR>
+-----------------------------------------------------------------+<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
---------------------------------------------------------------------<BR>
To unsubscribe, e-mail: dev-unsubscribe@mapguide.osgeo.org<BR>
For additional commands, e-mail: dev-help@mapguide.osgeo.org<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>