|
POST
|
I got an indentation error. Please help, advise and respond. You must be fanatically consistent with indents. Do not mix tabs and spaces and make sure your indents are absolutely aligned for each block of code. If you're not using an IDE (IDLE, PythonWin, PyScripter, WingIDE are the big four) I highly recommend it! Here's an example of your function properly indented:
"""Returns true if in path there is only one basename"""
import os
mlist = []
for file in os.listdir(path):
if os.path.basename(file).split(".")[0] not in mlist:
mlist.append(os.path.basename(file).split(".")[0])
if len(mlist)>1:
return True
else:
return False
... View more
08-17-2012
12:07 PM
|
0
|
0
|
4375
|
|
POST
|
You can't make a layer from the layer you already have open with a cursor. A two-step process may work better for you to get the cursor out of the picture. # Make feature layer of all points arcpy.MakeFeatureLayer_management("pyServiceConnection", "servLyr") # Create list of unique object ids rows = arcpy.SearchCursor("servLyr") # Loop over points objIDs = list() for row in rows: objIDs.append(row.OBJECTID) # make list unique objIDs = list(set(objIDs)) # Make and delete feature layer for each point one at a time for objID in objIDs: where = "OBJECTID = {0}".format(objID) arcpy.MakeFeatureLayer_management("servLyr", "lyr1", where) # Delete feature layer arcpy.Delete_management("lyr1")
... View more
08-16-2012
05:40 PM
|
0
|
0
|
778
|
|
POST
|
What exactly does that error message mean? I would guess that the error message means the the list from which you're trying to pull the first element ([0]) is empty. I'd check the arguments to your ListLayers function to make sure they are valid. The way to know for sure is to put this debug statement right before it:
layers = arcpy.mapping.ListLayers(mxd2,"orange",df2)
print len(layers), str(layers)
... View more
08-16-2012
05:27 PM
|
0
|
0
|
1665
|
|
POST
|
I tried inserting the line for using a "d" to prefix the output feature dataset name in my script, the script did run, created some datasets and errored out at one of the dwg files, i am not able to figure out why it is not able to create the annotation for that file and why it is erroring out at that point. Check the value of outDS you're getting with a print statement -- but also make sure your output GDB is entirely empty. arcpy.env.overwriteOutput = True is a good idea too! Perhaps this syntax will work better for you: outDS = arcpy.ValidateTableName("d" + os.path.splitext(os.path.basename(file))[0]) (regarding looping attempt) i guess i am missing something because it is not even creating the GDBs. Yes - Look up the syntax on .format() in the python help. You need to substitute that year into the gdb name using .format: gdbName = "d{0}.gdb".format(year)
arcpy.CreateFileGDB_management("C:/data",gdbName)
... View more
08-15-2012
02:39 PM
|
0
|
0
|
1868
|
|
POST
|
if you need to post more code it would be good to see what the/a value of your INPUT_DIR variable is, and to see the code indented (use the # button to preserve it). Yes! [post=224499]Please read: How to post Python code[/post]
... View more
08-15-2012
02:03 PM
|
0
|
0
|
1539
|
|
POST
|
Ok. As I have personally not done the install for that I cannot say if it was a mistake during the installation or if it was an actual software incompatiblity.... I assume that since Desktop is not yet 64 bit that the Python they have is 32 as well? The help says PythonWin is still shipped with the software, but I can't find it in my distribution. It does work with ArcGIS 10.1. PythonWin can be downloaded here. (Go the most recent build and look for the file "pywin32-xxx.win32-py2.7.exe") sourceforge.net/projects/pywin32/files/pywin32 A future update to Desktop 10.1 is being tested that allows 64 bit background processing on ArcGIS Desktop -- though you will probably continue to do ArcGIS script development using Python-32. In addition to its capable IDE, PythonWin includes windows-specific modules that allow you to easily interact with the Win32API, Office apps, etc. Personally, I'm a big fan of WingIDE. I have found it well worth the $100 for the Pro version.
... View more
08-15-2012
08:30 AM
|
0
|
0
|
1901
|
|
POST
|
but my problem now is that I need to customize the feature datasets such that all the feature datasets will have the same fullname as the CADfiles becos we have a naming convention for all our files for ease of recorgnition. The validation is stripping that leading number because gdb object names should not start with a number. Here's a tweak that will preserve those full names be prefixing a "d" to the output feature dataset name: outDS = arcpy.ValidateTableName(os.path.splitext("d" + os.path.basename(file))[0]) Creating a geodatabase for each folder should be pretty straightforward. Wrap a for loop around what you have:
for year in range(1990,2005): # 1990-2004
inFolder = r"c:\data\cadfiles\{0}_dwg".format(year) # 1990_dwg
gdbName = "d{0}.gdb".format(year) # d1990.gdb
arcpy.env.workspace = gdb
...
... View more
08-15-2012
08:16 AM
|
0
|
0
|
6678
|
|
POST
|
Here's the help reference for paths that goes into detail why and some other good tips about paths: Arc 10.0 help: Paths explained: Absolute, relative, UNC, and URL
... View more
08-14-2012
08:21 PM
|
0
|
0
|
1539
|
|
POST
|
Hi Everyone, I am looking for a python or php script that will accept the Range and Meridian values of a location and use it to identify the UTM zone. I'm not familiar with what you mean by "range" unless you mean the range of a single zone, say -72 to -78 longitude. The meridian is of course the center of the zone, say, -74. UTM is nicely described in its wikipedia article, as follows: The UTM system divides the surface of Earth between 80°S and 84°N latitude into 60 zones, each 6° of longitude in width. Zone 1 covers longitude 180° to 174° W; zone numbering increases eastward to zone 60 that covers longitude 174 to 180 East. So -- you know the zone's central meridian, you can calculate the zone like this:
zone = int((( merid + 180 ) % 360 ) / 6 ) + 1
For a value of merid = -75 this yields a zone value of 18. Here's python interactive code to test it:
>>> for merid in range(-177,183,6):
... print merid, merid-3,merid+3,int(((merid + 180) % 360) / 6) + 1
...
-177 -180 -174 1
-171 -174 -168 2
-165 -168 -162 3
Here's another explanation, that uses different (but I'm assuming equivalent) integer math. http://www.resurgentsoftware.com/GeoMag/utm_coordinates.htm
... View more
08-14-2012
08:01 PM
|
0
|
0
|
2984
|
|
POST
|
Hello, I'm new to ArcGIS. I have a vbscript that was written for 9.3 that I need to convert to run on 10.1. set gp = CreateObject("esriGeoprocessing.GPDispatch.1")
gp.TableSelect_analysis "Database Connections\\Chancery.odc\\dbo.CDM_ARCCHANCERY2", "C:\\ArcProcessing\\IMP_ARC_CHANCERY.dbf", "Id > 0" I highly recommend doing this using Python instead. The old GPDispatch interface is poorly supported if at all.
import arcpy
arcpy.TableSelect_analysis(\
"Database Connections\\Chancery.odc\\dbo.CDM_ARCCHANCERY2",
"C:\\ArcProcessing\\IMP_ARC_CHANCERY.dbf", "Id > 0") But, you should perhaps try simply running the Table Select tool interactively first to make sure the database connection is set up correctly.
... View more
08-14-2012
03:50 PM
|
0
|
0
|
859
|
|
POST
|
(I) have created depth grid rasters for each stream within the 100 year floodplain of the desired area. I have used the Mosaic to New Raster tool as well as Workspace to New Mosaic. Both produce a seamless depth grid for the entire area, but the new raster dataset seems to shift to the southeast by 60-80 ft. The time to set the snap raster environment is before you create each of the input rasters so the grid cells will all neatly line up with each other. If the grid cells in the input rasters do not "line up," at least one of the input rasters to the mosaic operation will have to be resampled.
... View more
08-14-2012
03:40 PM
|
0
|
0
|
2057
|
|
POST
|
it is able to run but with an error stating that it is unable to create the anotation feature class. It's hard to tell without more details, but my guess is that the feature class names are not unique. All object names within a gdb (tables, feature classes, feature datasets [even those inside of a feature dataset], relationship classes, everything) must be globally unique within the gdb workspace. If your .dwg files have feature classes that are named the same, for example: 94b12v01.dwg\Anno and 94b13c01.dwg\Anno) the only solution is to convert each .dwg to unique gdbs or use Feature Class to Feature Class to copy feature classes one at a time with unique names. (This may require an inner loop and more logic, perhaps the use of the arcpy ListFeatureClasses method.) Also, make sure any feature datasets are deleted from the output gdb after failed attempts. As for setting up the names with a character prefix, you could prefix an "f" to each feature datasetname like this: outDS = "f" + outDS
... View more
08-13-2012
10:22 AM
|
0
|
0
|
6678
|
|
POST
|
Here's an approach that is more robust: import arcpy
import glob
import os
gdb = r"C:\data\cadfile2.gdb"
arcpy.env.workspace = gdb
reference_scale = "1500"
for file in glob.glob(r"C:\CADdata\*.dwg"):
# the following line pulls out the "base name" (file.dwg), strips the .dwg extension,
# and then ensures the name is a valid dataset name for the current workspace
outDS = arcpy.ValidateTableName(os.path.splitext(os.path.basename(file))[0])
arcpy.CADToGeodatabase_conversion(file, gdb, outDS, reference_scale) Also - look out for this gotcha in the tool reference: Feature class names must be unique for the entire geodatabase or the tool will fail. One more thing, you may want to prefix your feature dataset names with a letter - object names that start with a number can cause ArcGIS operations (especially queries) to fail.
... View more
08-13-2012
09:28 AM
|
0
|
0
|
6678
|
|
POST
|
It's been some time since I've had a chance to use the ModelBuilder tool in Toolbox. Just thought I'd add -- I highly recommend you look into using the 10.x iterator tools. IMHO the new iterator tools are much easier to work with than the older 9.x iterating method shown in your screen shot. Here's a tutorial to make you an instant expert! http://blogs.esri.com/esri/arcgis/2011/07/28/tutorial-on-iterators-in-modelbuilder/
... View more
08-13-2012
08:32 AM
|
0
|
0
|
1536
|
|
POST
|
At the UC this year we saw the need for some more documentation on including modules and packages install-free, so we're working on a blog post about that right now. I'm all ears. There is something to be said for widening the footprint of python modules (within reason of course) enough to provide script developers more functionality with no customization of a standard ArcGIS install. Requiring special futzing can be death to a potentially useful tool!
... View more
08-09-2012
10:04 AM
|
0
|
0
|
2676
|
| 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
|