Why doesn't GeometryEngine.Union perform the union?

1602
2
03-29-2017 10:46 AM
MarkCammarere
New Contributor III

I'm trying to union two valid (polygon) geometries (they both have valid extents and spatial references), but when I do the Union, I get an empty geometry with NaN extent:

Geometry aGeom = GeometryEngine.Union(aGeom1, aGeom2);

The input geometries (aGeom1, aGeom2) are rectangular polygons in the WGS84 spatial reference (WKID = 4326). I've even tried unioning one of the geometries with itself - and I still get an empty geometry. Please help!

Tags (2)
0 Kudos
2 Replies
TonyWakim
Esri Contributor

Couple of points:

- Make sure both the Geometries have the same Spatial Reference (which you mentioned is WGS84, but just to double check)

- Try calling GeometryEngine.Simplify() on the Geom1 and Geom2 before using them in the Union and see if that helps.

If this does not help, please provide the version of Runtime .Net that you are using. And if possible the coordinates for the Geometries you are using in the Union operation.

Thanks,

Tony Wakim

0 Kudos
JenniferNery
Esri Regular Contributor

Can you share the input geometries? I'm unable to reproduce with the following code:

var geom1 = Esri.ArcGISRuntime.Geometry.Geometry.FromJson("{\"rings\":[[[74,27],[83,27],[83,21],[74,21],[74,27]]],\"spatialReference\":{\"wkid\":4326}}");
var geom2 = Esri.ArcGISRuntime.Geometry.Geometry.FromJson("{\"rings\":[[[78,29],[87,29],[87,22],[78,22],[78,29]]],\"spatialReference\":{\"wkid\":4326}}");
var geom3 = GeometryEngine.Union(geom1, geom2);‍‍‍‍‍‍

I also tried to interactively draw the rectangle and perform the union of those. This will create geometries in the same reference as the map. 

private async void Button_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var geom1 = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);
        var geom2 = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);
        var geom3 = GeometryEngine.Union(geom1, geom2);
        var graphic = new Graphic(geom3, new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Colors.Blue, null));
        var overlay = MyMapView.GraphicsOverlays[0];
        overlay.Graphics.Add(graphic);
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Can you see if calling GeometryEngine.Simplify to input geometries before calling Union, returns a valid union geometry?

0 Kudos