POST
|
Have you tried creating a test variable with a set value in MB? If %Double% doesn't work, then it's not a problem with the raster table, but some other syntax. If %Double% does work, then it's a problem with how you are getting Max.
... View more
05-20-2014
11:17 AM
|
0
|
0
|
749
|
POST
|
I find that ArcMap 10.2 crashes to desktop if I load this tool up with many layers. However, it functions quite reliably one layer at a time. The python console makes this very easy to use: layers = band-select layers, drag and drop into console, hit enter, for layer in layers:
arcpy.sa.ExtractMultiValuesToPoints('RandomPoints', layer, 'NONE') hit enter Has been much easier and more foolproof than other methods.
... View more
04-27-2014
12:28 PM
|
0
|
0
|
1087
|
POST
|
I've been trying to automate the process of clipping thematic rasters to the same extent and then subdividing them by polygon. However, there have been a lot of errors along the way. Here's the latest: Runtime error Traceback (most recent call last): File "<string>", line 85, in <module> File "<string>", line 44, in clip_to_shape File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7030, in ExtractByMask in_mask_data) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper result = wrapper(*args, **kwargs) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 7026, in Wrapper out_raster) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. The table was not found. The table was not found. [VAT_times_ras1] Table attachments not supported in this release of the Geodatabase. The table was not found. [VAT_Extract_tim11] The table was not found. [VAT_Extract_tim11] A column was specified that does not exist. A column was specified that does not exist. The table was not found. [VAT_Extract_tim11] The operation was attempted on an empty geometry. Failed to execute (ExtractByMask). This occurs at the beginning of the 2nd iteration of the for loop. Examination of the data layers shows that the attribute tables of masked_themes are being emptied by the 1st iteration, for an unknown reason. (The headers are still there.) import matplotlib.pyplot as plt
arcpy.env.workspace = 'in_memory'
arcpy.env.snapRaster = r'Fr Demo\Q70slope'
arcpy.env.cellSize = r'Fr Demo\Q70slope'
# store working lists
provinces = [r'Physiographic Provinces\PhysioPacific',r'Physiographic Provinces\PhysioAtlantic',r'Physiographic Provinces\PhysioCentral',r'Physiographic Provinces\PhysioDarien']
themes = ['HWSDunit1kmWGS','Geo1kmWGS',r'Fr Demo\Q70slope']
validators = [r'USGS\Combined\MitchCatBinary1kmGCS',r'U of Oslo\NicCatBinary1kmGCS',r'El Salvador\1km rasters\EScat1kmGCSBinaryClip',r'GLC\GLC1kmGCSbinary']
trainers = [r'Training\TrainingWeighted1kmGCS',r'Training\TrainingAll1kmGCS',r'Training\TrainingSampled1kmGCS']
def create_mask(raster):
# create presence raster
temp = arcpy.sa.IsNull(raster)+1
temp2 = arcpy.sa.LessThan(temp,2)
mask= arcpy.sa.SetNull(temp2,1,'value=0')
del temp, temp2
return mask
def create_masks(rasters):
masks=[]
for raster in rasters:
temp = create_mask(raster)
masks.append(temp)
del temp
return masks
def unify_masks(rasters):
for i in range(len(rasters)):
if i == 0: mask = arcpy.sa.Times(rasters,1)
else: mask = arcpy.sa.Times(rasters,mask)
return mask
def clip_to_mask(rasters,mask):
outputs = []
for raster in rasters:
temp = arcpy.sa.Times(mask,raster)
outputs.append(temp)
del temp
return outputs
def clip_to_shape(rasters,shape):
outputs = []
for raster in rasters:
temp = arcpy.sa.ExtractByMask(raster,shape)
outputs.append(temp)
del temp
return outputs
def get_Fr_table(theme,landslides):
fieldname = "value"
newfieldname = 'Fr'
zsum_table = arcpy.sa.ZonalStatisticsAsTable(theme, fieldname, landslides, 'temp', 'DATA', 'SUM')
arcpy.AddField_management(zsum_table, newfieldname,"DOUBLE")
rows = arcpy.UpdateCursor(zsum_table)
total_count, total_sum = 0,0
for row in rows:
total_count += row.getValue("count")
total_sum += row.getValue("sum")
rows = arcpy.UpdateCursor(zsum_table)
for row in rows:
Lcb = row.getValue("sum")
Scb = row.getValue("count")
Fr = (float(Lcb)/total_sum)/(float(Scb)/total_count)
row.setValue(newfieldname, Fr)
rows.updateRow(row)
return zsum_table
# create raster mask for all layers
masks = create_masks(themes) + create_masks(trainers)
mask = unify_masks(masks)
del masks
# mask all layers
masked_themes = clip_to_mask(themes, mask)
masked_trainers = clip_to_mask(trainers, mask)
masked_validators = clip_to_mask(validators, mask)
del mask
for province in provinces:
# get name of physiographic province
n = province.find('\Physio')+7
province_name = province[n:]
print province_name
# clip layers to province
province_themes = clip_to_shape(masked_themes, province)
province_trainers = clip_to_shape(masked_trainers, province)
province_validators = clip_to_shape(masked_validators, province)
... View more
04-18-2014
07:30 AM
|
0
|
0
|
2222
|
POST
|
I gave Zonal Statistics as Table 2 from v 1.3 a try. It was very easy to use, but it still skips a lot of polygons. (Only 3279 out of 3550 buffers made it into the final table.) It's too bad, because I ran the Model Builder method overnight and it didn't complete.
... View more
04-04-2014
05:47 AM
|
0
|
0
|
745
|
POST
|
Just started Eric's suggestion. It looks like it will probably work, but it's very, very slow. Is there a better way to do this? Hi Anna, You can do this with Zonal Statistics as Table. You just need to make a model that uses the Iterate Feature Selection iterator so that each of the overlapping polygons is passed into the zonal tool individually. You'll get an output table with 1 record for each polygon, then you run Merge to put the rows all back into one table. Then you join back to the polygons using the Zone Field you specified in Zonal Statistics as Table. Technically, you need two models. One that does the iterations on Zonal and collects all the values (the tables), and one that does Merge. You only want to execute Merge once, so this will be your main model, and the iterating model will be the sub-model. Please review the section called, "Advanced use of model iterators", within the help topic, Integrating a model within a model. Best Regards, Eric
... View more
04-03-2014
02:53 PM
|
0
|
1
|
1884
|
POST
|
Solved my own problem (the 2nd field was the polygon) with: for field in fields: # Skip useless fields if field.type == "Geometry": continue fieldname = field.name if "ID" in fieldname: continue # Skip floats for now if field.type == "Double": continue if field.type == "Float": continue
... View more
03-28-2014
08:29 AM
|
0
|
0
|
772
|
POST
|
I get this error when attempting to automate my geoprocessing in the console: Runtime error Traceback (most recent call last): File "<string>", line 9, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 6195, in ZonalStatisticsAsTable statistics_type) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper result = wrapper(*args, **kwargs) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 6187, in Wrapper statistics_type) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function. Can't build VAT for multiband or floating-point raster dataset Failed to execute (ZonalStatisticsAsTable). The first output raster is created correctly, but it never gets to the 2nd. I thought my problem might be related to the in-memory files, but that is not the case. Replacing both of the in_memory\\ locations with a disk location gives exactly the same error. Maybe I need to delete something from memory at the end of the for loop, but it's not clear what. Here is my code: zones = 'HWSDGeolIntersectCopy' landslides = r'USGS\Combined\MitchCatBinary1kmGCS' import arcpy fields = arcpy.ListFields(zones) for field in fields: fieldname = field.name newfieldname = 'Fr_' + fieldname zsum_table = arcpy.sa.ZonalStatisticsAsTable(zones, fieldname, landslides, 'in_memory\zsum_' + zones, 'DATA', 'SUM') arcpy.AddField_management(zsum_table, newfieldname,"DOUBLE") rows = arcpy.UpdateCursor(zsum_table) total_count, total_sum = 0,0 for row in rows: total_count += row.getValue("count") total_sum += row.getValue("sum") rows = arcpy.UpdateCursor(zsum_table) for row in rows: Lcb = row.getValue("sum") Scb = row.getValue("count") Fr = (float(Lcb)/total_sum)/(float(Scb)/total_count) row.setValue(newfieldname, Fr) rows.updateRow(row) arcpy.JoinField_management(zones, fieldname, zsum_table, fieldname, newfieldname) # The following code fixes those polygons not contained in the study area, but present in the output map. # It does so by changing the Fr value to 1. 1 may not be correct, but it is a better representation of # a situation where no data exists than 0. expression = "zero2one(!"+newfieldname+"!)" codeblock = """def zero2one(Fr): if Fr == 0: return 1 else: return Fr""" arcpy.CalculateField_management(zsum_table, newfieldname, expression, "PYTHON_9.3", codeblock) arcpy.PolygonToRaster_conversion(zones, newfieldname[0:10], 'in_memory\\' + newfieldname, 'MAXIMUM_COMBINED_AREA', 'NONE', '0.00833333333333') # clean up del rows arcpy.Delete_management(zsum_table)
... View more
03-28-2014
07:40 AM
|
0
|
1
|
4041
|
POST
|
Ended up using zonal statistics for this. The 1st concern I had may be addressed by judicious use of the the priority setting. However, I had to accept that multiple initiation points would not be retrieved from the same polygon (unless they had exactly the same elevation).
... View more
03-19-2014
09:43 AM
|
0
|
0
|
215
|