|
POST
|
It's because arcpy is wrapping single quotes around the file path. print repr(Layer) >>> u"'C:\\WorkSpace\\test workspace\\test.shp'" This works: import arcpy, os #Read input parameters from script tool LayersList = arcpy.GetParameterAsText(0).split(";") # Process: Add Field for Layer in LayersList: arcpy.AddMessage(repr(Layer)) arcpy.AddField_management(Layer.strip("'"), "DUP", "DOUBLE", 9, "", "", "Dup", "NULLABLE")
... View more
05-23-2012
04:07 PM
|
0
|
0
|
3431
|
|
POST
|
Optional parameters are passed as a # character so that place counting is preserved. So you could test for the value being == '#' to see if it was not set. That's what I thought and what I remember from ArcGIS 9x, but it seems to be empty strings now not '#'. Actually, I just tested this and it's an empy string '' when using GetParameterAsText(n) and '#' when using sys.argv For a script tool with 3 parameters, 2 optional (and not entered when I ran it). import sys,arcpy
for i,arg in enumerate(sys.argv[1:]):
arcpy.AddMessage("argv %s=%s"%(i,repr(arg)))
arcpy.AddMessage("param %s=%s"%(i,repr(arcpy.GetParameterAsText(i))))
Executing: Script Layer1 # #
Start Time: Mon May 14 12:33:51 2012
Running script Script...
argv 0='Layer1'
param 0=u'Layer1'
argv 1='#'
param 1=''
argv 2='#'
param 2=''
Completed script Script...
Succeeded at Mon May 14 12:33:52 2012 (Elapsed Time: 1.00 seconds)
... View more
05-13-2012
06:37 PM
|
0
|
0
|
668
|
|
POST
|
If you want to write geoprocessing scripts in Ruby, try the old GPDispatch syntax (note, I have no Ruby experience, I just googled this...): require 'win32ole'
gp = WIN32OLE.new('esriGeoprocessing.GpDispatch.1')
... View more
05-12-2012
03:50 PM
|
0
|
0
|
1039
|
|
POST
|
You are missing an operator before "1.5494739" 1/(1 + Power(2.71828, (-1 * (("slope" * 0.0531159)+ ("solar" * -0.0012492) missing operator, i.e. +-/* 1.5494739))))
... View more
05-12-2012
02:10 AM
|
0
|
0
|
487
|
|
POST
|
The Exists method checks for the existence of data elements, i.e. "feature classes, tables, datasets, shapefiles, workspaces, layers, and files". A domain is a rule, not a data element. Regardless, you already know that the domains are in the database as you have a list of them, i.e. domains = desc.domains, there's no need to double check. If you want to check that there are any domains at all, test for an empty list, perhaps something like: if desc.domains:
print 'There be domains ahead...'
else:
print 'No domains here!'
... View more
05-09-2012
01:27 PM
|
0
|
0
|
2162
|
|
POST
|
When run as a script tool, arcpy passes empty optional arguments as empty strings (i.e. ''). Test this with: litName = arcpy.GetParameterAsText(2) #Optional The three letter code for records in a field. In the script tool this parameter is a String
pCount = arcpy.GetArgumentCount()
if pCount == 2 or not litName:
do things
else:
do other things PS: please use CODE tags when posting code - http://forums.arcgis.com/threads/48475-Please-read-How-to-post-Python-code
... View more
05-02-2012
07:53 PM
|
0
|
0
|
668
|
|
POST
|
The zipfile module is pure python. Get a copy of zipfile.py from python 2.6, rename it and distribute it with your own scripts. E.g. (assuming it is saved as zipfile26.py in the same directory as your code): import zipfile26 z = r"C:\zipfile.zip" zf = zipfile26.ZipFile(z, 'r') zf.extractall(etc...) You could also try subclassing ZipFile (2.5) and adding the extract, extractall and _extract_member methods copied from the 2.6 ZipFile class. Completely untested but something like the following *might* work... import zipfile,os,shutil class ZipFile26(zipfile.ZipFile): def extract(self, member, path=None, pwd=None): """Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using `path'. """ if not isinstance(member, zipfile.ZipInfo): member = self.getinfo(member) if path is None: path = os.getcwd() return self._extract_member(member, path, pwd) def extractall(self, path=None, members=None, pwd=None): """Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist(). """ if members is None: members = self.namelist() for zipinfo in members: self.extract(zipinfo, path, pwd) def _extract_member(self, member, targetpath, pwd): """Extract the ZipInfo object 'member' to a physical file on the path targetpath. """ # build the destination pathname, replacing # forward slashes to platform specific separators. # Strip trailing path separator, unless it represents the root. if (targetpath[-1:] in (os.path.sep, os.path.altsep) and len(os.path.splitdrive(targetpath)[1]) > 1): targetpath = targetpath[:-1] # don't include leading "/" from file name if present if member.filename[0] == '/': targetpath = os.path.join(targetpath, member.filename[1:]) else: targetpath = os.path.join(targetpath, member.filename) targetpath = os.path.normpath(targetpath) # Create all upper directories if necessary. upperdirs = os.path.dirname(targetpath) if upperdirs and not os.path.exists(upperdirs): os.makedirs(upperdirs) if member.filename[-1] == '/': if not os.path.isdir(targetpath): os.mkdir(targetpath) return targetpath source = self.open(member, pwd=pwd) target = file(targetpath, "wb") shutil.copyfileobj(source, target) source.close() target.close() return targetpath
... View more
04-20-2012
06:36 PM
|
0
|
0
|
910
|
|
POST
|
No, raw strings only apply to string literals not string variables. You just need to quote your expression as you would entering it manually in the field calculator: arcpy.CalculateField_management(fc, fld, '"'+case_number+'"') #Or arcpy.CalculateField_management(fc, fld, '"%s"' % case_number)
... View more
04-05-2012
12:27 PM
|
0
|
0
|
3235
|
|
POST
|
So there's no place to get a full listing of arcpy functions, classes, and modules? Yes, see the ArcGIS 10 help. Particularly the ArcPy site package, but see also Geoprocessing with Python, Geoprocessing environment settings and the Geoprocessing tool reference.
... View more
03-28-2012
10:01 PM
|
0
|
0
|
1072
|
|
POST
|
Do you actually need "mean" aspect? Another option is to generate a trend surface and calculate aspect from that to get the overall aspect of a polygon - eg: [ATTACH=CONFIG]12944[/ATTACH] To do this... Clip and mask your DEM to the polygon Convert the masked DEM to points, or... Create Random Points constrained by your landslide polygon which you can use to sample the elevation values. Then Generate the elevation trend surface from those points and then calculate aspect (and slope if required) from that.
... View more
03-22-2012
05:19 PM
|
0
|
0
|
6986
|
|
POST
|
First things first... read thisthread and put code tags around your script. Like so: cur = arcpy.UpdateCursor(FC)
for row in cur:
try:
fieldVal = row.getValue(fieldOne)
if fieldVal = xxxxxxx:
value =
row.setValue(newField, value) A few issues: a try: statement must have an except: clause equality tests use "==" not "=" "value =" needs a value or it will cause a syntax error, i.e. value = "something" E.g. cur = arcpy.UpdateCursor(FC)
for row in cur:
try:
fieldVal = row.getValue(fieldOne)
if fieldVal == xxxxxxx:
value = row.setValue(newField, value)
except Exception as err:
Do something useful here or don't use try except at all For any more assistance you need to give us more info - are you calculating for each of the 2 tables separately, are they joined, do you have to get the value for "newField" from another field in the table/s, etc...?
... View more
03-21-2012
10:15 PM
|
0
|
0
|
532
|
|
POST
|
Instead of deleting your question, why not post it again in this thread and also post the answer you found in case someone else has the same problem?
... View more
03-21-2012
10:02 PM
|
0
|
0
|
264
|
|
POST
|
Both raw and radiance (output as integer with scale factor of 1000, standard ENVI WV2 radiance calculation). Here's one done with integer radiance values, top is glint affected, bottom is same region following deglinting: [ATTACH=CONFIG]12916[/ATTACH]
... View more
03-21-2012
03:26 PM
|
0
|
0
|
2030
|
|
POST
|
Yes you can build script tools with GDAL just like other python packages. Make sure you install the appropriate GDAL bindings for the version of python you use with ArcGIS. Also, don't run the scripts 'in process', see the GDAL Python "Gotchas" wiki page.
... View more
03-11-2012
09:27 PM
|
0
|
3
|
6879
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-30-2025 03:00 PM | |
| 1 | 06-10-2025 08:06 PM | |
| 5 | 05-20-2025 07:56 PM | |
| 1 | 05-04-2025 10:34 PM | |
| 5 | 04-22-2025 09:04 PM |