|
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? 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)
... View more
06-21-2013
08:59 AM
|
0
|
0
|
4199
|
|
POST
|
The tool turns out a raster with no "values". While they can be displayed, they are incredibly large files and can not be converted to a shape file due to not having any data attached. If polygons are what you want, you would need to do something like this to create an integer grid of all non-null cells, and then convert that to polygons:
dem1 = SetNull(IsNull(ExtractByAttributes(Raster("dem"), where)),1)
... View more
06-21-2013
08:17 AM
|
0
|
0
|
1599
|
|
POST
|
You may want to look into terrains, which can handle larger numbers of points and do this conversion on the fly when needed.
... View more
06-21-2013
08:10 AM
|
0
|
0
|
1529
|
|
POST
|
Next time I encounter the problem, I will see if a dissolve could be a better way to handle the small, spurious watersheds. If you do want to zap away these small watersheds pieces, the raster tool equivalent of Eliminate is to use these tools to locate these small isolated regions and nibble them away: RegionGroup (FOUR option) ZonalGeometry (calculate AREA) Con (to select small areas) Nibble
... View more
06-20-2013
02:23 PM
|
0
|
0
|
2217
|
|
POST
|
Thanks Stuart, This helps a lot, and your explanation is very clear. I'm in the process of re-installing right now and will set the PATH and PYTHONHOME variables. I had installed the Enthought for python and had forgotten that I had it on my computer. Prior to uninstalling I had tried just changing the the PATH and PYTHONHOME variables, but that alone didn't end up doing the trick. If I'm understanding what you're saying correctly if I want to run 64bit python for scripts outside of ArcGIS I should simply be able to change the PATH and PYTHONHOME variables temporarily to point them to the 64 bit version? -Tom Tom, currently EPD and ArcGIS are lined up with versions. We have had good luck accessing arcpy from EPD and EPD from arcpy by doing this, and avoiding all the environment variable stuff, which can get your wrapped around the axle in Windows. 1. allow EPD scripts to import arcpy copy C:\Python27\ArcGIS10.1\lib\site-packages\Desktop10.1.pth to C:\Python27\epd32\lib\site-packages\zzDesktop10.1.pth (use your EPD install folder) and 2. allow arc python scripts to import epd modules create a file C:\Python27\ArcGIS10.1\lib\site-packages\zzEPD.pth including the path C:\Python27\epd32\lib\site-packages The use of the "zz" prefix is to control the order to make sure the "native" libraries to that environment are loaded first.
... View more
06-20-2013
02:19 PM
|
0
|
0
|
554
|
|
POST
|
I don't think that will work Curtis since each point probably has a unique z You're absolutely right Eric. You deserve the checkmark!
... View more
06-20-2013
02:01 PM
|
0
|
0
|
3329
|
|
POST
|
The Extract by attribute tool however created more questions than it answered. Did the string substitution to create the SQL expression throw you for a loop?
where = "VALUE > " + str(a1min) + " AND VALUE < " + str(a1max)
where = "VALUE > {0} AND VALUE < {1}".format(a1min, a1max)
These expressions are equivalent, they both evaluate to something like: VALUE > 5000 AND VALUE < 6000 I like to promote the use of string substitution because it makes the SQL expression setup much easier to read and debug.
... View more
06-20-2013
01:58 PM
|
0
|
0
|
1599
|
|
POST
|
Hi all, I'm running Python using WSGI under Wamp. The user uploads a shapefile to my server then I try to run arcpy.Describe and even though os.path.exists(...) says the file exists, arcpy it telling me that the file doesn't exist. Is there any particular reason why this would happen? Also, if I run the same function from the console (instead of via the browser), arcpy is able to magically find the file. I'm using an absolute path to the file and I'm not using arcpy.env.workspace at all. Are you specifying the path correctly (to handle backslashes)? Ie using r"" or "\\" or "/"?
... View more
06-20-2013
09:36 AM
|
0
|
0
|
739
|
|
POST
|
I have a point file with 4 points with an elevation field and I want to convert to a 3D line. Have you tried the Points To Line tool followed by Feature To 3D By Attribute?
... View more
06-20-2013
09:33 AM
|
0
|
0
|
3329
|
|
POST
|
I obtain acceptable TIN when the z tolerance is equal or higher than 1 unit. But when i test 0.5, 0.9 or even 0.999 values, my TIN becomes completely irrational (for example, the first half of my TIN is a perfect regular TIN with 1-meter edges, but the second half does not represent nothing, with 200-meters-edge triangles). It seems that 1 is a limit value for z tolerance, is this correct ? What can i do to test lower values than 1 ? Are you sure you have this much Z accuracy in your elevation data? Is this going to create more than few million nodes? If this is indeed a bug with the tool and not your data, you could scale your data by using a Z factor. This will scale your values by 100 so you can use smaller tolerances, for example, if the z_factor is set to 100, a z_tolerance of 50 would represent 0.5.
... View more
06-20-2013
09:13 AM
|
0
|
0
|
1529
|
|
POST
|
I know that exist a tool Add Spatial index but I haven't found one that just update or recalculate my spatial index. Is there one? From the help for Add Spatial index: By default, ArcGIS creates and maintains a spatial index for geodatabase feature classes. For a geodatabase feature class to not have a spatial index, you must explicitly remove it using the Remove_Spatial_Index tool If you find it didn't automatically update, you can run both tools to remove and then add the spatial index.
... View more
06-20-2013
08:59 AM
|
0
|
0
|
1706
|
|
POST
|
Is there a better way to use the multivalue property in a script tool? You could use GetParameter() instead of GetParameterAsText() and process it as a value table. This is the only approach for example, with a list of layer names if you want to handle layers that contain ";". It's a lot more complicated to work with parameter objects, and harder to debug, so I try to avoid doing it that way. Are you sure you are getting quotes? The best way to check is with repr: CensusDataList = arcpy.GetParameterAsText(0).split(";") for d in CensusDataList: print repr(d) If you do indeed have extra quotes, you could strip them like this: CensusDataList = string.split(arcpy.GetParameterAsText(0), ";") CensusDataList = [d.strip("'") for d in CensusDataList] And avoid spaces in paths -- just trouble as far as I'm concerned! One more thing, in arcpy, tools can read lists, so you don't need to join them back together with ";" delimiters: #Loop through each state directory in the list to create an input value (another list) hzCounties = ["{}\\bndrygbs.mdb\\hzCounty".format(p) for p in CensusDataList]
... View more
06-19-2013
04:03 PM
|
0
|
0
|
1022
|
|
POST
|
the original AML querry and calc was simple Select: >= 30 AND (( [PF] is null ) AND ( [MC] = 300 )) Calc: [PF] = 'Char' Amy, I knew AML. AML was a friend of mine. This is not AML. Avenue, VBA maybe? Please, can anyone tell me how to determin if A) features are selected and B) how to correctly calc the selected set into the item . Here's a direct answer to your question
arcpy.env.workspace = "myfile.mdb"
pvar = arcpy.AddFieldDelimeters("P") #
for mdb, "P" otherwise
pfvar = arcpy.AddFieldDelimeters("PF")
mcvar = arcpy.AddFieldDelimeters("MC")
where = '{0} > 30 AND (({1} IS NULL) AND ({2} = 300))'.format(pvar,pfvar,mcvar)
lyr = arcpy.MakeFeatureLayer_management(features, "lyr", where)
result = arcpy.GetCount_management(lyr)
nselect = int(result.getOutput(0))
print str(nselect), " selected"
arcpy.CalculateField_management(lyr, "P", "'Char'", "PYTHON_9.3")
arcpy.Delete_management(lyr) # clean up
... View more
06-19-2013
03:35 PM
|
0
|
0
|
1457
|
|
POST
|
I have a table with multiple min and a max numbers for multiple points. I would like to use "Extract by Attribute" to pull the fitting areas from a DEM which corresponds to each area. The best way to get the variables from a table into Python is using cursors. For example: rows = arcpy.SearchCursor("areatable.dbf") k = 1 for row in rows: a1min = float(row.getValue("Area1Min")) a1max = float(row.getValue("Area1Max")) where = "VALUE > {0} AND VALUE < {1}".format(a1min, a1max) dem1 = ExtractByAttributes(Raster("dem"), where) dem1.save("dema{}".format(k)) # save as grids dema1, dema2 del row, rows Instead of ExtractByAttributes you could use the Con function like this. This is more of an Arcpy approach really: dem = Raster("dem1") dem1 = Con(dem > a1min and dem < a1max, dem)
... View more
06-19-2013
03:22 PM
|
0
|
0
|
1599
|
|
POST
|
Any ideas how I can get the AHP extension (arcscripts link) to run in ArcMap 10.1? The documentation for this tool says it was last tested with ArcGIS 9.1. ArcObjects applications don't tend to travel well between major versions, the developer would have to pretty much re-code it to work with the 10.x version of the software -- there were major architecture updates at 10.0 -- I have never seen a 9x .dll that worked with 10.x. You have to ask the developer to update the extension, (hopefully using the new addin technology so it can be loaded without elevated privileges). Shaun, did you locate a different version? The one on ArcScripts is a .dll (presumably built with VB6, *not* VBA).
... View more
06-19-2013
03:05 PM
|
0
|
0
|
3809
|
| 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
|