|
POST
|
this is still an issue for us, it's as if ArcGIS does not recognize the dxf files in the directory to iterate as cad datasets has anyone else experienced this? Looks like the iterator is not finding any files, correct? Are the CAD datasets recognized in the catalog window? I'd also look at pathnames that start with a number or have spaces, these can sometimes have problems.
... View more
02-17-2012
08:31 AM
|
0
|
0
|
3164
|
|
POST
|
if arcpy.Exists(existing_xml):
# do the conversion
arcpy.ESRITranslator_conversion (existing_xml, translator, r'\\export\outputfile.xml') # this fails if the MD is pre ArcGIS10 The Python Way is to save yourself trouble by taking the approach of instead of asking for permission, asking for forgiveness later. It sounds messy, but the approach has an elegance that (I think) is really remarkable. For example (note, totally untested code):
import os
import arcpy
from arcpy import conversion as CV
# get translator path
InstallDir = arcpy.GetInstallInfo("Desktop")["InstallDir"]
translator = os.path.join(InstallDir,r"\Metadata\Translator",
"ESRI_ISO2ISO19139.xml")
# input and output
docThing = r"C:\work\myfile.gdb\featureclass"
outXML = os.path.join(r"\\export",os.path.basename(docThing)) + ".xml"
try:
CV.ESRITranslator(docThing, translator, outXML)
except:
# export failed
try:
# perhaps this metadata just needs upgrade?
print "upgrading %s to 10..." % docThing
CV.UpgradeMetadata(docThing,"ESRIISO_TO_ARCGIS")
finally:
# in any case, if upgrade fails or not, create or update
# metadata off the dataset properties
CV.SynchronizeMetadata(docThing,"ALWAYS")
try:
# one more time try to export
CV.ESRITranslator(docThing, translator, outXML)
except:
print "Metadata export failed for " + docThing
... View more
02-16-2012
07:06 AM
|
1
|
0
|
2689
|
|
POST
|
There's a nice python string method that trims whitespace around strings: >>> x
'\r\nhere is my real text\n'
>>> x.strip()
'here is my real text' So one approach you could use would be: arcpy.CalculateField_management(mytable,"FIELDNAME","!FIELDNAME!.strip()","PYTHON") One could also use VBScript: arcpy.CalculateField_management(mytable,"FIELDNAME","Trim([FIELDNAME]")
... View more
02-16-2012
06:18 AM
|
0
|
0
|
5671
|
|
POST
|
ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute). even if I just cut-and-paste your code. Well, you didn't want me to test it did you? Put a "print where" in the code right before you do the selection and maybe that will help you figure out what's up. To show all non-printables etc you can try: print repr(where). You didn't show us any data. If GageCode is an integer, then your query expression should be: where = "GageCode = %s" % int(row[0])
... View more
02-09-2012
01:18 PM
|
0
|
0
|
3281
|
|
POST
|
Thanks for turning me on to the csv module. Cool!
import csv, arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
env.workspace = 'E:/Weathering_GIS/Working.gdb'
try:
f = open('E:/Weathering_GIS/Sheds.csv')
sheds = csv.reader(f)
for row in sheds:
print row # this is a python list - you want the first element ([0])
arcpy.MakeFeatureLayer_management(arcpy.workspace, 'Shedpoints9')
# my solution is to construct the where clause here. Note the escaped single quotes.
where = "GageCode = \'%s\'" % row[0]
arcpy.SelectLayerByAttribute_management("Shedpoints9","",where)
except:
del sheds
f.close()
raise
... View more
02-09-2012
12:56 PM
|
0
|
0
|
3281
|
|
POST
|
Eventually, this will be incorporated into a script that uses os.walk to go through a directory tree. Any help would be appreciated. I know you're obviously using 9.3, but I want to add to the thread that you can do "os.walk" type things with a model easily with ModelBuilder 10.0 iterator tools. It's one of the things that make 10.0 worth the hassles. But even in 9.3, if you have a working model, you can call the model it from a python script -- no need to export/edit in Python: ... os.walk code ...
gp.AddToolbox(r"x:\path\to\my\toolbox.tbx")
gp.MyModelTool_mytools(arg1,arg2)
... View more
02-07-2012
01:24 PM
|
0
|
0
|
2170
|
|
POST
|
I think your code just needs a little debugging lines_shp = sys.argv[1] # or: gp.getParameterAsText(0) (yes, 0)
linesCopy_cov = sys.argv[2] # or: gp.getParameterAsText(1)
##lines_shp = "C:\\test\\lines.shp"
# Local variables...
# Process: Feature Class To Coverage...
gp.FeatureclassToCoverage_conversion(lines_shp + " ARC", linesCopy_cov, "", "DOUBLE")
GetParameterAsText() works better with more complex variables like coordinate systems, so I now use it instead of sys.argv. Except for sys.argv[0] which convenienely contains the path of the script (say, to help you find paths to associated scripts or tools).
... View more
02-07-2012
10:38 AM
|
0
|
0
|
2170
|
|
POST
|
I am using an insert cursor to create many (>5,000) new rows in a feature class. It is taking a very long time to run. In VBA, there was a "rowbuffer" object that was more efficient than inserting single row objects -- is there something similar in Python? You may want to try buffering using the in_memory workspace: create a feature class in the in_memory workspace, insert rows to it using a cursor, then copy them out to disk, use delete rows tool to clear it, repeat. At the end of your process append your pieces together. You could still use your VBA method if you used a .NET addin instead of Python (none of that for me, thanks). Esri is addressing this shortcoming of arcpy (slow cursors) with the new arcpy.da method in Arc 10.1. I haven't tried it yet but have been told it will be dramatically faster.
... View more
02-07-2012
10:26 AM
|
0
|
0
|
1460
|
|
POST
|
What am I doing wrong? I'm completely stumped! I tried your script and got the same results, though for another, similar type (Feature Layer) your logic worked perfectly. My guess is this is not supported for feature set parameters because of their special ability to interact with the hosting application.
... View more
02-06-2012
12:37 PM
|
0
|
0
|
1249
|
|
POST
|
Unfortunately, my frustration with these changes stems from the the .save function. In my script when I hit that particular line it blows up PyWin and my error traps fail to document why. Just a thought: Is arcpy scratch and current workspace set to a folder with a "safe" path name? (no spaces or "-" characters etc in the pathname)? Raster tools often don't play well with pathnames like that. (Fun, since in Windows XP the default TEMP - often what you get if you don't define the workspace explicitly.)
... View more
02-06-2012
08:10 AM
|
0
|
0
|
1178
|
|
POST
|
There is probably a better way to do this sort of string/variable substitution thing, but... r1 = r"C:\temp1\test1"
r2 = r"C:\temp39\test14"
r3 = r"C:\temp56\test177"
r4 = r"C:\temp563\test765"
eq = "{0} + {1} + {2} + {3}"
eq1 = eq.format(r1,r2,r3,r4)
print eq1
The code snippet above, if pasted in a python window, prints this: C:\temp1\test1 + C:\temp39\test14 + C:\temp56\test177 + C:\temp563\test765 If those input paths are all the same, (that is, your "Data" workspace"), it seems to me setting the gp.workspace to that path would be less messy, then just specify an output path to write the results: import os
SOMAoutput = os.path.join(outWorkspace, "a" + speciesCode + "_br")
#example output name is a069swgo_br
One more thing - although ModelBuilder exports all those AddToolbox calls, if they are standard ArcToolbox tools they are unnecessary -- the gp knows where to find them.
... View more
02-01-2012
02:33 PM
|
0
|
0
|
3485
|
|
POST
|
I was just curious if there is a way to get python scripts run out of Arctoolbox to skip the parameter input window for scripts which don't need input parameters. I have several scripts that run updates based on known layers, so they don't need any inputs or outputs. Any ideas? (besides going through VB/other programming language) You don't need to supply parameters for the script to run. The .py file should run fine just from a system command prompt if there are no parameters or environments the script requires to run correctly. .py and .pyc files are set up to run in Windows, so you can just crank them up using a command window, windows explorer (double-click) or Task Scheduler.
... View more
02-01-2012
02:16 PM
|
0
|
0
|
2252
|
|
POST
|
However, it will not loop anymore Your loop is incorrect. You don't need a counter or while loop. FIPSlist = ('001', '003', '005') for fip in FIPSlist: query = "FIPS_PARIS ='" + fip + "'" arcpy.TableSelect_analysis("Master_TAHI", FIPS + r"\FIPS" + fip + ".dbf",query)
... View more
02-01-2012
08:20 AM
|
0
|
0
|
4645
|
|
POST
|
Still having problems with the where clause. The select features will not go through the list loop. It only wants to find the list name since it is in quotes. I just can't figure this out. You've got a syntax error. I highly recommend using a syntax checker. Corrected (using escapes for the single quotes -- just for clarity) arcpy.TableSelect_analysis(inputTable, outputWorkspace +\
"\\fips_" + str(fip) + ".dbf", \
"FIPS_PARIS = " + "\'" + fip + "\'")
Using string formatting and the os.path module to construct paths is a lot easier to code and debug:
query = "FIPS_PARIS = \'%s\'" % fip
outTable = os.path.join(outputWorkspace,"fips_%s.dbf" % fip)
arcpy.TableSelect_analysis(inputTable,outTable,query)
And there is a new string format() method (introduced in Python 2.4) that will eventually replace it:
query = "FIPS_PARIS = \'{0}\'".format(fip)
outTable = os.path.join(outputWorkspace,"fips_{0}.dbf".format(fip)
arcpy.TableSelect_analysis(inputTable,outTable, query)
... View more
02-01-2012
06:58 AM
|
0
|
0
|
1990
|
|
POST
|
PYTHONPATH is a Windows (or UNIX) environment variable that needs to be set before the script is run, if you need it. The purpose of that variable is to modify sys.path when Python launches. Sys.path is a list of folders that tells Python where to look for imports, ie "import mymodule" will look for a file "mymodule.py" or "mymodule.pyc" through the sys.path, and use the first one it finds. It looks like you are trying to invoke the ntpath module. This module is already in the sys.path, so you could get to it with: import ntpath However, you don't need to import it -- the os module is what you want (and what you are using). I'm pretty sure os calls ntpath for you on windows, something else on Mac or Unix. If you need to alter where to look at runtime, you can alter the sys.path as follows. import sys
sys.path.append(r"C:\mytools\python\modules") You can check out where imports will look by listing your sys.path:
>>> import sys
>>> sys.path Note, by default, "" is the first item in sys.path. So if you include a custom module in the same folder as the script, it will always use that version. http://docs.python.org/tutorial/modules.html
... View more
01-31-2012
10:21 AM
|
0
|
0
|
2285
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-11-2021 01:26 PM | |
| 5 | 12-10-2021 04:58 PM | |
| 1 | 02-27-2017 09:30 AM | |
| 2 | 12-04-2023 01:05 PM | |
| 1 | 04-12-2016 10:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-19-2024
12:10 AM
|