This document is archived and information here might be outdated. Recommended version. |
Projects this geometry into a new spatial reference.
[Visual Basic .NET] Public Sub Project ( _ ByVal newReferenceSystem As ISpatialReference _ )
[C#] public void Project ( ISpatialReference newReferenceSystem );
[C++]
HRESULT Project(
ISpatialReference* newReferenceSystem
);
[C++] Parameters newReferenceSystem
newReferenceSystem is a parameter of type ISpatialReference*
To Project, the geometry needs to have a Spatial Reference set, and not have an UnknownCoordinateSystem. The new spatial reference system passed to the method defines the output coordinate system. If either spatial reference is Unknown, the coordinates are not changed. The Z and measure values are not changed by the Project method.
A geometry is not densified before it is projected. This can lead to the output geometries not reflecting the 'true' shape in the new coordinate system. A straight line in one coordinate system is not necessarily a straight line in a different coordinate system. Use IGeometry2::ProjectEx if you want to densify the geometries while they are projected.
The Project method must be applied on high-level geometries only. High-Level geometries are point, multipoint, polyline and polygon. To use this method with low-level geometries such as segments (Line, Circular Arc, Elliptic Arc, B�zier Curve), paths or rings, they must be wrapped into high-level geometry types.
If a geometry is projected to a projected coordinate system that can't represent the geographic area where the geometry is located (or if trying to move an xy coordinate from outside the projected coordinate system back into geographic), the geometry will be set to empty.
Note: This method can only be called upon the top level geometries (Points, Multipoints, Polylines and Polygons). If the from/to spatial references have different geographic coordinate systems, the Project method looks for a GeoTransformationsOperationSet. If the set of Geotransformations is present in memory, Project will use it to perform a geographic/datum Transformation. To use a specific geotransformation, use the IGeometry2::ProjectEx method.
//Create Spatial Reference Factory
ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference sr1;
//GCS to project from
IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);
sr1 = gcs;
sr1.SetFalseOriginAndUnits(-180, -90, 1000000);
//Projected Coordinate System to project into
IProjectedCoordinateSystem pcs = srFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_NAD1983N_AmericaLambert);
pcs.SetFalseOriginAndUnits(0, 0, 1000);
ISpatialReference sr2;
sr2 = pcs;
//Point to project
IPoint point = new PointClass() as IPoint;
point.PutCoords(-117.17, 34.06);
//Geometry Interface to do actual project
IGeometry geometry;
geometry = point;
geometry.SpatialReference = sr1;
geometry.Project(sr2);
point = geometry as IPoint;
double x;
double y;
point.QueryCoords(out x, out y);
Debug.Print("X: " + x.ToString());
Debug.Print("Y: " + y.ToString());