Hi, Looking at the GeometryBag in the SDK the extent property is not implemented. Is there another way of getting the extent of the added geometries in the GeometryBag. The samples show how to add geometries using the GeometryBagBuilder, get the GeometryBag and check the geometries added. But not all the functionality as in ArcObjects. Am I missing something?
SDK: ArcGIS Pro 2.4 API Reference Guide
Samples: ProSnippets Geometry · Esri/arcgis-pro-sdk Wiki · GitHub
Thank you.
Martin
Solved! Go to Solution.
This works for me with 2.9 (see Extent at end)
private static void Test()
{
//from here: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic20909.html
using (GeometryBagBuilder builder = new GeometryBagBuilder(SpatialReferences.WGS84))
{
GeometryBag emptyBag = builder.ToGeometry();
// emptyBag.IsEmpty = true
MapPoint point = MapPointBuilder.CreateMapPoint(1, 2, SpatialReferences.WebMercator);
builder.AddGeometry(point);
// builder.CountGeometries = 1
GeometryBag geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 1
// geometryBag.PointCount = 1
// geometryBag.IsEmpty = false
IReadOnlyList<Geometry> geometries = geometryBag.Geometries;
// geometries.Count = 1
// geometries[0] is MapPoint with a sr of WGS84
bool isEqual = geometryBag.IsEqual(emptyBag); // isEqual = false
List<Coordinate2D> coords2D = new List<Coordinate2D>()
{
new Coordinate2D(0, 0),
new Coordinate2D(0, 1),
new Coordinate2D(1, 1),
new Coordinate2D(1, 0)
};
Multipoint multipoint = MultipointBuilder.CreateMultipoint(coords2D, SpatialReferences.WGS84);
builder.InsertGeometry(0, multipoint);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2
geometries = geometryBag.Geometries;
// geometries.Count = 2
// geometries[0] is Multipoint
// geometries[1] is MapPoint
Polyline polyline = PolylineBuilder.CreatePolyline(coords2D, SpatialReferences.WebMercator);
builder.AddGeometry(polyline);
//builder.RemoveGeometry(1);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2
geometries = geometryBag.Geometries;
// geometries.Count = 2
// geometries[0] is Multipoint
// geometries[1] is Polyline
var ext = geometryBag.Extent;
Console.WriteLine(ext.ToJson());
}
}
Hi Martin,
Try iterating through the geometries in the geometrybag, calling the Extent property on each, adding all the extents into a List<Geometry>
Then use the GeometryEngine.Instance.Union method.
Assuming all your geometries in the bag are of the same spatial reference this should work.
I'll add an issue to make sure we look at adding an implementation for the GeometryBag.Extent function.
Thanks
Narelle
Hi Narelle,
Thank you for your message.
I tried your suggestion but getting "ArcGIS.Core.Geometry.GeometryObjectException: 'GeometryObjectException: The geometry parameter was of the wrong type for the method.'". I'm working with different types of geometries, Points, Lines and some times polygons as one set for the GeometryBag to get the extent of all in GeometryBag. Think it doesn't like the extents of the points when doing the GeometryEngine.Instance.Union.
I added a workaround for the interim where I calculate the xMin, xMax, yMin and yMax from all the geometry extents and use the EnvelopeBuilder.CreateEnvelope(xMin, yMin, xMax, yMax, toSpatialReference) to build the smallest Envelope.
Thank you for looking into it.
Regards,
Martin
Hey Narelle,
This is still not implemented in 2.8.1, and I don't see anything in the 2.9 release notes that implies a fix there either. Do you know when this will be implemented?
I tried the same workaround you recommended but got the same error as Martin. The workaround I'm using is to keep a list of Polygons and build a Multipoint with the points, call union on the polygon list, then union that extent with the Multipoint extent.
Thanks,
Stephen
This works for me with 2.9 (see Extent at end)
private static void Test()
{
//from here: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic20909.html
using (GeometryBagBuilder builder = new GeometryBagBuilder(SpatialReferences.WGS84))
{
GeometryBag emptyBag = builder.ToGeometry();
// emptyBag.IsEmpty = true
MapPoint point = MapPointBuilder.CreateMapPoint(1, 2, SpatialReferences.WebMercator);
builder.AddGeometry(point);
// builder.CountGeometries = 1
GeometryBag geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 1
// geometryBag.PointCount = 1
// geometryBag.IsEmpty = false
IReadOnlyList<Geometry> geometries = geometryBag.Geometries;
// geometries.Count = 1
// geometries[0] is MapPoint with a sr of WGS84
bool isEqual = geometryBag.IsEqual(emptyBag); // isEqual = false
List<Coordinate2D> coords2D = new List<Coordinate2D>()
{
new Coordinate2D(0, 0),
new Coordinate2D(0, 1),
new Coordinate2D(1, 1),
new Coordinate2D(1, 0)
};
Multipoint multipoint = MultipointBuilder.CreateMultipoint(coords2D, SpatialReferences.WGS84);
builder.InsertGeometry(0, multipoint);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2
geometries = geometryBag.Geometries;
// geometries.Count = 2
// geometries[0] is Multipoint
// geometries[1] is MapPoint
Polyline polyline = PolylineBuilder.CreatePolyline(coords2D, SpatialReferences.WebMercator);
builder.AddGeometry(polyline);
//builder.RemoveGeometry(1);
geometryBag = builder.ToGeometry();
// geometryBag.PartCount = 2
geometries = geometryBag.Geometries;
// geometries.Count = 2
// geometries[0] is Multipoint
// geometries[1] is Polyline
var ext = geometryBag.Extent;
Console.WriteLine(ext.ToJson());
}
}
Thanks for the nudge, @KirkKuykendall1. I installed 2.9 on a VM, and it is indeed implemented! If I could mark your response as the answer, I would.