Friday, January 18, 2013
10.1 SP 1 32 bit vs 64 bit
I ran across an interesting forum posting about the differences of 32 vs 64 bit python.
Check it out here: http://forums.arcgis.com/threads/70241-10.1-sp-1-and-32-64-bit-Python-versions
It's worth a good read to understand if you install the 64-bit background processor provided at SP 1 how it operates and works on your machine.
Remember if you do install the 64-bit version of python, you will have to install the 64-bit of all your extensions as well.
Enjoy
Labels:
ArcGIS 10.1,
ArcPy,
Programming,
Python Add-ins
Thursday, January 3, 2013
ArcPy 10.1 - Multiple Data Frames and Data Driven Pages
Data driven pages is a great way to automate map production over a given area, and it works right out of the box with a single data frame. If you have 2 or more data frames though, you will need to control the movement of each data frame object by performing some sort of coding (ArcObjects or ArcPy).
A simple way to move multiple data frames is to:
A simple way to move multiple data frames is to:
- Get a list of all data frames
- Identify the parent data frame
- Move the extents of the other data frame
Sounds simple? Well it is.
To get started, get a reference to the map document
mxd = arcpy.mapping.MapDocument("CURRENT")
Change "CURRENT" to a path if not run in ArcMap. Then list all the data frames
dfs = arcpy.mapping.ListDataFrames(mxd)
Now how do you know what data frame is the parent data frame or what data frame is a child data frame? Luckily at 10.1, the data driven page object provides a property called dataFrame, which returns the DataFrame object. At 10.0, you would either use names or indexing values to determine which is the parent or not, but this example is for 10.1.
ddp = mxd.dataDrivePages
parentDF = ddp.dataFrame
Next step is to pan the other data frames to the extent of the parent data frame's extent.
for pageNum in range(1, ddp.pageCount + 1):
for df in dfs:
ddp.currentPageID = pageNum
row = ddp.pageRow
extent = row.Shape.extent
if (df.name == parentDF.name) and (df.scale == parentDF.scale):
print 'I found the parent frame'
else:
df.panToExtent(extent)
arcpy.mapping.ExportToPNG(mxd, r"C:\Project\OutPut\ParcelAtlas_" + str(pageNum) + ".png")
Here we have a bunch of code that loops through each data driven page area and then modifies each underlying data frame that isn't the parent. After the data frames are changes, the code then exports the maps to PNG to the '...\output' folder with reference to the page number.
Enjoy
Labels:
ArcGIS 10.1,
ArcPy,
Programming,
Python,
Scripting
Tuesday, December 18, 2012
Using env.addOutputsToMap
The environmental variable addOutputsToMap prevents geoprocessing task results from being displayed in the TOC. This environmental property by default is set to true, so every tool's result will display in the table of contents in ArcMap.
When developing python add-ins, you should utilize this tool to prevent sub-processes results from being added to the map. A good example of this, is if your python add-in creates a table if it doesn't exist for logging purposes. Your end user does not want to see this table, or know it exists, but if addOutputsToMap is set to true, the value will display in the table of contents. Changing it to false would prevent the data from showing.
Example:
Enjoy
When developing python add-ins, you should utilize this tool to prevent sub-processes results from being added to the map. A good example of this, is if your python add-in creates a table if it doesn't exist for logging purposes. Your end user does not want to see this table, or know it exists, but if addOutputsToMap is set to true, the value will display in the table of contents. Changing it to false would prevent the data from showing.
Example:
from arcpy import env
env.addOutputsToMap = false
#... perform GP task...
env.addOutputsToMap = true
Enjoy
Labels:
ArcPy,
Programming,
Python,
Python Add-ins
Monday, December 17, 2012
Finding Distance Along A Line
The arcpy polyline geometry object has a very helpful method called positionAlongLine (value, {use_percentage}). This function finds either a distance (in the feature's coordinate system) or the percentage from the line's starting location. It then returns a PointGeometry object that can be used for further analysis, or that can be saved out as a feature class using the CopyFeatures tool. If you use the optional use_percentages, false means it's a distance, true means it is a percentage with values between 1-100. If a value is great than the length or over 100 % then the last point is used. If values are less than 0 or less than 0% then the first point is used as well.
Assuming you have a line feature class, just create a search cursor and begin accessing your locations.
fc = r"c:\temp\lines.shp" with da.SearchCursor(fc, ["SHAPE@"] as cursor: for row in cursor: print row[0].positionAlongLine(10, True)
print row[0].positionAlongLine(10, False)
Enjoy
Labels:
ArcGIS 10.1,
ArcPy,
Python,
Scripting
Wednesday, December 12, 2012
Finding and Changing Max Value in Numpy Array
Today, I answered a forum question about finding and changing a numpy array. You can use the max() and the where() in the numpy to search for values in your array and change them using loops.
Here we have the numpy array and find the array's maximum value. Then using the where(), the location in the array are given back. From there, the code then changes the values in the 2-D array from the maximum value back to zero.
Enjoy
You can download a very simple example here.
Here is the simple code:
import numpy
myarray = numpy.array([[ 5.4, 7.5, 2.2, 8.5, 8.6, 7.5],
[ 7.7, 3.5, 1.4, 9.6, 8.5, 5.5],
[ 5.2, 6.1, 8.6, 6.7, 4.3 , 6.8],
[ 9.6, 4.5, 2.7, 3.6, 6.7, 4.5],
[ 1.2, 2.3, 7.2, 6.3, 2.2, 2.0 ],
[ 1.3, 2.0, -99.0, 9.6, -99.0, 1.2]
]
)
print myarray
maxValue = myarray.max()
itemindex = numpy.where(myarray >= maxValue)
for i in xrange(0, len(itemindex[0])):
array1 = itemindex[0]
array2 = itemindex[1]
myarray[array1[i]][array2[i]] = 0
print myarray
Here we have the numpy array and find the array's maximum value. Then using the where(), the location in the array are given back. From there, the code then changes the values in the 2-D array from the maximum value back to zero.
Enjoy
Thursday, December 6, 2012
Tuesday, December 4, 2012
AGS 10.1 Quirk with Windows Domain Security
Today I configured a test machine to use windows domain accounts at the GIS tier for security. When I went to connect to the site using catalog, I noticed that if I included the '\' (backslash) in the user name it could not connect. After removing the backslash, the connection worked.
This means that if your user is 'domainname\name' you would use just the 'name' in the AGS connection string.
This means that if your user is 'domainname\name' you would use just the 'name' in the AGS connection string.
Labels:
ArcGIS 10.1
Subscribe to:
Posts (Atom)