Convert Extent to Polygon

8851
7
09-22-2010 12:23 PM
New Contributor
Is there a way to convert an Extent object to a Polygon object?  I need to create a tool that allows the user to draw an extent rectangle and then store this object in a polygon feature class.
Tags (2)
1 Solution

Accepted Solutions
Esri Contributor
Hi,

Good question.  Yes, you can because an Extent object has the following properties.

-xmax (Top-right X-coordinate of an extent envelope)
-xmin (Number  Bottom-left X-coordinate of an extent envelope)
-ymax (Number  Top-right Y-coordinate of an extent envelope)
-ymin (Bottom-left Y-coordinate of an extent envelope)

Provided that you have these properties, you can use each coordinate value to create a new Polygon.

Ex.

var polygon = new esri.geometry.Polygon(new esri.SpatialReference({wkid:4326}));

Remember to add points clockwise and finish by having the last point be the same as the first point in the parameters.

Regards,
Doug Carroll, ESRI Support Services SDK Team
http://support.esri.com/
7 Replies
Esri Contributor
Hi,

Good question.  Yes, you can because an Extent object has the following properties.

-xmax (Top-right X-coordinate of an extent envelope)
-xmin (Number  Bottom-left X-coordinate of an extent envelope)
-ymax (Number  Top-right Y-coordinate of an extent envelope)
-ymin (Bottom-left Y-coordinate of an extent envelope)

Provided that you have these properties, you can use each coordinate value to create a new Polygon.

Ex.

var polygon = new esri.geometry.Polygon(new esri.SpatialReference({wkid:4326}));

Remember to add points clockwise and finish by having the last point be the same as the first point in the parameters.

Regards,
Doug Carroll, ESRI Support Services SDK Team
http://support.esri.com/
New Contributor
That worked....thanks!
New Contributor
A toPolygon() method was added on the Extent class at v2.3.

http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/geometry/Extent.html#toPolygon()
New Contributor II
I"m getting a weird thing.   The toPolgyon method is in the API reference, yes, but it is not available in the dev environment (Flash Builder 4.6).    However, intellisense is showing me a toString method from the Extent class and this method is not in the API reference.   ?????

I'm using the most recent ArcGIS api.

Thanks,
New Contributor II
Something still isn't right in the API, but I have a workaround to be able to use toPolygon().    Declare the extent with a fully qualified class name (com.esri.ags.geometry.Extent).    The intellisense still will not provide toPolygon() but use it anyway.   The IDE will only give a warning and the code will compile and run fine.

-Greg
by
Esri Regular Contributor
@Greg, just a clarification: this is the JavaScript forum and I think you are referring to the Flex API (re: FlashBuilder). If you still have a question you may want to repost over in the Flex API Forum: http://forums.arcgis.com/forums/18-ArcGIS-API-for-Flex

-Andy
Esri Developer Network
New Contributor II

Can this be done in ArcGIS Pro as well?