|
POST
|
I find checking 'Run with highest privileges' needs to be checked on Windows 7 for scheduled tasks.
... View more
10-05-2012
03:18 AM
|
0
|
0
|
3917
|
|
POST
|
Change the wb_file parameter to use the arcpy.env.scratchFolder instead of hard coding the directory. GP tools when fired off from server create a temp directory for each job, and you want to do your work there. Then you would use arcpy.SetParameterAsText or arcpy.SetParameter() to return the results back to the end user.
# change
wb_file = r'C:\arcgisserver\directories\arcgisoutput\_ags_' + str(uuid.uuid4()) + '_' + parameters[0].value + '.xlsx'
# to
wb_file = env.scratchFolder + os.sep + "myfilename.xlsx"
Hope this helps.
... View more
10-05-2012
02:08 AM
|
0
|
0
|
1227
|
|
POST
|
For your text file, you can try using a with statement:
with open(r"P:\GIS\Python_test\Data_inventory\shapefiles_test.txt", 'w') as f:
#do stuff
This will ensure it closes properly. You can also try using try/except statements in your code and return the exact location where everything is failing.
import sys
import traceback
import inspect
def trace():
'''
trace finds the line, the filename and error message and returns it
to the user
'''
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# script name + line number
line = tbinfo.split(", ")[1]
filename = inspect.getfile( inspect.currentframe() )
# Get Python syntax error
#
synerror = traceback.format_exc().splitlines()[-1]
return line, filename, synerror
This function should be called in the except part of your code.
try:
# use your code
except:
print trace() # or write to log file
This should help you catch your bug/error.
... View more
09-24-2012
10:14 AM
|
0
|
0
|
604
|
|
POST
|
Try using AddTableView() http://resources.arcgis.com/en/help/main/10.1/index.html#/AddTableView/00s30000006m000000/
... View more
09-20-2012
05:03 AM
|
0
|
0
|
503
|
|
POST
|
You could use the ArcSDESQLExecute command to check your connection: http://resources.arcgis.com/en/help/main/10.1/index.html#//018z0000007z000000
... View more
09-17-2012
07:55 AM
|
0
|
0
|
603
|
|
POST
|
You need an python installed and an editor. There are many free IDEs like pythonwin or eclipse with pydev. There are also pay ones as well like WING. Hope this helps
... View more
07-27-2012
06:15 AM
|
0
|
0
|
1316
|
|
POST
|
It looks like your issue is that the csv file is open, and the arcpy function cannot work on the open/locked file. Try this:
# Import system modules
import arcpy
from arcpy import env
import os
try:
directory = "C:/temp/cert"
os.chdir(directory)
env.workspace = directory
gdb = "template.gdb"
extension = ".csv"
# get a listing of all CSV files
for myfile in os.listdir("."):
if myfile.endswith(extension):
#read in the domain values from the file
f = open(myfile, 'r')
header = f.readline().split(",")
code = header[0]
desc = header[1].rstrip().lstrip()
f.close()
del f
#Set local parameters
domTable = os.path.abspath(myfile)
codeField = code
descField = desc
dWorkspace = gdb
domName = myfile.split(extension)[0] #the domain takes on the name of the file, minus the ".csv" section
domDesc = desc.replace("_"," ")
print domTable, codeField, descField, dWorkspace, domName, domDesc
print os.path.exists(domTable)
arcpy.TableToDomain_management(domTable, codeField, descField, dWorkspace, domName, domDesc,"REPLACE")
#f.close()
except Exception, e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "Line %i" % tb.tb_lineno
print e.message
... View more
07-23-2012
06:00 AM
|
0
|
0
|
826
|
|
POST
|
How are you running the code? What IDE are you using? PythonWin for example will not clear out items from memory when you run the code. In addition, you can delete objects you are no longer using, for example: del ListDatabase, ListDatasets at the end of your code. You might want to consider putting calling your code from a toolbox script, so a new python instance spins up every time you run the script. Other factors include: - hard drive speed - network speed - RAM in machine - CPU speed - Size of feature classes copied Nothing really jumps out at me besides not managing your objects. How does this function compare to arcpy.CopyFeatures()? Hope this helps.
... View more
07-18-2012
05:17 AM
|
0
|
0
|
1734
|
|
POST
|
You can use this script: http://code.google.com/p/opcon/source/browse/trunk/lib/CoordConverter.py to get the coordinates into MGRS or USNG coordinates (they are the same thing). Sample use:
>>> import CoordConvertor
>>> ct = CoordConvertor.CoordTranslator()
>>> print ct.AsMGRS([36.279707,-77.266846],4,False)
18S TF 96401735
Couple this module with the arcpy.UpdateCursor() you can then insert each value into your column. You can also try to follow the instruction found here: http://blogs.esri.com/esri/arcgis/2011/01/05/converting-and-displaying-coordinates-in-arcgis-10/ Hope this helps.
... View more
05-17-2012
08:27 AM
|
1
|
0
|
1427
|
|
POST
|
You can use the mapping module to write a query definition to the layer. Example:
from arcpy import mapping
import arcpy
mxd = mapping.MapDocument("CURRENT")
layers = mapping.ListLayers(mxd)
for layer in layers:
layer.definitionQuery = "<FIELD> = '" + sql + "'"
del layer
mxd.save()
del layers
del mxd
Hope this helps.
... View more
04-16-2012
03:55 AM
|
0
|
0
|
929
|
|
POST
|
You can't save an mxd inside a file geodatabase, you need to save it in a folder. To get the path of your workspace, try this:
import os
#... code
workPath = os.path.dirname(env.workspace)
print workPath
# do stuff
del workPath
I didn't include it in the code I posted originally (my script is pretty long), but I already have env.workspace defined as a gdb file path (actually it's not hardcoded, I'm using arcpy.GetParameterAsText since I am also creating a script tool). env.workspace = r"C:\fp2.gdb" so that I don't have to define like 5 more variables when I need to call them further down in my script and can just use "": ex. arcpy.AddField_management ("dec209data", "dec2009dataLayer") The problem is that you cannot save an .mxd into a gdb so the location of my mxd is not within the env.workspace (it's in the same folder as the .gdb though - C:\fp2copy). So I believe this is why it will not overwrite the mxd and I have to define another variable for an mxd if I want to be able to save the 4 layers that I am adding to it using arcpy.mapping module (as in my previous post using mxd1). Correct me if I am wrong, but the only way I would be able to overwrite my mxd is to change the env.workspace to the folder I am processing everything to/from (C:\fp2copy) and then define variables for all of the datasets currently being saved within the gdb (see attached) or will one of the other methods you suggested work (os module etc.)? I'm trying to create the least amount of variables as possible for efficiency. Thanks so much for your assistance!!
... View more
04-11-2012
10:39 AM
|
0
|
0
|
5275
|
|
POST
|
Sure you can overwrite a map document. I'd set the environmental overwrite output parameter to true. If you are currently accessing the map document, I'd use save(). That will save any changes in the current map document. If you want to export changes to say an existing file, you can use either standard python like the shutil or os module to copy and remove files, or you can use the arcpy Delete() and Copy() in the data management toolbox. You can also try just using the SaveAs() function on the MapDocument object with the overwrite output parameter set to true.
... View more
04-11-2012
02:12 AM
|
0
|
0
|
5275
|
|
POST
|
Do you know where it's crashing? Are you sure it's related to arcpy/a bad map document? Can you post a sample of your code and a good and bad map document?
... View more
04-11-2012
02:07 AM
|
0
|
0
|
3041
|
|
POST
|
Have you tried putting a try/except in your code to catch the map documents that are causing you issues?
.... in loop
[INDENT]try:
mxd = mapping.MapDocument(mxdPath)
#.... do something
except:
#write to file which map documents are incorrect[/INDENT]
The try/except pattern should allow you to ignore the errors and output the failing paths to a text file or something else. You can then take that file and run the mxd doctor on them.
... View more
04-10-2012
03:58 AM
|
0
|
0
|
3041
|
|
POST
|
For your first variable, if you input is a string, then yes you could do it that way. There is also an input called ArcMap Document that you might want to look at. For the 2nd parameter, assuming it's of type string, then yes that's how it would work. I would also perform some checks to ensure that the input is a valid format of .mxd, and that the file you are going to write to does not exist.
... View more
04-10-2012
02:21 AM
|
0
|
0
|
5275
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-24-2017 05:56 AM | |
| 1 | 03-28-2018 03:28 AM | |
| 1 | 07-24-2017 05:39 AM | |
| 1 | 06-01-2016 03:48 AM | |
| 1 | 01-27-2016 02:53 AM |
| Online Status |
Offline
|
| Date Last Visited |
3 weeks ago
|