My goal is to provide Users the ability to draw a rectangle on a map to pass the extents back to export a .png of the extent drawn.
This would be done through a
I see potential in the Clip and Ship functionality where the User Draws a Rectangle to pass the top and bottom x,y values.
My script currently uses a County Layer to select 1 or 2 counties.
The code then zooms to selected features extent.
This is sort of hit an miss as the user needs to know what counties to select.
I want the user to draw extent instead.
In that case, the If statement would go away.
map_extent = parameters.valueAsText map_extent2 = parameters.valueAsText
outfolder = arcpy.env.scratchWorkspacemxd = r"\\Maps\MyMap.mxd"outputPath = outfolder + os.sep + "Map.png"if map_extent <> "Default Extent": expression = '"altName" IN' + " ('" + map_extent + "', '" + map_extent2 + "')" arcpy.AddMessage(expression) county_layer = arcpy.mapping.ListLayers(mxd) arcpy.AddMessage(county_layer) arcpy.SelectLayerByAttribute_management(county_layer, "NEW_SELECTION", expression) df = arcpy.mapping.ListDataFrames(mxd) df.zoomToSelectedFeatures() arcpy.RefreshActiveView()
arcpy.mapping.ExportToPNG(mxd, outputPath)arcpy.SetParameterAsText(2, outputPath)
You can probably use a combination of a Search Cursor and an extent object to set the data frame extent:
import arcpy inGeom = arcpy.GetParameter(0) mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd) for row in arcpy.da.SearchCursor(inGeom, ["SHAPE@"]): extent = row.extent df.extent = extent
I would like the user to draw an extent. Not get extent from a records in a table or feature layer.
There is a built in functionality of Extract Data Tool that passes the extent in the way I'm thinking.
When using the tool in ArcCatalog, the user would have to select a data source to clip to.
In ArcMap the tool allows you to draw a rectangle to define extents.
It uses a shape called Area_of_Interest for the deault shape type.
My script will be published to ArcGIS Server, so it will be able to use a map to draw the extent.
I think if we get as far as using the draw Area_of_Extent, that would do it.
Please see screen shot of Extract Data
Thank you again,
The parameter data type that the Area Of Interest is using above is a FeatureSet. It can be used to allow a user to either dynamically draw and input geometry (point, Line, Polygon) or browse for a Featureclass.
The important part of that parameter in the script tool is the schema property, The FeatureClass you use for the schema defines two things for the FeatureSet:
1. Geometry type
2. Field type and names
As Jonathan mentioned above you can then use a cursor to get the drawn geometry from that parameter.