|
POST
|
Rhett, Please disregard my dumb question 🙂 It was really the problem with the tab! It is working great! I will post another thread if I have any more questions about the updating of rows using this type of selection! Thank you so much! You rock! I was wondering if you posted that before you saw the last post about the tab. That was confusing as could be, as my code "looked" the same, but I got different results typing it in vs running my script. As far as the sort and fields, the myField+" D" lets me pass the field as a variable so I can use in a def for multiple FC's. As you can see in my last posting, I hard coded it to OBJECTID, so can be done either way. R_
... View more
07-09-2013
01:44 PM
|
0
|
0
|
1000
|
|
POST
|
I am actually running the script I am writing so I am not directly using the tool. Not sure why it works. Are you running in the python window in ArcMap/Catalog or actually in the IDE or command window? If I try to run on a FC in the IDE (stand alone without ArcCrap) I get this:
ExecuteError: Failed to execute. Parameters are not valid.
The value cannot be a feature class
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Mosaic Layer.
Failed to execute (SelectLayerByAttribute).
Once I use a feature layer, it works fine. R_
... View more
07-09-2013
01:42 PM
|
0
|
0
|
2025
|
|
POST
|
I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!!
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID D").next().getValue("OBJECTID")
arcpy.AddMessage(maxValue)
Ionara, Well, this was a little confusing as I get the same result each time I run the script also, unless I type it directly into the console. If I type it in, I get the max and min numbers. If I run the code, I get the min number each time. Turns out there is a copy/paste/formatting issues somewhere. the "OBJECTID D" should have a space in between the "OBJECTID" and the "D". However, it appears as if there is a tab character there, so it is getting ignored in the cursor so the table is sorted by default (OID Ascending). Once I put a space in there as expected, it successfully gets both the max and min.
maxValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID D").next().getValue("OBJECTID")
max Value = 2110
minValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID A").next().getValue("OBJECTID")
min Value = 1
R_
... View more
07-09-2013
01:34 PM
|
0
|
0
|
2025
|
|
POST
|
I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!!
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID D").next().getValue("OBJECTID")
arcpy.AddMessage(maxValue)
Yes, the select by location needs a feature layer also. For you to be able to create a selection directly on the FC, I would assume that you are running from within ArcMap. If this is the case, ArcMap "secretly" and "silently" converts FC's in the TOC to a feature layer that can be used for input to the tools. if a feature layer is needed, and you choose the dropdown list in the tool to select the FC, the visible FC's are actually an on the fly feature layer. So, I guess if this is always run from within ArcMap, you woulnd't need that step as it is done for you. Of course, if you export that script/model to python, it doesn't do this part for you and you need to add in the make feature or the script will error out. R_
... View more
07-09-2013
01:29 PM
|
0
|
0
|
2025
|
|
POST
|
You could use a cursor with a sort on it:
infc = my input feature class
myField = field I am after the max value from
OID = ObjectID field of my FC.
[maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)
change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable. this would give you the values, could then use that to select by. R_ Ionara, In my original posting of this code, I have the myField+" D" section that you have changed to the OBJECTID field. This is the field that it is sorting on, so using the OID field, will get you the first (+ " A") or last (+ " D") record in the table. If you are trying to find a max or min value of a particular field, you need to have that field set as the sort field. " D" sorts the table by field and would put the largest value as the first row. The .next() grabs the next (in this case the first) row, that being sorted descending, is the max. R_
... View more
07-09-2013
12:59 PM
|
0
|
0
|
2025
|
|
POST
|
Fire got put out before I made it. :DIf you don't just need to update, but actually need a "selection" to use in a process, this is the line of thought I was thinking:
minValue = arcpy.SearchCursor("Stewardship", "", "", "", "OID A").next().getValue("OID")
arcpy.MakeFeatureLayer_management ("Stewardship", "feat_layer")
arcpy.SelectLayerByAttribute_management ("feat_layer", "NEW_SELECTION", " [OID] = " + maxValue)
Whatever you do now on "feat"layer" will honor the selection if that tool supports it.
R_ This one I changed to minValue since we are sorting Ascending so would get the min as the first row.
... View more
07-09-2013
12:42 PM
|
0
|
0
|
2025
|
|
POST
|
rows = arcpy.UpdateCursor("Stewardship", "", "", "", "OBJECTID A")
row = rows.next()
row.yearonly = DateStart[5:9]
rows.updateRow(row)
another quick thought before I run, UpdateCursor supports the sort also, might try something like above and see if it works correctly. This is how I define row(s) values without having to actually iterate through the cursor. Of course, you need to have a field in Stewardship FC named "yearonly". Should update the field "yearonly" to the value in stored in the variable DateStart[5:9]. R_ Of course, I noticed that the " D" was changed to " A", so this should actually grab the minimum value, not the max.
... View more
07-09-2013
12:35 PM
|
0
|
0
|
4311
|
|
POST
|
I think I am getting there but still getting an error for the first line. Do you see anything wrong on the first line? Thanks!!!! I am getting this error: Error Info: <type 'exceptions.RuntimeError'>: ERROR 999999: Error executing function.
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID A").next().getValue("OID")
arcpy.SelectLayerByAttribute_management("Counties", "NEW_SELECTION", maxValue)
result = int(arcpy.GetCount_management("Stewardship").getOutput(0))
arcpy.AddMessage(result)
Got a fire going in a few minutes, so I'll have to try to get back to previous posts later, but it seems you are on the right track. However, will need to make a feature layer before selection as selectbyatt can't utilize a FC directly. As far as the error, probably your OID field name, it can't be both. you are sorting on OBJECTID, but trying to extract a value from OID. R_ R_
... View more
07-09-2013
12:28 PM
|
0
|
0
|
4311
|
|
POST
|
Brad, you are correct, it seems I was a little confused..... or something..... Anyway, I'd have to defer to Robert's post above. R_
... View more
07-09-2013
12:25 PM
|
0
|
0
|
4697
|
|
POST
|
To get user input in python, can use raw_input.
W = raw_input("Enter Weight in kg. -->")
If running within a tool, you would probably need the GetPrameters... and set the parameters in the script itself. Would suggest the help files for info on that. http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000004000000
... View more
07-09-2013
11:16 AM
|
0
|
0
|
2973
|
|
POST
|
This works, but you will have to check with your numbers to make sure it is working "correctly"
m = (1.5 * W + 2 * (W + L) * (L / W)**2 + n * (W + L) * (1.5 * V**2 + 0.35 * V * S))
R_
... View more
07-09-2013
09:50 AM
|
0
|
0
|
2973
|
|
POST
|
Basically, it is just sorting the table decending by myField, then grabbing the "first" row. Change the " D" to " A" and will sort ascending and would grab the minimum value instead. R_
... View more
07-09-2013
09:36 AM
|
0
|
0
|
4311
|
|
POST
|
Brad, The TOC widget lets you exlude layer(s) by layer label in the config.xml. If you add the label of a layer to the exlude section of the TOC, you should not see that service in the TOC to be able to turn on/off in the first place. It sounds like you are trying to exclude a sub-layer from the TOC. I don't see anywhere that says that is possible, unless the sub-layer was loaded separatly so that it had it's own <layer> tag in the config.xml file. R_
... View more
07-09-2013
09:33 AM
|
0
|
0
|
4697
|
|
POST
|
You could use a cursor with a sort on it: infc = my input feature class myField = field I am after the max value from OID = ObjectID field of my FC.
maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)
change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable. this would give you the values, could then use that to select by. R_
... View more
07-09-2013
09:20 AM
|
0
|
0
|
4311
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-14-2026 04:00 PM | |
| 1 | 09-14-2022 07:53 AM | |
| 1 | 09-14-2022 08:23 AM | |
| 1 | 05-21-2026 08:53 AM | |
| 1 | 05-14-2026 04:28 PM |
| Online Status |
Online
|
| Date Last Visited |
2 weeks ago
|