<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to successfully project the map extent into a different spatial reference in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-successfully-project-the-map-extent-into-a/m-p/1150416#M7879</link>
    <description>&lt;P&gt;I am having a really difficult time trying to project the map extent (WGS84) into an envelope of a different spatial reference (Web Mercator or UTM). I have tried multiple ways of changing the spatial reference of an envelope, but none of them are working. I know they aren't working because I am drawing a graphic on the screen for the envelope, but nothing appears when changing the envelope to a different spatial reference. Using the map's spatial reference of WGS84 for the envelope works perfectly and it is drawn to the screen.&lt;/P&gt;&lt;P&gt;As an fyi, I am converting the envelope into a polygon, which I am using for the graphic.&lt;/P&gt;&lt;P&gt;The following are four different code attempts that I have made using Web Mercator. I have also tried with UTM:&lt;/P&gt;&lt;PRE&gt;SpatialReference sr3857 = SpatialReferenceBuilder.CreateSpatialReference(&lt;SPAN class=""&gt;3857&lt;/SPAN&gt;);
&lt;SPAN class=""&gt;// Builder constructors need to run on the MCT.&lt;/SPAN&gt;
&lt;SPAN class=""&gt;using&lt;/SPAN&gt; (SpatialReferenceBuilder srBuilder = &lt;SPAN class=""&gt;new&lt;/SPAN&gt; SpatialReferenceBuilder(&lt;SPAN class=""&gt;3857&lt;/SPAN&gt;))
{
    &lt;SPAN class=""&gt;// do something with the builder&lt;/SPAN&gt;
    sr3857 = srBuilder.ToSpatialReference();
}
ArcGIS.Core.Geometry.Polygon envPoly = &lt;SPAN class=""&gt;null&lt;/SPAN&gt;;
Envelope mapExtent = (Envelope)GeometryEngine.Instance.Project(MapView.Active.Extent, sr3857);

&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;private&lt;/SPAN&gt; Envelope &lt;SPAN class=""&gt;BuildEnvelope&lt;/SPAN&gt;(&lt;SPAN class=""&gt;MapPoint mapPt, Envelope inputEnvelope&lt;/SPAN&gt;)&lt;/SPAN&gt;
{
    EnvelopeBuilder envelopeBuilder = &lt;SPAN class=""&gt;new&lt;/SPAN&gt; EnvelopeBuilder(SpatialReferences.WebMercator);
    envelopeBuilder.XMin = inputEnvelope.XMin;
    envelopeBuilder.YMin = inputEnvelope.YMin;
    envelopeBuilder.XMax = inputEnvelope.XMax;
    envelopeBuilder.YMax = inputEnvelope.YMax;

    &lt;SPAN class=""&gt;return&lt;/SPAN&gt; envelopeBuilder.ToGeometry();
}
Envelope mapExtent = BuildEnvelope(MapView.Active.Extent)

Envelope mapExtent = EnvelopeBuilder.CreateEnvelope(MapView.Active.Extent, SpatialReferences.WebMercator);

Envelope mapExtent = EnvelopeBuilder.CreateEnvelope(MapView.Active.Extent, SpatialReferences.WebMercator);&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Mar 2022 21:25:01 GMT</pubDate>
    <dc:creator>DaveLewis73</dc:creator>
    <dc:date>2022-03-03T21:25:01Z</dc:date>
    <item>
      <title>How to successfully project the map extent into a different spatial reference</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-successfully-project-the-map-extent-into-a/m-p/1150416#M7879</link>
      <description>&lt;P&gt;I am having a really difficult time trying to project the map extent (WGS84) into an envelope of a different spatial reference (Web Mercator or UTM). I have tried multiple ways of changing the spatial reference of an envelope, but none of them are working. I know they aren't working because I am drawing a graphic on the screen for the envelope, but nothing appears when changing the envelope to a different spatial reference. Using the map's spatial reference of WGS84 for the envelope works perfectly and it is drawn to the screen.&lt;/P&gt;&lt;P&gt;As an fyi, I am converting the envelope into a polygon, which I am using for the graphic.&lt;/P&gt;&lt;P&gt;The following are four different code attempts that I have made using Web Mercator. I have also tried with UTM:&lt;/P&gt;&lt;PRE&gt;SpatialReference sr3857 = SpatialReferenceBuilder.CreateSpatialReference(&lt;SPAN class=""&gt;3857&lt;/SPAN&gt;);
