<?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 Geometry union at antimeridian in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geometry-union-at-antimeridian/m-p/1352910#M82912</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have to union many extents all over the globe, including antimeridian (180th meridian) on both sides and crossing.&lt;/P&gt;&lt;P&gt;I cannot get to have extents on both sides of 180th meridian to merge :&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/Chris_Siveco/pen/JjxvpvJ?editors=1000" target="_blank" rel="noopener"&gt;https://codepen.io/Chris_Siveco/pen/JjxvpvJ?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Only one side extents are merging. The one that is crossing 180th meridian is merging ok, and the one on the left also. But not the one on the right.&lt;/P&gt;&lt;P&gt;Is there a way to achieve this ?&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
    <pubDate>Thu, 23 Nov 2023 10:10:12 GMT</pubDate>
    <dc:creator>ChristopheS</dc:creator>
    <dc:date>2023-11-23T10:10:12Z</dc:date>
    <item>
      <title>Geometry union at antimeridian</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geometry-union-at-antimeridian/m-p/1352910#M82912</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have to union many extents all over the globe, including antimeridian (180th meridian) on both sides and crossing.&lt;/P&gt;&lt;P&gt;I cannot get to have extents on both sides of 180th meridian to merge :&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/Chris_Siveco/pen/JjxvpvJ?editors=1000" target="_blank" rel="noopener"&gt;https://codepen.io/Chris_Siveco/pen/JjxvpvJ?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Only one side extents are merging. The one that is crossing 180th meridian is merging ok, and the one on the left also. But not the one on the right.&lt;/P&gt;&lt;P&gt;Is there a way to achieve this ?&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2023 10:10:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geometry-union-at-antimeridian/m-p/1352910#M82912</guid>
      <dc:creator>ChristopheS</dc:creator>
      <dc:date>2023-11-23T10:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Geometry union at antimeridian</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geometry-union-at-antimeridian/m-p/1353734#M82936</link>
      <description>&lt;P&gt;It is because on line 73. ext1 and ext3 do not intersect &lt;U&gt;numerically speaking&lt;/U&gt;.&amp;nbsp; That is, before the call to union, here is the state of things:&lt;/P&gt;&lt;P&gt;ext1: (150, 50) -&amp;gt; (210, 80)&lt;/P&gt;&lt;P&gt;ext3: (-175, 55) -&amp;gt; (-120, 65)&lt;/P&gt;&lt;P&gt;As you can see, if you put this on a simple cartesian plane, they won't intersect.&amp;nbsp; &amp;nbsp;You can add some functionality to adjust the geometries one rotation around the world to the east or west to get what you're looking for like so:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;title&amp;gt;
      Intro to graphics | Sample | ArcGIS Maps SDK for JavaScript 4.28
    &amp;lt;/title&amp;gt;
    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.28/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.28/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
      }
    &amp;lt;/style&amp;gt;
    &amp;lt;script&amp;gt;
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/Graphic",
        "esri/geometry/Polygon",
        "esri/geometry/Extent",
        "esri/geometry/geometryEngine"
      ], (Map, MapView, Graphic, Polygon, Extent, GeometryEngine) =&amp;gt; {
        const map = new Map({
          basemap: "hybrid"
        });

        const view = new MapView({
          center: [-180, 60],
          container: "viewDiv",
          map: map,
          zoom: 3
        });

        var ext1 = new Extent({
          xmin: 170.0,
          ymin: 56.0,
          xmax: -170.0 + 360,
          ymax: 70.0
        });

        drawAThing(ext1);
        //-----------------
        var ext2 = new Extent({
          xmin: 150.0,
          ymin: 50.0,
          xmax: -150.0 + 360,
          ymax: 80.0
        });
        drawAThing(ext2);

        var ext3 = new Extent({
          xmin: -175.0,
          ymin: 55.0,
          xmax: -120.0,
          ymax: 65.0
        });
        drawAThing(ext3);

        var ext4 = new Extent({
          xmin: 140.0,
          ymin: 54.0,
          xmax: 175,
          ymax: 57.0
        });
        drawAThing(ext4);

        view.on("click", function (evt) {
          //-------------------
          alert("union ready ?");
          view.graphics.removeAll();
          var geom = unionGeometries(ext1, ext2);
          geom = unionGeometries(geom, ext3);
          geom = unionGeometries(geom, ext4);

          drawAThing(geom);
          //-------------------
        });

        function drawAThing(geo) {
          // Create a symbol for rendering the graphic
          var fillSymbol = {
            type: "simple-fill", // autocasts as new SimpleFillSymbol()
            color: [227, 139, 79, 0.8],
            outline: {
              // autocasts as new SimpleLineSymbol()
              color: [255, 255, 255],
              width: 1
            }
          };

          // Add the geometry and symbol to a new graphic
          var graphic = new Graphic({
            geometry: geo,
            symbol: fillSymbol
          });
          view.graphics.addMany([graphic]);
        }

        function unionGeometries(geometry, extent) {
          if (!extent.intersects(geometry)) {
            var extent2 = extent.clone();
            extent2.xmax += 360;
            extent2.xmin += 360;

            if (extent2.intersects(geometry))
              return GeometryEngine.union([geometry, extent2]);
            else {
              extent2.xmin -= 720;
              extent2.xmax -= 720;

              if (extent2.intersects(geometry))
                return GeometryEngine.union([geometry, extent2]);
            }
          }

          return GeometryEngine.union([geometry, extent]);
        }
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, the unionGeometries function was added, and the "extN" objects were created as full-on Extent objects to make this work.&amp;nbsp; Note this only works if geometries are offset by no more than one rotation.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 20:09:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geometry-union-at-antimeridian/m-p/1353734#M82936</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-11-27T20:09:17Z</dc:date>
    </item>
  </channel>
</rss>

