POST
|
The Make Feature Layer tool had the workspace specified (a variable in the model). Once I removed the entry, the tool worked. Still, it worked with the workspace specified before, and then it stopped... Inconsistency.
... View more
07-02-2014
09:37 AM
|
1
|
1
|
469
|
POST
|
This seems to be a bug because it behaves differently. If I try to run individual tools within my model one by one, the Make Feature Layer tool adds layers to TOC if I uncheck the "Add To Display" and "Model Parameter" options in the context menu of the output layer (and I do have the "Add results of geoprocessing operations to the display" ticked on in the Geoprocessing tab of the File>Options dialog in ArcMap). When I ran the tools the same way in my previous ArcMap session, "Add To Display" and "Model Parameter" options were checked and the layers were added. Then it stopped working...
... View more
07-02-2014
08:34 AM
|
0
|
0
|
469
|
POST
|
# Import modules
import arcpy
from datetime import datetime
# Define variables
surveyDateEnteredFld = "DATENTERED" # existing text field
surveyDateFld = "SURVEY_DATE"
expression = "formatDate(!" + surveyDateEnteredFld + "!)"
codeBlock = """def formatDate(datestr):
d = datetime.datetime.strptime(datestr, '%m%d%Y')
return d"""
# Add and calculate new date field
arcpy.AddField_management(outputTableView, surveyDateFld, "DATE")
arcpy.CalculateField_management(outputTableView, surveyDateFld, expression, "PYTHON", codeBlock)
... View more
06-25-2013
06:16 AM
|
0
|
0
|
258
|
POST
|
Greetings! I need help with accessing field description in feature classes using Python. So far, I've made a Python script that does the following (see attached): gets a list of feature classes from a workspace, gets a list of fields in each of those fcs outputs field names and their info to a csv file Now I'd like to add fields description to each field as it is displayed in the metadata. Is there an easy way to do this? I was thinking of exporting metadata to an xml file and reading the field description from there... but seems like there may be an easier way. Thank you,
... View more
11-08-2012
10:10 AM
|
0
|
0
|
371
|
POST
|
That's the weird thing: that doesn't work. I've also tried to refresh the view and TOC but this must be something to do with the group layer... arcpy.RefreshActiveView() arcpy.RefreshTOC()
... View more
11-23-2011
06:55 AM
|
0
|
0
|
1470
|
POST
|
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0] targetGroupLayer = arcpy.mapping.ListLayers(mxd, "24000 Scale Data", df)[0] addLayer = arcpy.mapping.Layer(r"C:\Project\Data\StreetsWithLabels.lyr") arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM") mxd.saveACopy(r"C:\Project\Project2.mxd") del mxd, addLayer That works, except a layer is only added to a group layer in the new mxd - C:\Project\Project2.mxd - not the current mxd if you are using the Python window from within ArcMap.
... View more
11-23-2011
05:44 AM
|
0
|
0
|
1470
|
POST
|
Hello, I have a Python script that creates a .KMZ file, renames it to .ZIP, extracts the files from the .ZIP into a folder, replaces text inside the doc.kml (adds screen overlay). The next step I thought would be to put the .kml file back in the .ZIP and rename the .ZIP back to .KMZ, but I cannot get Python to do that for me. Here's the piece I think I need to change (the entire Python script is attached): # open the zipped file for writing zfile = zipfile.ZipFile( basecamp + newZIP, 'w' ) arcpy.AddMessage('opened the zip file for writing') print 'opened the zip file for writing' KMLData = open(basecamp + KMLFile, 'r') for info2 in zfile.infolist(): fname2 = info2.filename if fname2 == basecamp + newZIP + KMLFile: KMLWrite = open(fname2, 'w') KMLWrite.write(KMLData) KMLWrite.close() arcpy.AddMessage( 'KML replaced successfully') print 'KML replaced successfully' KMLData.close() zfile.close()
... View more
10-26-2011
11:11 AM
|
0
|
0
|
1126
|
POST
|
How to convert .TAB to ArcGIS 10 feature class: 1. Activate Data Interoperability extension 2. In ArcToolbox, double-click Data Interoperability Tools 3. Click Quick Import 4. Select the format, .TAB dataset, and click OK 5. Enter the new output file geodatabase 6. Click OK
... View more
08-26-2011
07:17 AM
|
0
|
0
|
1299
|
POST
|
Is there a way to do this? #################### try: # 9.2 and beyond import arcgisscripting, collections, arcpy, sys, os gp = arcgisscripting.create() except: # 9.1 and before import win32com.client, collections, arcpy, sys, os gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Set version gp.SetProduct("ArcEditor") # Set the workspace gp.workspace = ("M:\") # Publish map to PMF gp.blankblankblankblank # Package PMF gp.blankblankblankblank
... View more
04-01-2011
12:09 PM
|
0
|
0
|
220
|
POST
|
How can add a different field size for the Feat_Code field in the output? I think the problem here is that the entry I mentioned above - �??22.5degelbow�?? - is 12 characters long, and the output file has size = 11
... View more
01-26-2011
07:21 AM
|
0
|
0
|
383
|
POST
|
Thank you, Harles. I did get the code to work somewhat (added +"/Export/" after every dir+"/") but apparently there are some limitations to field entries... That is disappointing. It starts OK, and this is the error I get at the end: Start Time: Wed Jan 26 12:01:16 2011 ERROR 000278: Failed on input OID 31, could not write value â??22.5degelbowâ?? to output field Feat_Code Failed to execute (Merge). Failed at Wed Jan 26 12:01:24 2011 (Elapsed Time: 8.00 seconds) *** ERROR: Shapefiles (Point) failed to merge *** Here is the code that somewhat works:
# This script will merge all point shapefiles in subfolders
# of the workspace specified below
# Import modules and create the geoprocessor object
try:
# 9.2 and beyond
import arcgisscripting, collections, arcpy, sys, os
gp = arcgisscripting.create()
except:
# 9.1 and before
import win32com.client, collections, arcpy, sys, os
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
# Set version
gp.SetProduct("ArcEditor")
# Set the workspace
gp.workspace = ("C:/Trimble Geomatics Office/Projects")
# Start a blank list for Polygon files
# polyList = []
# Start a blank list for Point files
pointList = []
# For each subdirectory
for dir in os.listdir(gp.workspace):
if os.path.isdir(gp.workspace+"/"+dir+"/Export/"):
# Get a list of the files in each directory
files = os.listdir(gp.workspace+"/"+dir+"/Export/")
# For each file in a given directory
for file in files:
# Get only files that end with .shp
if (file.endswith(".shp")):
print file
# Describe feature class
desc = gp.Describe(gp.workspace+"/"+dir+"/"+"/Export/"+file)
type = desc.ShapeType
#print dir+"/"+file + " type is: " + type
#if type == "Polygon":
# print dir+"/"+file + " is Polygon"
# polyPath = polyList.append(dir+"/"+file)
if type == "Point":
print dir+"/"+file + " is Point"
pointPath = pointList.append(dir+"/"+"/Export/"+file)
# Hard-code the output merged shapefile names
# polyshapefile = "Mergedpoly.shp"
pointshapefile = "Mergedpoint2.shp"
# Given a list of shapefiles, separate each by a ";"
# and put quotes around the whole thing
# def polyshpList(polyPath):
# return '"%s"' % ';'.join(polyList)
def pointshpList(pointPath):
return '"%s"' % ';'.join(pointList)
# Set the variable to the newly formatted list of shapefiles
# polymergedlist = polyshpList(polyPath)
pointmergedlist = pointshpList(pointPath)
# Polygons
# try:
# print "\nMerging " + polymergedlist + " to get " + polyshapefile + "...\n"
# gp.merge_management(polymergedlist, polyshapefile)
#print gp.getMessages()
#except:
# print gp.getMessages()
# print "\n *** ERROR: Shapefiles (Polygon) failed to merge *** \n"
# Points
try:
print "\nMerging " + pointmergedlist + " to get " + pointshapefile + "...\n"
gp.merge_management(pointmergedlist, pointshapefile)
print gp.getMessages()
except:
print gp.getMessages()
print "\n *** ERROR: Shapefiles (Point) failed to merge *** \n"
print "\nDone."
... View more
01-26-2011
07:10 AM
|
0
|
0
|
383
|
POST
|
I thought so, too! 1.) gp.workspace needs forward slashes (or another correct form) - you can't use backslashes - did not make a difference when I changed it 2.) you need a full path to the file instead of dir+"/"+file (depending on where your running the script from). 3.) the shapefile is not "Point". shapefiles are points Could it be because the shapefiles are buried in folders as shown in the attached image?
... View more
01-26-2011
06:05 AM
|
0
|
0
|
383
|
POST
|
Hi, Everyone, I am new to Python. I've copied the code you have posted here and modified it: 1. set the product to ArcEditor 2. commented out the code for polygon shp merging (I only need to merge points) 3. I saved it in the C:\Python26\ArcGIS10.0\Scripts directory as MergeSHP.py I am getting the following error when run the module: Traceback (most recent call last): File "C:\Python26\ArcGIS10.0\Scripts\MergeSHP.py", line 62, in <module> pointmergedlist = pointshpList(pointPath) NameError: name 'pointPath' is not defined Apparently the line def pointshpList(pointPath): doesn't work... Any help? Thank you # This script will merge all point shapefiles in subfolders # of the workspace specified below # Import modules and create the geoprocessor object try: # 9.2 and beyond import arcgisscripting, collections, arcpy, sys, os gp = arcgisscripting.create() except: # 9.1 and before import win32com.client, collections, arcpy, sys, os gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Set version gp.SetProduct("ArcEditor") # Set the workspace gp.workspace = ("W:\GPS\Trimble_Jobs\Trimble_Geomatics_Office\Projects") # Start a blank list for Polygon files # polyList = [] # Start a blank list for Point files pointList = [] # For each subdirectory for dir in os.listdir(gp.workspace): if os.path.isdir(gp.workspace+"/"+dir): # Get a list of the files in each directory files = os.listdir(gp.workspace+"/"+dir) # For each file in a given directory for file in files: # Get only files that end with .shp if (file.endswith(".shp")): print file # Describe feature class desc = gp.Describe(gp.workspace+"/"+dir+"/"+file) type = desc.ShapeType #print dir+"/"+file + " type is: " + type #if type == "Polygon": # print dir+"/"+file + " is Polygon" # polyPath = polyList.append(dir+"/"+file) if type == "Point": print dir+"/"+file + " is Point" pointPath = pointList.append(dir+"/"+file) # Hard-code the output merged shapefile names # polyshapefile = "Mergedpoly.shp" pointshapefile = "Mergedpoint.shp" # Given a list of shapefiles, separate each by a ";" # and put quotes around the whole thing # def polyshpList(polyPath): # return '"%s"' % ';'.join(polyList) def pointshpList(pointPath): return '"%s"' % ';'.join(pointList) # Set the variable to the newly formatted list of shapefiles # polymergedlist = polyshpList(polyPath) pointmergedlist = pointshpList(pointPath) # Polygons # try: # print "\nMerging " + polymergedlist + " to get " + polyshapefile + "...\n" # gp.merge_management(polymergedlist, polyshapefile) #print gp.getMessages() #except: # print gp.getMessages() # print "\n *** ERROR: Shapefiles (Polygon) failed to merge *** \n" # Points try: print "\nMerging " + pointmergedlist + " to get " + pointshapefile + "...\n" gp.merge_management(pointmergedlist, pointshapefile) print gp.getMessages() except: print gp.getMessages() print "\n *** ERROR: Shapefiles (Point) failed to merge *** \n" print "\nDone."
... View more
01-26-2011
04:50 AM
|
0
|
0
|
383
|
POST
|
I've copied and modified the script you have posted here, and it fails at gp. in the beginning :confused:, telling me a SyntaxError:invalid syntax Fun times! 🙂 # Import modules and create the geoprocessor object try: # 9.2 and beyond import arcgisscripting, sys, os gp = arcgisscripting.create() # Set the product gp.SetProduct(�??ArcEditor�?�) # Set the workspace gp.workspace = ("W:\GPS\Trimble_Jobs\Trimble_Geomatics_Office\Projects\") # Start a blank list for Point files pointList = [] # For each subdirectory for dir in os.listdir(gp.workspace): if os.path.isdir(gp.workspace+"/"+dir): # Get a list of the files in each directory files = os.listdir(gp.workspace+"/"+dir) # For each file in a given directory for file in files: # Get only files that end with .shp if (file.endswith(".shp")): print file # Describe feature class desc = gp.Describe(gp.workspace+"/"+dir+"/"+file) type = desc.ShapeType #print dir+"/"+file + " type is: " + type if type == "Point": print dir+"/"+file + " is Point" pointPath = pointList.append(dir+"/"+file) # Hard-code the output merged shapefile names pointshapefile = "Mergedpoint.shp" # Given a list of shapefiles, separate each by a ";" # and put quotes around the whole thing def pointshpList(pointPath): return '"%s"' % ';'.join(pointList) # Set the variable to the newly formatted list of shapefiles pointmergedlist = pointshpList(pointPath) # Points try: print "\nMerging " + pointmergedlist + " to get " + pointshapefile + "...\n" gp.merge_management(pointmergedlist, pointshapefile) print gp.getMessages() except: print gp.getMessages() print "\n *** ERROR: Shapefiles (Point) failed to merge *** \n" print "\nDone."
... View more
12-16-2010
02:46 AM
|
0
|
0
|
463
|
Title | Kudos | Posted |
---|---|---|
1 | 07-02-2014 09:37 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|