krfournier

Same Result for Polygon Area

Discussion created by krfournier on Dec 21, 2011
Latest reply on Dec 21, 2011 by krfournier
Here is my code for getting a polygon's area. Note that this is C++, and all the "CESRI" classes are my own thin wrappers around the various interfaces. So, my C++ code should read more like C#, and I use the same naming conventions as ESRI.

CESRIFeatureLayer featureLayer = m_mapControl.GetLayer(nIndex).QueryFeatureLayer();
CESRIFeatureClass featureClass = featureLayer.GetFeatureClass();

CESRIQueryFilter filter;
filter.CreateQueryFilter();

CString strShapeField = featureClass.GetShapeFieldName();
CString strKeyField = featureClass.GetKeyFieldName();

CString strWhereClause;
strWhereClause.Format( _T("%s = %s"), strKeyField, lpszFeature );
filter.SetWhereClause( strWhereClause );

CESRIFeatureCursor cursor = featureLayer.Search( filter, false );
   
CESRIFeature feature;
cursor.NextFeature( feature );

CESRIGeometry geometry = feature.GetShape();
geometry.SetSpatialReference( m_mapControl.GetSpatialReference() );
dResult = geometry.QueryArea().GetArea();


Now, prior to calling this code, I have set my projection to "Europe Lambert", i.e., 102014. Here is the code for that:

// create the spatial reference factory
CESRISpatialReferenceFactory spatialReferenceFactory;
spatialReferenceFactory.CreateSpatialReferenceEnvironment();

// create the predefined spatial reference
CESRIProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem( 102014 );

// make it the map's spatial reference
m_mapControl.SetSpatialReference( projectedCoordinateSystem );


This projection is in meters, and I can confirm that the MapControl's MapUnits property is in fact returning Meters. Still, I'm always getting my Area is Decimal Degrees. What am I missing here?

Outcomes