Wednesday, September 28, 2011

Turning on labels through ArcPy

The Layer object in the ArcPy module allows python developers to turn on labels of a feature class on and off at run time.  This is especially helpful if you are exporting maps and you want to control what Layers are labeled.
Example: Turning on Labels
import arcpy
from arcpy import mapping
fc = r"c:\temp\fc.shp"
tempLayer = "tempLayer"
arcpy.MakeFeatureLayer_management(fc, tempLayer)
#   Make the Layer Object
#
layer = mapping.Layer(tempLayer)
layer.showLabels = True
#   Show the changes in ArcMap
#
arcpy.RefreshActiveView()
del layer 


Enjoy

Tuesday, September 27, 2011

Usage() - Arcpy

Usage() is a helpful tool that will return the syntax for a specific tool.  It's a great thing to use in IDLE when writing a python script and you forget what variables go where.

Example:
>>> import arcpy
>>> print arcpy.Usage("Buffer_analysis")
Buffer_analysis(in_features, out_feature_class, buffer_distance_or_field, {FULL | LEFT | RIGHT | OUTSIDE_ONLY}, {ROUND | FLAT}, {NONE | ALL | LIST}, {dissolve_field;dissolve_field...})
Buffer Features
>>> print arcpy.Usage("MakeFeatureLayer_management")
MakeFeatureLayer_management(in_features, out_layer, {where_clause}, {workspace}, {field_info}) Create a Feature Layer

Pretty help for those who don't have to refer to the help document all the time.
Enjoy!

Monday, September 19, 2011

A Quick Note on Multiprocessing

If you create a multiprocessing script and you want to use the python script in ArcToolbox, ensure the following settings are set on your script:
1. Show command window when executing is unchecked
2. Run python script in process is unchecked

Your python script should now multi-process if you wrote it correctly.

Enjoy


Tuesday, September 6, 2011

Finding Disk Size

Ever need to know how much space is left on a disk drive, well I did when creating map books for large areas. import os 
import platform
import ctypes 
def get_free_space(folder):
   """ Return folder/drive free space (in bytes) """ 
   if platform.system() == 'Windows': 
      free_bytes = ctypes.c_ulonglong(0)
      ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) return free_bytes.value 
   else: 
      return os.statvfs(folder).f_bfree 
if __name__ == "__main__":
   path = (r"network drive") 
   print get_free_space(path) 

This prints the free space as bytes. It is cross platform and will work on both Linux,MaxOS and Windows. Enjoy