I have a piece of code that converts a map extent from one projection to another using GeometryEngine.Project() function, then later convert it back to the original projection. What I noticed is that as I do this, my extent keeps growing in size through each conversion. Here's my sample code to demonstrate this issue:
SpatialReference spRef1 = _map1.SpatialReference; SpatialReference spRef2 = _map2.SpatialReference; Geometry extent1 = MyMapView.Extent; System.Console.WriteLine("extent1:" + extent1); Geometry extent2 = GeometryEngine.Project(extent1, spRef2); System.Console.WriteLine("extent2:" + extent2); Geometry extent3 = GeometryEngine.Project(extent2, spRef1); System.Console.WriteLine("extent3:" + extent3); Geometry extent4 = GeometryEngine.Project(extent3, spRef2); System.Console.WriteLine("extent4:" + extent4);
I took the map extent and project it back and forth between the projection. Here's e output result:
extent1:Envelope[XMin=-13657052.8897704, YMin=5704031.99454925, XMax=-13654690.3535498, YMax=5705394.14433894, Wkid=102100]
extent2:Envelope[XMin=7642556.79710776, YMin=683718.917830887, XMax=7648078.00265341, YMax=686989.703265818, Wkid=2913]
extent3:Envelope[XMin=-13657089.5657256, YMin=5703968.27772793, XMax=-13654654.0392246, YMax=5705457.8619931, Wkid=102100]
extent4:Envelope[XMin=7642468.43306019, YMin=683570.513830889, XMax=7648165.48222178, YMax=687138.129620944, Wkid=2913]
If projection works as expected, I would expect extent1 = extent3, and extent2 = extent4, but as you can see that is not the case. Is there something I am missing in my understanding on how the GeometryEngine.Project() function works?
Solved! Go to Solution.
The extent is probably being "reboxed". EPSG:102100 is Web Mercator which is a cylindrical projection. Latitude and longitude lines are perpendicular and square (parallel to grid north/south and grid east/west). EPSG:2913 is a US state plane zone for Oregon that uses Lambert conformal conic projection. Latitude and longitude lines are perpendicular, but not parallel to grid north/south and east/west lines. A rectangular extent in 102100 will be tilted slightly. If it's reboxed (find the min and max values), there will be new coordinate values. I took the original two values, found the other corners and then projected them:
-13657052.8897704 5704031.99454925
-13654690.3533550 5705394.14433894
-13657052.8897704 5705394.14433894
-13654690.3533550 5704031.99454925
Unproject to lat/lon:
-122.6833934690943 43.52171365960083
-121.6621704433817 45.53028630417766
-122.6833934690943 45.53028630417766
-121.6621704433817 43.52171365960083
Project to 2913:
7642556.797098541 683865.1900488964
7648078.003092581 686843.4524277482
7642641.258368226 686989.7029220903
7647994.362606527 683718.9174751663
You can see that the results in 2913 are no longer rectangular. While the first x (easting) value is the smallest, the smallest y (northing) value is the last one, not the first.
Melita
The extent is probably being "reboxed". EPSG:102100 is Web Mercator which is a cylindrical projection. Latitude and longitude lines are perpendicular and square (parallel to grid north/south and grid east/west). EPSG:2913 is a US state plane zone for Oregon that uses Lambert conformal conic projection. Latitude and longitude lines are perpendicular, but not parallel to grid north/south and east/west lines. A rectangular extent in 102100 will be tilted slightly. If it's reboxed (find the min and max values), there will be new coordinate values. I took the original two values, found the other corners and then projected them:
-13657052.8897704 5704031.99454925
-13654690.3533550 5705394.14433894
-13657052.8897704 5705394.14433894
-13654690.3533550 5704031.99454925
Unproject to lat/lon:
-122.6833934690943 43.52171365960083
-121.6621704433817 45.53028630417766
-122.6833934690943 45.53028630417766
-121.6621704433817 43.52171365960083
Project to 2913:
7642556.797098541 683865.1900488964
7648078.003092581 686843.4524277482
7642641.258368226 686989.7029220903
7647994.362606527 683718.9174751663
You can see that the results in 2913 are no longer rectangular. While the first x (easting) value is the smallest, the smallest y (northing) value is the last one, not the first.
Melita
Thanks Melita for taking the time to explain this concept to me. I am a SW developer, so some of this GIS stuff is sometimes over my head. But after reading through your explanation, it does help me to understand why this happens.
... And I guess I should follow up with a thought that in order to get around this 'boxing' issue with the envelope, I can instead project the 4 points that make up the corners of the envelop, then rebuild the envelop after each projection -- that should keep the extent to its original size.
Does the same reboxing theory hold for projecting geometries from a projected cs to a geographic cs (e.g. ITRF_2005_Rwanda to GCS ITRF 2005). In other words, densification takes place?
Yes, because a PCS extent may be tipped relative to the "graticule" in lat-lon space. We treat the graticule (system of latitude-longitude lines) as if it's a flat, 2D grid, so the extent of a PCS may end up at an angle, a trapezoid, etc. after it's unprojected.
Melita
Melita, could it be just because GeometryEngine.Project() works wrong - since 10.2.6 (or maybe 10.2.5) it doesn't apply the right transformations. See this post: Incorrect results of GeometryEngine.Project for EPSG:31468 in 10.2.6 I experience the same problem in the application I'm working on.
Yes, it's possible. I don't know about the geometry engine bugs (different team). If you post or send me (mkennedy at esri) the input / output values, I can check them.
Melita