row.top = arcpy.GetRasterProperties_management(raster, "top")
row.top = str(arcpy.GetRasterProperties_management(raster, "top"))
row.top = str(arcpy.GetRasterProperties_management(raster, "top"))
>>> r = arcpy.GetRasterProperties_management("cdl20091.tif","top") # result object >>> r <Result '3173073.79641599'> >>> r.getOutput(0) # result object output u'3173073.79641599' >>> str(r) # returns string rep of result output '3173073.79641599' >>> float(str(r)) # convert to float 3173073.79641599
import os path = "e:\\test\\" rasters = [] for path,dirs,files in os.walk(path): for file in files: if file.endswith(".tif") == True: rasters.append(str(path) + "\\" + str(file))
import os import arcpy from arcpy import env env.workspace = "E:/Data/X-005" # Create table if arcpy.Exists("E:/Data/X-005/Test.dbf"): arcpy.Delete_management("E:/Data/X-005/Test.dbf") table = arcpy.CreateTable_management("E:/Data/X-005", "Test.dbf") # Add fields arcpy.AddField_management(table, "name", "TEXT") arcpy.AddField_management(table, "top", "TEXT") # Insert values rows = arcpy.InsertCursor("E:/Data/X-005/Test.dbf") # get rasters path = "e:\\test" rasters = [] for path,dirs,files in os.walk(path): for file in files: if file.endswith(".tif") == True: rasters.append(str(path) + "\\" + str(file)) for raster in rasters: row = rows.newRow() row.top = arcpy.GetRasterProperties_management(raster, "top") row.name = raster rows.insertRow(row) # Delete cursor and row objects ro remove locks on the data # del row del rows
Traceback (most recent call last): File "W:\Organisation\10013 Aktualisierung der Luftbilddatenbank in Bezug auf Georeferenzierung\Daten\georeference_in_attribute_table_new.py", line 31, in <module> row.top = arcpy.GetRasterProperties_management(raster, "top") File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__ return setattr(self._arc_object, attr, ao) ValueError: Row: Invalid input value for setting
import os import arcpy from arcpy import env env.workspace = "C:/Data" # Create table if arcpy.Exists("C:/Data/Test.dbf"): arcpy.Delete_management("C:/Data/Test.dbf") table = arcpy.CreateTable_management("C:/Data", "Test.dbf") # Add fields arcpy.AddField_management(table, "name", "TEXT") arcpy.AddField_management(table, "top", "TEXT") # Insert values rows = arcpy.InsertCursor("C:/Data/Test.dbf") # get rasters path = "C:/data" rasters = [] for path,dirs,files in os.walk(path): for file in files: if file.endswith(".ecw") == True: rasters.append(str(path) + "/" + str(file)) for raster in rasters: row = rows.newRow() row.top = arcpy.GetRasterProperties_management(raster, "top") row.name = raster rows.insertRow(row) # Delete cursor and row objects ro remove locks on the data # del row del rows
Now I get the following problem when I run the script:Traceback (most recent call last): File "W:\Organisation\10013 Aktualisierung der Luftbilddatenbank in Bezug auf Georeferenzierung\Daten\georeference_in_attribute_table_new.py", line 31, in <module> row.top = arcpy.GetRasterProperties_management(raster, "top") File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", line 35, in __setattr__ return setattr(self._arc_object, attr, ao) ValueError: Row: Invalid input value for setting