POST
|
Hello I am completely new to using the arcobjects SDK and have run into a minor issue with a dockable window. When I load the window everything is okay, but once the window is collapsed, the formatting is getting messed up (see image). Pointing me in the direction to fix this issue and any helpful tips would be greatly appreciated! Thanks [ATTACH=CONFIG]29285[/ATTACH]
... View more
11-22-2013
05:45 AM
|
0
|
3
|
508
|
POST
|
@Jill: Thank you for the snippet. I will try this out. @mzcoyle: I closed everything else out and ran it again, with no crashes. I found another issue though, good call on the memory. Thanks
... View more
07-03-2013
06:06 AM
|
0
|
0
|
1896
|
POST
|
Hi Chris, When querying NULL values, you will want to use the syntax "Field IS NULL". You will also want to iterate through your fields list and set the query up for each field name. Here is an example: import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"
fields = ["OBJECTID", "Name", "Address"]
for dirpath, dirnames, filenames in arcpy.da.Walk(env.workspace):
for filename in filenames:
for field in fields:
where = field + " IS NULL"
try:
with arcpy.da.SearchCursor(filename, fields, where) as cursor:
for row in cursor:
print("OBJECTID {0}").format(row[0]) + " in " + filename + " has a NULL value in field " + field
except RuntimeError:
pass
del row, cursor Thank you for the suggestion and helpful script. When I run this on a larger folder (100+) it crashes IDLE. But ran nicely on only 5 or so folders. Thoughts?
... View more
06-24-2013
12:05 PM
|
0
|
0
|
1898
|
POST
|
Your where expression is poorly formed, and you missed a step in the arcpy.da.walk. I would suggest avoiding the cursor altogether:
fields = ["A", "B", "C", "D", "E", "F", "G"]
where = ['"{0}" IS NULL'.format(f) for f in fields]
where = " OR ".join(where)
# where = "A" IS NULL OR "B" IS NULL OR ...
for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="featureclass", type="Polyline"):
for filename in filenames:
path = os.path.join(dirpath, filename) # see example 2 in the help for arcpy.da.walk
lyr = arcpy.MakeFeatureLayer_management(path, "lyr", where)
rows = int(arcpy.GetCount_management(lyr).getOutput(0))
if rows > 0: print filename, " has null values"
If you want to look at all fields no matter what they are named, you can try this inside the loop:
fields = [f.name for f in arcpy.Describe(path).Fields]
where = " OR ".join(['"{0}" IS NULL'.format(f) for f in fields])
lyr = arcpy.MakeFeatureLayer_management(path, "lyr", where)
Thank you for taking a look and with the helpful script. I am running into an issue where it prints 'has null values' when there are no null values. Such that, a date column prints null values when they are not null, same with LAT/LON fields. It seems that is there is more than 1 field in the variable [fields] then it says that the last field in the list has null values. Any thoughts on this?
... View more
06-24-2013
12:02 PM
|
0
|
0
|
1898
|
POST
|
I am trying to use the search cursor to find all null values within a table but am having a hard time with the where-clause statement. How do i search for null values using searchcursor? I have a small example of what I am trying to do:
import arcpy
in_workspace = r"C:/data
"
fields = ["A", "B", "C", "D", "E", "F", "G"]
where = fields = "None"
for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="featureclass", type="Polyline"):
for filename in filenames:
with arcpy.da.SearchCursor(filename, fields, where) as cursor:
for row in cursor:
print filename, "has null values"
I get - RuntimeError: cannot open 'filename' Thanks for any help and time/consideration.
... View more
06-21-2013
05:37 AM
|
0
|
7
|
8061
|
POST
|
In the Results window, what is the exact syntax that is being run? Can you post that? Also is 'dem0' in the map document? It seems to be that it cannot resolve the naming of the raster. Also can you run the script in segments? Will the IsNull work on it's own? Focal Stats? 'dem0' is in the map document. I have tried with multiple different raster images as well. I tried to run the tool in segments and get the same error 000539. I even tried run the tool as a stand alone python script but get the tool is not licensed error. I posted the syntax I used above? What am I missing?
... View more
06-18-2013
06:14 AM
|
0
|
0
|
464
|
POST
|
The help for the error says that it includes the issue that Python has encountered. What's the exact text you're getting with the error? Thank you for responding to this. when I enter:
Con(IsNull('dem0'), FocalStatistics('dem0', NbrRectangle(9,9,"CELL"), 'MEAN'), "dem0")
I usually see error number 1: exceptions.TypeError: cannot concatenate 'str' and 'int' objects. But I just ran it again and have this: Error running expression: rcexec() Thank you for any insight on this.
... View more
06-17-2013
05:43 AM
|
0
|
0
|
464
|
POST
|
Replace the work part with this should do it:
for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="FeatureClass",type="All"):
for filename in filenames:
if "ELEVATION" in [f.name for f in arcpy.ListFields(os.path.join(dirpath, filename))]:
arcpy.AddField_management(os.path.join(dirpath, filename), "SL_ELEV", "SHORT", "", "", "", "", "NULLABLE")
arcpy.CalculateField_management(os.path.join(dirpath, filename), "SL_ELEV", "int(round( !ELEVATION!, -2))", "PYTHON")
else:
print "no Elevation field for dataset ", filename
Of course, you can skip the else: part, only needed if you want it to do something when ELEVATION field not present. R_ This is seriously great. I tried something like this with no luck. But now I understand why it did not work.
if "ELEVATION" == arcpy.ListFields(os.path.join(dirpath, filename)):
Thank you for your time with this.
... View more
06-06-2013
12:49 PM
|
0
|
0
|
403
|
POST
|
Deleted my last post after re-reading. However, it looks like you can use one for loop to replace all three that you are running. might try something like:
import arcpy
import os, math
from arcpy import env
in_workspace = r"F:/Inventory_export_dev/testRnd"
fcList = []
for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="FeatureClass",type="All"):
for filename in filenames:
arcpy.AddField_management(os.path.join(dirpath, filename), fieldName, "SHORT", "", "", "", "", "NULLABLE")
arcpy.CalculateField_management(os.path.join(dirpath, filename), "SL_ELEV", "int(round( !ELEVATION!, -2))", "PYTHON")
No need to put the filenames in a list if all you are going to do is iterate through them again. Just as well do the work on the first iteration. Of course, this will errror out if any of the FC's in your in_workspace do not have the numeric ELEVATION field. R_ I see this works perfectly then. Is there an easy way to skip the files that do not have the elevation field?
... View more
06-06-2013
12:16 PM
|
0
|
0
|
403
|
POST
|
That method works fine for me. Are you sure your field is the right type (long int)? I had no issue with it in arcmap attribute table field calculator. Just in IDLE... My code below:
import arcpy
import os, math
from arcpy import env
in_workspace = r"F:/Inventory_export_dev/testRnd"
rndValue = "int(round(!ELEVATION!, -2))"
fcList = []
fieldName = "SL_ELEV"
for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="FeatureClass",type="All"):
for filename in filenames:
fcList.append(os.path.join(dirpath, filename))
for list in fcList:
arcpy.AddField_management(list, fieldName, "SHORT", "", "", "", "", "NULLABLE")
print "Rounding ELEVATION field to SL_ELEV"
#Rounds values from [ELEVATION] to [SL_ELEV]
for elev in fcList:
arcpy.CalculateField_management(elev, fieldName, rndValue, "PYTHON")
am I missing something?
... View more
06-06-2013
10:50 AM
|
0
|
0
|
1884
|
POST
|
You would use a negative number for the second round() parameter of course. Use int() to ensure it returns an integer instead of float. int(round([field], -2)) How can I use this outside of arcmap? When I try, an error of "Invalid field [field]" appears. I am trying to use it like this:
rndValue = "int(round(!ELEVATION!, -2))"
...
arcpy.CalculateField_management(elev, fieldName, rndValue, "PYTHON")
Thank you
... View more
06-06-2013
10:20 AM
|
0
|
0
|
1884
|
POST
|
I am trying to add a field to all layers with multiple GDB's. Am I unable to collect a list of values and run addField tool on them? import arcpy import os, math from arcpy import env in_workspace = r"F:/test/testRnd" rndValue = "int(round(!ELEVATION!, -2))" fcList = [] fieldName = "SL_ELEV" for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="FeatureClass",type="All"): for filename in filenames: fcList.append(os.path.join(dirpath, filename)) #Add new field arcpy.AddField_management(fcList, fieldName, "SHORT", "", "", "", "", "NULLABLE") Thanks I just needed to run another loop. This got it. for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="FeatureClass",type="All"): for filename in filenames: fcList.append(os.path.join(dirpath, filename)) for list in fcList: arcpy.AddField_management(list, fieldName, "SHORT", "", "", "", "", "NULLABLE")
... View more
06-06-2013
09:28 AM
|
0
|
0
|
172
|
POST
|
I am trying to add a field to all layers with multiple GDB's. Am I unable to collect a list of values and run addField tool on them? import arcpy import os, math from arcpy import env in_workspace = r"F:/test/testRnd" rndValue = "int(round(!ELEVATION!, -2))" fcList = [] fieldName = "SL_ELEV" for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="FeatureClass",type="All"): for filename in filenames: fcList.append(os.path.join(dirpath, filename)) #Add new field arcpy.AddField_management(fcList, fieldName, "SHORT", "", "", "", "", "NULLABLE") Thanks
... View more
06-06-2013
09:19 AM
|
0
|
1
|
652
|
POST
|
You would use a negative number for the second round() parameter of course. Use int() to ensure it returns an integer instead of float. int(round([field], -2)) That is the winner right there, thank you! I knew ther was a better way then to use math.ceil(). I really appreciate the help.
... View more
06-06-2013
08:17 AM
|
0
|
0
|
1884
|
Title | Kudos | Posted |
---|---|---|
1 | 04-09-2015 02:58 PM | |
1 | 04-09-2015 03:20 PM | |
1 | 04-10-2015 07:36 AM |
Online Status |
Offline
|
Date Last Visited |
11-29-2021
12:15 PM
|