|
POST
|
I always meant to come back to this to write something along these lines, but I figured if it ain't broke don't fix it, so I let it slide. Very nice though, tested and approved. One small thing though. Missing underscore on one line. def GetFieldMappings(fc_in, fc_out, dico):
field_mappings = arcpy.FieldMappings()
field_mappings.addTable(fc_in)
for input, output in dico.iteritems():
field_map = arcpy.FieldMap()
field_map.addInputField(fc_in, input)
field = field_map.outputField # Missing underscore
field.name = output
field_map.outputField = field
field_mappings.addFieldMap(field_map)
del field, field_map
return field_mappings
... View more
11-22-2011
07:20 AM
|
1
|
0
|
3829
|
|
POST
|
Looks like improper indentation, but hard to tell. Try writing the whole thing out in IDLE and then copy it in to ArcGIS, if you must run it using the Python window in Arc. Edit: Also with your path strings, use r in front ex. r"H:\Dr. Hines\New File Geodatabase.gdb"
... View more
11-17-2011
11:24 AM
|
0
|
0
|
1309
|
|
POST
|
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=An_overview_of_writing_geoprocessing_scripts
... View more
11-15-2011
07:23 AM
|
0
|
0
|
577
|
|
POST
|
Sorry, I wasn't very clear. You should try to put the previous GP tools in a function, the add field isn't the problem it is just encountering the lock, it is a previous tool, probably the last dissolve there, that is holding the lock. Are you sure your pathnames are not too long? No other processes accessing the data? May be redundant, but have you tried using TestSchemaLock at various times to see where that particular shapefile is being locked and not released? http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000024000000
... View more
11-07-2011
04:25 AM
|
0
|
0
|
1621
|
|
POST
|
I've found using functions solves a lot of ghost schema locking issues I've had.
... View more
11-03-2011
12:32 PM
|
0
|
0
|
1620
|
|
POST
|
It depends on the formatting of your filename. Let's assume it has a name such as textfile = "april25_value.txt" If it is always the same length of "value" you can use something like this. if textfile[-9:] == "value.txt" or if it has a separator like an underscore, you can do if textfile.rsplit("_")[1] == "value.txt" There are other options as well, all depends on how the file names vary you want to process.
... View more
11-02-2011
05:12 AM
|
0
|
0
|
438
|
|
POST
|
Length of list len(listing) Get index starts at zero, so for your example listing = [2,4,6,8] To get 6 you would do listing[2]
... View more
11-01-2011
06:29 AM
|
0
|
0
|
1155
|
|
POST
|
Thanks for all the suggestions, the where clause got me rolling in the right direction, slight modification and worked perfectly. where = "TILE_NAME in ('" + '\',\''.join(dataList) + "')" The workspace wasn't really an issue since I was working in memory, but a good habit to get in to nonetheless. Here's the working script now.
import arcpy, os
sde = r"Database Connections\wisprod.sde"
inputWorkspace = r"\\winms-gissvr\data\new_avi_pgdb\data"
dataList = list()
twnshpLyr = r"TFM_BKG.NEATLINE"
selectSearch = arcpy.SearchCursor(twnshpLyr)
for row in selectSearch:
township = row.getValue("TILE_NAME")
arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb"
fcList = arcpy.ListFeatureClasses()
if fcList:
dataList.append(str(township))
else: pass
arcpy.env.workspace = inputWorkspace
where = "TILE_NAME in ('" + '\',\''.join(dataList) + "')"
arcpy.MakeFeatureLayer_management(sde+os.sep+twnshpLyr, "townshipData", where)
... View more
11-01-2011
05:48 AM
|
0
|
0
|
1133
|
|
POST
|
As for your code problem, try this. Notice how disrespectful of workspaces layers are. import arcpy, os
from arcpy import env
arcpy.env.OverwriteOutput=True
inputWS = r"C:/Temp/LAYERS"
env.workspace=inputWS
mxd=arcpy.mapping.MapDocument("CURRENT")
df=arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
slayer=arcpy.ListFiles("*.lyr")
lcount=len(slayer)
print lcount
for filelay in slayer:
print filelay
lyrFile=arcpy.mapping.Layer(inputWS+os.sep+filelay)
arcpy.mapping.AddLayer(df,lyrFile)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
... View more
10-27-2011
02:17 PM
|
0
|
0
|
1038
|
|
POST
|
try using code tags
for proper indentation
Without the spaces [ CODE][/CODE ]
... View more
10-27-2011
01:57 PM
|
0
|
0
|
1038
|
|
POST
|
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002w0000005s000000 in_memory is in memory, if it were on disk there wouldn't be restrictions on what operations could or couldn't be written to it. It may reference a location on the hard drive for some file management reason over my head, but it is held directly in memory as well. Also, from the UC performance tips slides you linked When you write intermediate data -Do use in_memoryworkspace
... View more
10-27-2011
05:33 AM
|
0
|
0
|
1379
|
|
POST
|
Any suggestions on how I can speed this process up? Don't know much about geocoding first hand, but came across this. http://blogs.esri.com/dev/blogs/geocoding/archive/2011/02/09/tuning-a-locator-for-improved-performance.aspx
... View more
10-26-2011
01:48 PM
|
0
|
0
|
1379
|
|
POST
|
Aye, even though it lets you "create" the table in memory using .dbf, it will simply ignore that and reference the base name. Something like the following should work.
...
arcpy.CreateTable_management("in_memory", "temp")
arcpy.AddField_management(r"in_memory\temp", "address", "TEXT", "", "", "", "", "NON_NULLABLE", "REQUIRED", "")
...
... View more
10-26-2011
01:28 PM
|
0
|
0
|
1379
|
|
POST
|
What I am trying to do is create a definition query or where clause on a polygon grid feature layer. Each grid feature has a name and that name references a unique geodatabase in a directory. What I am doing is checking for a particular layer(s) in each geodatabase, saving that corresponding name in the feature layer if found, and outputting another feature layer with just the polygons that have a geodatabase with a corresponding feature class. Hopefully that wasn't too convoluted. My problem is, no matter what I've tried, I can't seem to pass this list on to something arcpy will take. Here's my code so far, simplified to just test if the geodatabase has features at all. The bold lines are where I would think I need to change to get this to work, crashes on the makefeaturelayer.
inputWorkspace = myWorkspace
dataList = list()
twnshpLyr = r"TFM_BKG.NEATLINE"
selectSearch = arcpy.SearchCursor(twnshpLyr)
for row in selectSearch:
township = row.getValue("TILE_NAME")
arcpy.env.workspace = inputWorkspace+os.sep+township+".mdb"
fcList = arcpy.ListFeatureClasses()
if fcList:
dataList.append(str(township))
else: continue
arcpy.MakeFeatureLayer_management(twnshpLyr, "townshipData", "TILE_NAME in (",str(dataList)+")")
Here is the error I get from the python window: Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Workspace or Feature Dataset: Dataset (...all the feature values in the list...) does not exist or is not supported Failed to execute (MakeFeatureLayer).
... View more
10-26-2011
05:51 AM
|
0
|
3
|
2739
|
|
POST
|
It basically restricts execution if it is imported to another script to specific functions called, unless the script itself is executed. Rafael's link gives a good explanation.
... View more
10-25-2011
06:14 AM
|
0
|
0
|
702
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-17-2011 10:36 AM | |
| 1 | 08-16-2012 10:48 AM | |
| 1 | 10-31-2012 08:39 AM | |
| 1 | 07-16-2012 01:52 PM | |
| 1 | 03-15-2012 10:57 AM |
| Online Status |
Offline
|
| Date Last Visited |
08-22-2024
11:12 PM
|