|
POST
|
Looking for examples of using the "ORDER_BY" SQL syntax that is now suported in the arcpy.da cursor model... Help system is lacking in examples on this front... Can any v10.1 pro rewrite this in arcpy.da format? arcpy.UpdateCursor(oesfHydroDislvFC, "", "", "", "SL_WTRTY_CD A;RIP_COMBO_UID D")
... View more
08-13-2012
01:03 PM
|
0
|
9
|
6413
|
|
POST
|
You certainly can run multiple scripts/processes at once. Here's a link to an example using the subprocess moodule: http://forums.arcgis.com/threads/33602-Arcpy-Multiprocessor-issues?p=177418&viewfull=1#post177418
... View more
08-13-2012
12:39 PM
|
0
|
0
|
1611
|
|
POST
|
Thanks Jason... In the docs I saw the part about the with statement "guarantee close and release of database locks and reset iteration", and thought that sounded good, but as long as the cursor executes successfully I guess that does that anyway.
... View more
08-13-2012
08:07 AM
|
0
|
0
|
6438
|
|
POST
|
Excited to get my hands dirty using the arcpy.da module, and I appreciate the reasoning for the optional "with" statement syntax. Question: While it is possible to do this: tileList = [r[0] for r in arcpy.da.SearchCursor(freq1Tbl, "TILE_NO")] it doesn't seem possible to do this: tileList = [row[0] for row in cursor with arcpy.da.SearchCursor(freq1Tbl, "TILE_NO") as cursor] Am I using the wrong syntax here, or can you just not use the with statement in a list/dictionary comprehension?
... View more
08-10-2012
10:29 AM
|
0
|
2
|
7373
|
|
POST
|
Many (most/all?) of the scripting users were accustomed to using the file-based .prj definitions. Some issues I see: 1. The SR properties .name, .PCSName and/or .GCSName do not necessarily match the allowable spatial reference token keywords�?� For example the factory code of 2927 (the projection for all WA State Govt. agencies) has a .name and .PCSName property of 'NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet', however the spatial reference token keyword is actually 'NAD 1983 HARN StatePlane Washington South FIPS 4602 (US Feet)'. So the effect of this issue is that this works: arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('NAD 1983 HARN StatePlane Washington South FIPS 4602 (US Feet)') and this DOES NOT work: arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet') Perhaps my projection (WA SPS NAD83HARN USFEET) is the exception here, but it would be nice to have a SR property that would yield the correct sr token keyword. 2. The Help system topics (Project tool, Project Raster tool, arcpy.env.outputCoordinateSystem, etc) do not adequately describe the disappearance of the file-based .prj files and it's impact on script-based use of the geoprocessing tools, nor does it describe the proper syntax of the factory codes (or how to search for them in projected coordinate systems .pdf reference doc), fails to mention the arcpy.ListSpatialReferences() method, and fails to mention a way to retrieve the proper sr token keywords. Also, script examples for the arcpy.env.outputCoordinateSystem method have the wrong syntax for using the spatial reference token keywords (Help provided example of arcpy.env.outputCoordinateSystem = "Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 18N.prj" results in an error. 3. There are no file-based .prj files anymore. This threw me for a big loop! I suppose you can make some with the .exportToString() method, but that's kinda a pain... Seems like some of the legacy tools such as Project Coverage required .prj files... Not sure why the help system mentions .prj files anymore if there aren't any to speak of! I liked the .prj file folders because they were easy to search... Other than the directory tree in the the coordinate system parameter GUI in the projection-related toolbox tools, I don't really see an easy way to browse and retrieve the factory codes or SR token keywords (which you now need to reference when specifying coordinate systems in a script). Getting rid of the file-based .prj definitions is a pretty big change... Like everything else though I'm sure we'll all get used to it.
... View more
08-10-2012
09:12 AM
|
0
|
0
|
2550
|
|
POST
|
Oh see what's different... The "sR.name" property appears to be slightly different than the "official" syntax compliant name that uis given by the arcpy.ListSpatialReferences() method. Is there any sR property that yields the "syntax compliant" name? sR.name property of 'NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet' vs. compliant name of 'NAD 1983 HARN StatePlane Washington South FIPS 4602 (US Feet)'
... View more
08-09-2012
09:39 AM
|
0
|
0
|
2550
|
|
POST
|
Thanks Jason - That did work... For example: >>> srList = arcpy.ListSpatialReferences("*washington*south*", "PCS")
>>> for sr in srList:
... print sr
Projected Coordinate Systems/State Plane/NAD 1927 (US Feet)/NAD 1927 StatePlane Washington South FIPS 4602
Projected Coordinate Systems/State Plane/NAD 1983 (CORS96) (Meters)/NAD 1983 (CORS96) StatePlane Washington South FIPS 4602 (Meters)
Projected Coordinate Systems/State Plane/NAD 1983 (CORS96) (US Feet)/NAD 1983 (CORS96) StatePlane Washington South FIPS 4602 (US Feet)
Projected Coordinate Systems/State Plane/NAD 1983 (Meters)/NAD 1983 StatePlane Washington South FIPS 4602 (Meters)
Projected Coordinate Systems/State Plane/NAD 1983 (US Feet)/NAD 1983 StatePlane Washington South FIPS 4602 (US Feet)
Projected Coordinate Systems/State Plane/NAD 1983 HARN (Meters)/NAD 1983 HARN StatePlane Washington South FIPS 4602 (Meters)
Projected Coordinate Systems/State Plane/NAD 1983 HARN (US Feet)/NAD 1983 HARN StatePlane Washington South FIPS 4602 (US Feet)
Projected Coordinate Systems/State Plane/NAD 1983 NSRS2007 (Meters)/NAD 1983 NSRS2007 StatePlane Washington South FIPS 4602 (Meters)
Projected Coordinate Systems/State Plane/NAD 1983 NSRS2007 (US Feet)/NAD 1983 NSRS2007 StatePlane Washington South FIPS 4602 (US Feet)
>>> arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(srList[6])
>>> This also works (not sure what I was doing wrong before): arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('NAD 1983 HARN StatePlane Washington South FIPS 4602 (US Feet)')
... View more
08-09-2012
09:30 AM
|
0
|
0
|
2550
|
|
POST
|
Ya - i guess that's how it would work via scripting. Sure is a pain to find the "codes" since the .pdf is not well structured like the Coordinate Systems directory tree. Only way I could find the right code was by using v10.0, getting the sr object, and spitting out the "factory code" such as: >>> arcpy.env.outputCoordinateSystem = r"C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1983 HARN (US Feet)\NAD 1983 HARN StatePlane Washington South FIPS 4602 (US Feet).prj"
>>> arcpy.env.outputCoordinateSystem.factoryCode
2927 So, my new syntax in v10.1 is this: arcpy.env.outputCoordinateSystem = 2927 #WA_SPS_NAD83HARN_USFEET Note that (contrary to the Help topic) this syntax DOES NOT appear to work for me: >>> arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('NAD_1983_HARN_StatePlane_Washington_South_FIPS_4602_Feet')Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 505, in set_
self[env] = val
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 557, in __setitem__
ret_ = setattr(self._gp, item, value)
RuntimeError: <unprintable RuntimeError object> Note sure why the .prj files went away... Dawning of a new age of fully integrated seamless geospatial technology I guess... Sigh... COMPLAINT TO ESRI:The v10.1 Help topics that cover to projection-related stuff via Python scripting could use some further explanation about the new code/name based syntax. Script example syntax relating to using spatial reference names to set the SR appears to be incorrect.
... View more
08-09-2012
08:34 AM
|
0
|
0
|
2550
|
|
POST
|
Thanks Kim... http://forums.arcgis.com/threads/43644-UTM-Conversion-in-Python?p=222580&viewfull=1#post222580 Good ole' .prj... you will be missed!
... View more
08-08-2012
04:48 PM
|
0
|
0
|
2550
|
|
POST
|
In v10.0 and before there was always a folder that contained all the ESRI .prj definition files... Usually something like C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems. Maybe I messed up my install somehow, but now in v10.1 it seems that 'Coordinate Systems' folder is no longer there, and to boot, there are no .prj files at all in the ArcGIS Program Files directory... at all! I always used the .prj files to set the arcpy.env.outputCoordinateSystem variable (and all its various past incarnations). What gives? How can we now access the official ESRI projection definitions in a script if there are no .prj definition file anymore? The help says you can use .prj files, and the provided example in the arcpy.env.outputCoordinateSystem help topic yields: arcpy.env.outputCoordinateSystem = "Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/Northern Hemisphere/WGS 1984 UTM Zone 18N.prj"
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 515, in set_
self[env] = val
File "C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 567, in __setitem__
ret_ = setattr(self._gp, item, value)
RuntimeError: Object: Error in accessing environment <outputCoordinateSystem> Am I totally missing something?
... View more
08-08-2012
04:39 PM
|
0
|
13
|
7287
|
|
POST
|
Never had much consistent luck with using .xls files as an "ESRI-friendly" format... In my experience, it's best to use .dbf, .txt, .csv, etc. if you can. However, in v10.1 it seems to work for me (the .xls file is considered a workspace): >>> import arcpy >>> arcpy.env.workspace = r"C:\Temp\logist_reg_merge_20120725_runs.xls" >>> tblList = arcpy.ListTables() >>> print tblList [u'PivotReport$', u'RawData$', u'Sheet1$', u'Sheet2$']
... View more
08-02-2012
08:46 AM
|
0
|
0
|
1712
|
|
POST
|
Okay one last stab... Note the #comments... import arcpy
arcpy.SetProduct("ArcInfo") #or whatever lic level you are using
myFC = arcpy.GetParameterAsText(0) #IMPORTANT: In the toolbox GUI, this parameter should be a type of 'FeatureLayer'
var1 = arcpy.GetParameterAsText(1) #Toolbox type of 'String'
var2 = arcpy.GetParameterAsText(2) #Toolbox type of 'String'
arcpy.AddField_management(myFC, "FIELD1", "TEXT", "", "", "50")
arcpy.AddField_management(myFC, "FIELD2", "TEXT", "", "", "50")
updateRows = arcpy.UpdateCursor(myFC)
for updateRow in updateRows:
updateRow.FIELD1 = var1
updateRow.FIELD2 = var2
updateRows.updateRow(updateRow)
del updateRow, updateRows
... View more
08-01-2012
08:19 AM
|
0
|
0
|
585
|
|
POST
|
Yes, it'd be good to change the field types to text... How about this: myFC = arcpy.GetParameterAsText(0) var1 = arcpy.GetParameterAsText(1) var2 = arcpy.GetParameterAsText(2) arcpy.AddField_management(myFC, "FIELD1", "TEXT", "", "", "50") arcpy.AddField_management(myFC, "FIELD2", "TEXT", "", "", "50") arcpy.CalculateField_managment(myFC, "FIELD1", "'" + var1 + "'", "PYTHON") arcpy.CalculateField_managment(myFC, "FIELD2", "'" + var2 + "'", "PYTHON") an alternate way using an update cursor: myFC = arcpy.GetParameterAsText(0) var1 = arcpy.GetParameterAsText(1) var2 = arcpy.GetParameterAsText(2) arcpy.AddField_management(myFC, "FIELD1", "TEXT", "", "", "50") arcpy.AddField_management(myFC, "FIELD2", "TEXT", "", "", "50") updateRows = arcpy.UpdateCursor(myFC) for updateRow in updateRows: updateRow.FIELD1 = var1 updateRow.FIELD2 = var2 updateRows.updateRow(updateRow) del updateRow, updateRows If this aint working.... I dunno... Are you sure your toolbox script tool is pointing to the correct script?
... View more
07-31-2012
03:01 PM
|
0
|
0
|
3480
|
|
POST
|
How about: nameList = [r.Name for r in arcpy.SearchCursor(myFC)] Then... i = 0
for name in nameList:
print "Item #" + str(i) + " = " + str(name)
i = i + 1 There is a ".index()" method of a list, but it returns the index of the FIRST occurance of the specified item. For example: test = ["john","sam","john"] >>> test.index("john") 0 You probably want to be more explicit in this case, and include a counter instead of the list index (which makes the assumption that all the names will always be unique).
... View more
07-31-2012
10:11 AM
|
0
|
0
|
2239
|
|
POST
|
Sorry - leave off the int() part in the CalculateField tool. No sense in converting your character string to an integer! I was under the assumption your input values were integers. Not sure why I was thinking that... This should work: myFC = arcpy.GetParameterAsText(0)
var1 = arcpy.GetParameterAsText(1)
var2 = arcpy.GetParameterAsText(2)
arcpy.AddField_management(myFC, "FIELD1", "SHORT")
arcpy.AddField_management(myFC, "FIELD2", "SHORT")
arcpy.CalculateField_managment(myFC, "FIELD1", "'" + var1 + "'", "PYTHON")
arcpy.CalculateField_managment(myFC, "FIELD2", "'" + var2 + "'", "PYTHON")
... View more
07-31-2012
09:45 AM
|
0
|
0
|
3480
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-25-2014 12:57 PM | |
| 1 | 08-29-2024 08:23 AM | |
| 1 | 08-29-2024 08:21 AM | |
| 1 | 02-13-2012 09:06 AM | |
| 2 | 10-05-2010 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
08-30-2024
12:25 AM
|