|
POST
|
Hi there, I think you're on the right track with the scratch geodatabase. Without 10.2, you can't change the name of an existing field, so you'll have to create new fields. I would recommend these steps: 1. copy features to scratch gdb (good because you won't be editing your original data) 2. add new fields with new names and data types 3. to transfer the values from the old fields to the new, you can either use field calculate and cast the integer as a string, or you could run through the rows with cursors. I think that if you are just going from integers to strings, field calculate should be ok (expression would be: str(!Old_Field!)). Though, if you have null values, they will likely end up as "None". Use cursors for more fine-grained control if you end up with special problem rows... 4. drop the old fields (this is why it's good not to alter the original data) 5. append! (merge?) You could set this all up in model builder without too much trouble... Of course, the problem with adding new fields is that you will not be able to retain the order of the original fields; the new ones will be on the end. If this is a big problem, you may just want to do it manually using ArcGIS Diagrammer: http://resources.arcgis.com/gallery/file/arcobjects-net-api/details?entryID=F12ADF8F-1422-2418-34B2-C276C6BCCF98
... View more
01-17-2014
06:11 AM
|
0
|
0
|
1008
|
|
POST
|
Hi there, this is a little old but perhaps you're still working on it. My understanding is that there are potentially multiple rows per site, with multiple occurrences of 1 in the modelled field, and you want every set of site rows to have exactly one row where modelled = 1. Here are my thoughts (if this is a feature class, just substitute MakeFeatureLayer for MakeTableView):
table = r"path\to\table"
#create unique list of all sites
all_sites = []
rows = arcpy.SearchCursor(table)
for row in rows:
site = row.getValue("Site")
if not site in all_sites:
all_sites.append(site)
del rows, row
#use list to make a series of cursors and then update rows
for s in all_sites:
#set first row to 1, and all others to 0
first = True
rows = arcpy.UpdateCursor(table,'"Site" = ' + str(s))
for row in rows:
if first == True:
row.setValue("Modelled", 1)
first = False
else:
row.setValue("Modelled", 0)
rows.updateRow(row)
del rows, row
You may need to alter the query a little, maybe change the field delimiters, or how you deal with the site number (I'm not sure if you have it stored as an integer or string, here I'm thinking integer). Hopefully this will help out.
... View more
12-11-2013
05:46 AM
|
0
|
0
|
642
|
|
POST
|
Just thought I'd update this because I've long since fixed this issue. In 10.0, multiple input parameters create ValueTables, though I've recently upgraded to 10.1 and found that lists are created in that version. So this only applies to 10.0. To access the feature classes in the ValueTable, I use the following code:
import arcpy
#the following workspace parameter holds the path to the geodatabase
gdb_path = GetParameterAsText(0)
#with the toolvalidator script, the following multivalue string parameter is
#automatically populated with the names of each feature class in the above
#geodatabase. that way the user can select specific feature classes.
#use GetParameter to acquire it as a ValueTable
fc_list = GetParameter(1)
x = 0
while x < fc_list.rowCount:
fc_name = fc_list.getTrueValue(x, 0)
fc = gdb_path + os.sep + fc_name
#do something
x+=1
... View more
11-01-2013
01:57 PM
|
0
|
0
|
271
|
|
POST
|
Hello and thanks for the reply, Unfortunately, that work around still produces nothing. I happened to be working with a joined table, but after removing the join, still no luck. It doesn't even work to flip it around and say
def i(x):
var = x
if var:
return var
else:
return "not null anymore"
Because I'm starting with all Null values, I think my first step will just be to write "NULL" to the entire field, which works, and then query against the string "NULL". Any other ideas would be welcome, too, of course. Thanks!
... View more
02-07-2013
01:37 PM
|
0
|
0
|
976
|
|
POST
|
Ok, I just finished reading a bunch of threads on this, but need to double check this issue. I want to put something like this
def i(x):
if x is None:
return "Used to be Null"
else:
return x
into the code-block, but I've tried all sorts of variations that have been suggested, x == None, x == "", if not x, but nothing has produced any change in the values. Am I missing something, or is this just not going to work and I'll have to use update cursors to perform operations like this? I'm using 10.0 SP5. Thank you!
... View more
02-07-2013
12:29 PM
|
0
|
4
|
1367
|
|
POST
|
I just revisited this, and figured out that my problem was just a silly little detail and glob is perfect after all; I forgot to add "\\" in my string. So, this is all the code I need to put into ToolValidator to test whether an input file geodatabase is in an edit session:
import glob
if glob.glob(str(self.params[0].value) + '\\*.ed.lock'):
self.params[0].setErrorMessage("Close edit session.")
Now I'm going to use it in all my tools... Thanks for the help!
... View more
01-25-2013
02:09 PM
|
0
|
0
|
1016
|
|
POST
|
OK, making progress. When run from IDLE, with or without ArcMap open, it works with a slight modification: using *.ed.lock instead of *.lock. There are a bunch of lock files in there, but when an edit session is started, a file is created for each layer ending in ".ed.lock". No problem to search for those. However, I'm not able to get it to run correctly from ToolValidator. It won't return an error when it should. In the updateMessage class I have
import os.path, glob
if self.params[0].altered:
if glob.glob(str(self.params[0].value) + '*.ed.lock'):
self.params[0].setErrorMessage("Close edit session in Target Geodatabase before continuing.")
I have also tried with hardcoding the .gdb path instead of using str(self.params[0].value). When run from here, perhaps it will not recognize individual files within a .gdb, only feature classes, etc? I also tried os.path.isfile instead of glob.glob but with no luck...
... View more
01-22-2013
12:08 PM
|
0
|
0
|
1016
|
|
POST
|
Hi Kevin, thanks for the reply. It will return true no problem, but after I stop the editing session, it still returns true...
... View more
01-22-2013
09:30 AM
|
0
|
0
|
1016
|
|
POST
|
Hello, just a quick thing that I'd really like to add to a ToolValidator script: Is there a way to see if a geodatabase that I have as an input parameter is currently being edited? I'm running Python 2.6.6 and 10.0 SP5. It looks like I'd be able to do this with 10.1 and the arcpy.da module, but maybe there's a way with what I have.. Thanks, Adam
... View more
01-22-2013
07:25 AM
|
0
|
5
|
1244
|
|
POST
|
Hello, I'm working on a script that basically does one simple thing, append a bunch of feature classes in one geodatabase to corresponding fc's in another geodatabase (there's more to it, but there's no problem with that path of the script). I'm creating a log file to record the results, and there's something I want to do, but I just don't think it'll work. As parameters for the tool, I have only the target geodatabase, and then a multivalue input for all of the feature classes. In the script, the latter parameter comes in as a ValueTable, and I'm able to do what I need by accessing the feature classes with a while loop. However, I'm hoping to be able to take the first feature class, and work backward to automatically locate my newly created logfile in the folder that holds the original geodatabase. I struggled with this for a while, and found that the problem is that the values in the ValueTable to do not have paths. I've looked for a way of finding the containing folder/workspace of a feature class, but have come up short. Any ideas? Of course I can add a parameter that can just be filled in with a folder path, but I'd prefer to automate this. Thanks, Adam
... View more
01-14-2013
01:25 PM
|
0
|
1
|
528
|
|
POST
|
Service Pack 5 seems to have done the trick, no crashing, just the expected error message. Thanks!
... View more
01-02-2013
07:06 AM
|
0
|
0
|
1246
|
|
POST
|
Hi Jake, Happy New Year! Here's a screen shot. Let me know if you wanted a different parameter highlighted. Thanks! Adam
... View more
01-02-2013
05:38 AM
|
0
|
0
|
1246
|
|
POST
|
Yes, I tried that right away and it doesn't crash, I just get the "does not exist/not supported" message. Ok, it only happens when I drag/drop into the parameter that has been modified in the ToolValidator with the code described above. Here is the code that I have in ToolValidator: ([1] is the input fc parameter set to feature layer, and [2] is the string parameter that just shows the coordinate system of [1]): def updateParameters(self):
self.params[2].enabled = 0
if self.params[1].value:
self.params[2].enabled = 1
SR = arcpy.Describe(self.params[1].value).spatialReference
self.params[2].value = SR.name
self.params[2].enabled = 0
return When I comment out this code, the parameter drag/drop operation functions as it should.
... View more
12-21-2012
01:57 PM
|
0
|
0
|
1246
|
|
POST
|
Hello Chris, I'm running ArcGIS 10.0 without any service pack. I've been retrying this a number of times, and it crashes pretty reliably, but not every single time. One time gave me the error message you mentioned after I correctly input a layer and then tried to drag one from an inactive dataframe, but now that doesn't work and it crashes everytime... I'm using a script that I created, and it's one of my first attempts at any meaningful programming, so I could have something wrong that I'm unaware of. I can give you more details on the script if you need. Thanks!!
... View more
12-21-2012
01:08 PM
|
0
|
0
|
1246
|
|
POST
|
Splendid, thanks a million. Only thing I had to do was dedent the DeleteField line so that it did not try to run every time after checking each field.
... View more
12-20-2012
07:32 AM
|
0
|
0
|
722
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 04-03-2015 07:41 AM | |
| 1 | 04-02-2015 03:42 PM | |
| 3 | 08-14-2014 09:58 AM | |
| 1 | 08-12-2014 07:10 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:24 AM
|