Select to view content in your preferred language

Convert Extent to Polygon

11563
7
Jump to solution
09-22-2010 12:23 PM
LoriDavis
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.
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
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}));
polygon.addRing([[-180,-90],[-180,90],[180,90],[180,-90],[-180,-90]]);


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/

View solution in original post

0 Kudos
7 Replies
by Anonymous User
Not applicable
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}));
polygon.addRing([[-180,-90],[-180,90],[180,90],[180,-90],[-180,-90]]);


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/
0 Kudos
LoriDavis
New Contributor
That worked....thanks!
0 Kudos
MichaelHaggerty
Emerging 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()
0 Kudos
GregNichols
Emerging Contributor
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,
0 Kudos
GregNichols
Emerging Contributor
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
0 Kudos
AndyGup
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
0 Kudos
AaronFerrari
Occasional Contributor

Can this be done in ArcGIS Pro as well?

0 Kudos