Hello, I'm going crazy with this issue. I'm trying to change the points for a Rectangle Geometry from a IRectangleElement. The method I'm using is the following, igcs is well built and has the GCS_WGS_1984 coordinate system, the same as the map, and layers: public void SetPoints(ref IGeometry sourceGeometry)
{
IPointCollection polygon = new PolygonClass();
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
IGeographicCoordinateSystem igcs = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
(polygon as IPolygon).SpatialReference = igcs;
// Another test
//(polygon as IPolygon).SpatialReference = e.Geometry.SpatialReference;
IPoint ul= new PointClass();
ul.SpatialReference = igcs;
ul.PutCoords(UpperLeftLongitude, UpperLeftLatitude);
IPoint ur= new PointClass();
ur.SpatialReference = igcs;
ur.PutCoords(LowerRightLongitude, UpperLeftLatitude);
IPoint ll= new PointClass();
ll.SpatialReference = igcs;
ll.PutCoords(UpperLeftLongitude, LowerRightLatitude);
IPoint lr= new PointClass();
lr.SpatialReference = igcs;
lr.PutCoords(LowerRightLongitude, LowerRightLatitude);
(polygon as IPointCollection).AddPoint(ul);
(polygon as IPointCollection).AddPoint(ur);
(polygon as IPointCollection).AddPoint(lr);
(polygon as IPointCollection).AddPoint(ll);
(polygon as IPointCollection).AddPoint(ul);
((ITopologicalOperator)polygon).Simplify();
sourceGeometry = polygon as IGeometry;
sourceGeometry.SpatialReference = igcs;
} The call to this method is:
//Modify points
IGeometry eg = e.Geometry;
SetPoints(ref eg);
e.Geometry = eg; //eg at this point has Spatial Reference within it's content, but null is stored on e.Geometry.SpatialReference when assigned. In that assignment, the Spatial Reference of e.Geometry (e is an IRectangleElement but it's declared as an IElement) is set to null value. I lose that info but I don't know why. I don't know if I'm building the new rectangle in a worng way. Any idea about what's hapenning with the missing Spatial Reference? Thanks in advance.
... View more