Guest User

Untitled

a guest
Jan 16th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. import arcpy, glob, os, sys
  2. from arcpy import env, mapping
  3. path = os.getcwd()
  4. env.workspace = path
  5. RasterType = 'TIF'
  6. FileList = glob.glob(path + "*." + RasterType)
  7.  
  8. print 'Reading files from ' + path
  9. os.chdir(path)
  10. #print FileList
  11.  
  12. x=0
  13. z=1005
  14. File=FileList[x]
  15. LayerWorking=arcpy.mapping.Layer(File)
  16. print File
  17. LayerExtent=LayerWorking.getExtent()
  18. XMAX = LayerExtent.XMax
  19. XMIN = LayerExtent.XMin
  20. YMAX = LayerExtent.YMax
  21. YMIN = LayerExtent.YMin
  22. pnt1 = arcpy.Point(XMIN, YMIN)
  23. pnt2 = arcpy.Point(XMIN, YMAX)
  24. pnt3 = arcpy.Point(XMAX, YMAX)
  25. pnt4 = arcpy.Point(XMAX, YMIN)
  26. array = arcpy.Array()
  27. array.add(pnt1)
  28. array.add(pnt2)
  29. array.add(pnt3)
  30. array.add(pnt4)
  31. array.add(pnt1)
  32. polygon = arcpy.Polygon(array)
  33. ShapeFile = path + "Polygon_Extent" + "_" + str(z) + ".shp"
  34. print ShapeFile
  35. print arcpy.GetMessages()
  36. arcpy.CreateFeatureclass_management(path, ShapeFile, "POLYGON")
  37. print arcpy.GetMessages()
  38. arcpy.CopyFeatures_management(polygon, ShapeFile)
  39.  
  40. import arcpy, glob, os, sys, arcgisscripting
  41. from arcpy import env, mapping
  42. path = os.getcwd()
  43. env.workspace = path
  44. env.overwriteOutput = True
  45. RasterType = 'TIF'
  46. FileList = glob.glob(path + "*." + RasterType)
  47. print 'Reading files from ' + path
  48. os.chdir(path)
  49. #print FileList
  50. geometry_type = "POLYGON"
  51. template = "C:\Python26\GDA_1994_MGA_Zone_55.shp"
  52. has_m = "DISABLED"
  53. has_z = "DISABLED"
  54. # Creating a spatial reference object
  55. spatial_reference = arcpy.SpatialReference("C:\Python26\GDA_1994_MGA_Zone_55.prj")
  56.  
  57. x=0
  58. z=x+1
  59. for File in FileList:
  60. #File=FileList[x]
  61. RasterFile = arcgisscripting.Raster(File)
  62. RasterExtent = RasterFile.extent
  63. print File
  64. XMAX = RasterExtent.XMax
  65. XMIN = RasterExtent.XMin
  66. YMAX = RasterExtent.YMax
  67. YMIN = RasterExtent.YMin
  68. pnt1 = arcpy.Point(XMIN, YMIN)
  69. pnt2 = arcpy.Point(XMIN, YMAX)
  70. pnt3 = arcpy.Point(XMAX, YMAX)
  71. pnt4 = arcpy.Point(XMAX, YMIN)
  72. array = arcpy.Array()
  73. array.add(pnt1)
  74. array.add(pnt2)
  75. array.add(pnt3)
  76. array.add(pnt4)
  77. array.add(pnt1)
  78. polygon = arcpy.Polygon(array)
  79. arcpy.CreateFeatureclass_management(path, "Temp_Polygon_Extent" + "_" + str(z), geometry_type, template, has_m, has_z, spatial_reference)
  80. arcpy.CopyFeatures_management(polygon, "Temp_Polygon_Extent" + "_" + str(z))
  81. ShapeFile = "Temp_Polygon_Extent" + "_" + str(z) + ".shp"
  82. print "Created: " + ShapeFile
  83. arcpy.AddField_management(ShapeFile,'FileName','TEXT')
  84. desc = arcpy.Describe(ShapeFile)
  85. print desc, ShapeFile
  86. #rows = arcpy.InsertCursor(ShapeFile, desc)
  87. rows = arcpy.UpdateCursor(ShapeFile)
  88. #row = rows.newRow()
  89. #row.FileName = str(File)
  90. #row.FileName = File
  91. print 'Filled in: ', str(File)
  92. #rows.insertRow(row)
  93. for row in rows:
  94. row.FileName = str(ShapeFile)
  95. rows.updateRow(row)
  96. x=x+1
  97. z=z+1
  98.  
  99. #cleaning up
  100. arcpy.CreateFeatureclass_management(path, "Extent.shp", geometry_type, template, has_m, has_z, spatial_reference)
  101. list =[]
  102. lstFCs = arcpy.ListFeatureClasses("Temp_Polygon_Extent*")
  103. print 'Merging Polygon_Extents* to Extent.shp'
  104.  
  105. for fc in lstFCs:
  106. print fc
  107. list.append(fc)
  108.  
  109. arcpy.Merge_management(list, "Extent.shp")
  110. #print 'Deleting identical entries and temp files'
  111. #arcpy.DeleteIdentical_management("Extent.shp", ["SHAPE"])
  112. print 'Created Extent.shp and exiting'
  113.  
  114. for item in list:
  115. arcpy.Delete_management(item)
  116. del row, rows
  117.  
  118. import os, gdal
  119. gdaltindex Extent.shp *.tif
  120.  
  121. extent1 = arcgisscripting.Raster('stg1_05.jpg').extent
  122.  
  123. raster1 = arcgisscripting.Raster('stg1_05.jpg')
  124. extent1 = raster1.extent
  125.  
  126. gdaltindex Extent.shp *.jpg
Add Comment
Please, Sign In to add comment