&lt;SPAN class=""&gt;// Builder constructors need to run on the MCT.&lt;/SPAN&gt;
&lt;SPAN class=""&gt;using&lt;/SPAN&gt; (SpatialReferenceBuilder srBuilder = &lt;SPAN class=""&gt;new&lt;/SPAN&gt; SpatialReferenceBuilder(&lt;SPAN class=""&gt;3857&lt;/SPAN&gt;))
{
    &lt;SPAN class=""&gt;// do something with the builder&lt;/SPAN&gt;
    sr3857 = srBuilder.ToSpatialReference();
}
ArcGIS.Core.Geometry.Polygon envPoly = &lt;SPAN class=""&gt;null&lt;/SPAN&gt;;
Envelope mapExtent = (Envelope)GeometryEngine.Instance.Project(MapView.Active.Extent, sr3857);

&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;private&lt;/SPAN&gt; Envelope &lt;SPAN class=""&gt;BuildEnvelope&lt;/SPAN&gt;(&lt;SPAN class=""&gt;MapPoint mapPt, Envelope inputEnvelope&lt;/SPAN&gt;)&lt;/SPAN&gt;
{
    EnvelopeBuilder envelopeBuilder = &lt;SPAN class=""&gt;new&lt;/SPAN&gt; EnvelopeBuilder(SpatialReferences.WebMercator);
    envelopeBuilder.XMin = inputEnvelope.XMin;
    envelopeBuilder.YMin = inputEnvelope.YMin;
    envelopeBuilder.XMax = inputEnvelope.XMax;
    envelopeBuilder.YMax = inputEnvelope.YMax;

    &lt;SPAN class=""&gt;return&lt;/SPAN&gt; envelopeBuilder.ToGeometry();
}
Envelope mapExtent = BuildEnvelope(MapView.Active.Extent)

Envelope mapExtent = EnvelopeBuilder.CreateEnvelope(MapView.Active.Extent, SpatialReferences.WebMercator);

Envelope mapExtent = EnvelopeBuilder.CreateEnvelope(MapView.Active.Extent, SpatialReferences.WebMercator);&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 21:25:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-successfully-project-the-map-extent-into-a/m-p/1150416#M7879</guid>
      <dc:creator>DaveLewis73</dc:creator>
      <dc:date>2022-03-03T21:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to successfully project the map extent into a different spatial reference</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-successfully-project-the-map-extent-into-a/m-p/1153791#M7938</link>
      <description>&lt;P&gt;I have come up with a solution for this problem with the assistance of the Esri ArcGIS Pro SDK team.&amp;nbsp; The whole idea of attempting to project the map extent into an envelope of a different spatial reference has been scrapped and replaced with a much simpler and straightforward approach.&amp;nbsp; A rectangle with four corners is created that mirrors the extent of the map, as shown in the following code snippet:&lt;/P&gt;&lt;P&gt;Size mapSize = MapView.Active.GetViewSize();&lt;BR /&gt;MapPoint pt1 = MapView.Active.ClientToMap(new Point(0, 0));&lt;BR /&gt;MapPoint pt2 = MapView.Active.ClientToMap(new Point(mapSize.Width * scale, 0));&lt;BR /&gt;MapPoint pt3 = MapView.Active.ClientToMap(new Point(mapSize.Width * scale, mapSize.Height * scale));&lt;BR /&gt;MapPoint pt4 = MapView.Active.ClientToMap(new Point(0, mapSize.Height * scale));&lt;/P&gt;&lt;P&gt;Point mapClientPt = MapView.Active.MapToClient(screenMapPt);&lt;/P&gt;&lt;P&gt;bool ptIntersects = (mapClientPt.X &amp;gt;= 0) &amp;amp;&amp;amp; (mapClientPt.Y &amp;gt;= 0) &amp;amp;&amp;amp; (mapClientPt.X &amp;lt;= mapSize.Width * scale) &amp;amp;&amp;amp; (mapClientPt.Y &amp;lt;= mapSize.Height * scale);&lt;/P&gt;&lt;P&gt;This produces the exact results that I am looking for.&amp;nbsp; Once I have the rectangle I can then check to see if the mouse intersects it or not.&lt;/P&gt;&lt;P&gt;Thanks again to the Esri ArcGIS Pro SDK team.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 14:05:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/how-to-successfully-project-the-map-extent-into-a/m-p/1153791#M7938</guid>
      <dc:creator>DaveLewis73</dc:creator>
      <dc:date>2022-03-15T14:05:26Z</dc:date>
    </item>
  </channel>
</rss>

