Thursday, March 28, 2013

Support GUI Design in ArcGIS for Desktop

Please support this idea of having GUI designer in python built in with python add-ins.

It can be found here: http://ideas.arcgis.com/ideaView?id=087E00000004SmHIAU

Thanks everyone.

Wednesday, March 27, 2013

Creating Data Frame Extents (ArcPy 10.1)

I read your comments, and thank you for posting them.  I was asked how do you clip all layers in a map document by the current data frame's extent.

In a previous post, I discussed how to create extent polygons for feature classes and individual features.  The same method applies for creating an extent polygon using data frames.

The data frame object has a whole host of properties and methods which can be found here.  To get the extent of a data frame, just reference the extent property to obtain the data frame's current extent.  Create the extent polygon or feature class, and clip by the extent geometry.

# Clip layers by extent of data frame (assuming in arcmap session)
import os
import arcpy
from arcpy import env
from arcpy import mapping
mxd = mapping.MapDocument("CURRENT")
df = mxd.activeDataFrame
extent = df.extent
array = arcpy.Array()
array.add(extent.lowerLeft)
array.add(extent.lowerRight)
array.add(extent.upperRight)
array.add(extent.upperLeft)
array.add(extent.lowerLeft)
polygon = arcpy.Polygon(array, df.spatialReference)
array.removeAll()
del array
for layer in mapping.ListLayers(mxd, data_frame=df):
    clipped_fc = env.scratchGDB + os.sep + layer.datasetName + "_clipped"
    arcpy.Clip_analysis(in_features=layer, 
                        clip_features=polygon,
                        out_feature_class=clipped_fc)
    del layer
del mxd
del df
del extent

This code is just a quick re-hash of old concepts applied to a new method. The extent object creates a polygon, which is used to clip the layers in that data frame.

Friday, March 22, 2013

ArcGIS for Developers

Today I noticed a new site from Esri, and it's called 'ArcGIS for Developers'.  This website consolidates the web, mobile, and introduces some new desktop APIs.

The one that really excites me is the Qt API because I'm a fan of C++.  I also introduces the new approach to open for Esri by using GitHub for code sharing.  I've only started playing, but I'm excited to see what comes.

Check it out here: http://developers.arcgis.com/en/

Happy coding.


Wednesday, March 13, 2013

The random Module (python)

The random module is pseudo-random number generator.  This means that's truly not random, but close enough.

You should seed, initialize the generator with either a value, or with the system time (default value).

Example:

>>> import random
>>> random.seed()
>>> print random.random()
0.884447776659
>>> print random.random()
0.379767969805
>>> print random.random()
0.580327390006

Random also has the ability to pick from ranges and collection of elements, like letter:

>>> random.randrange(start=0, stop=101, step=1)
52
>>> random.choice('abcdefghij')
'b'


Happy Randomness.