What is the quickest way to convert an Envelope to a Polygon?

627
1
Jump to solution
05-03-2018 09:13 PM
PaulHaakma
Regular Contributor

In Runtime 100.x, what is the quickest way to convert an Envelope into a Polygon?

I seem to remember the old runtime had a method on an Envelope something like myEnv.toPolygon(), nice and easy. Now I have use a PolygonBuilder I assume? And I can't just set the geometry of it to an existing Envelope object as it doesn't seem to accept it.

An Envelope doesn't seem to have a PointCollection, so I can't even add from that. All it seems to have are xMax, xMin etc. Do I really have to cycle through and construct four points and add them one by one to the PolygonBuilder?

A way I found was to use GeometryEngine.buffer(myEnv, 0)  but that seems a bit hacky. It works, I'm just wondering if I'm missing some other simple way.

Cheers,

-Paul

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LukeSmallwood
Esri Contributor

Hi Paul,

I believe you should be able to use the boundary method on GeometryEngine (GeometryEngine QML Type | ArcGIS for Developers) to obtain the polyline boundary of the Envelope. Then you can use the polyline to construct your Polygon.

It might still be more efficient to construct the polygon directly from the xMin, xMax, yMin, yMax of the original envelope though.

I hope that helps,

Luke 

View solution in original post

0 Kudos
1 Reply
LukeSmallwood
Esri Contributor

Hi Paul,

I believe you should be able to use the boundary method on GeometryEngine (GeometryEngine QML Type | ArcGIS for Developers) to obtain the polyline boundary of the Envelope. Then you can use the polyline to construct your Polygon.

It might still be more efficient to construct the polygon directly from the xMin, xMax, yMin, yMax of the original envelope though.

I hope that helps,

Luke 

View solution in original post

0 Kudos