import arcpy from arcpy import env from arcpy import mapping env.overwriteOutput = 1 mxd = mapping.MapDocument(r"C:\temp\python\Points.mxd") df = mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd)[0] # Create new photo directory newPhoto = r"C:\Temp\Python\Photos\New Photos" dict = {} # Create dictionary of OBJECTIDs and the path to the photo with arcpy.da.SearchCursor(lyr, ["OBJECTID", "PHOTO"]) as cursor: for row in cursor: rasterName = row[1].split("\\")[-1] dict[row[0]] = rasterName firstTime = "True" # Select each point, zoom/pan to the selected point, create a polygon feature class from extent, # convert polygon to raster dataset for key in dict: if firstTime == 'True': arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "OBJECTID = " + str(key)) df.extent = lyr.getSelectedExtent() XMAX = df.extent.XMax XMIN = df.extent.XMin YMAX = df.extent.YMax YMIN = df.extent.YMin pnt1 = arcpy.Point(XMIN, YMIN) pnt2 = arcpy.Point(XMIN, YMAX) pnt3 = arcpy.Point(XMAX, YMAX) pnt4 = arcpy.Point(XMAX, YMIN) array = arcpy.Array() array.add(pnt1) array.add(pnt2) array.add(pnt3) array.add(pnt4) array.add(pnt1) polygon = arcpy.Polygon(array) arcpy.CopyFeatures_management(polygon, r"IN_MEMORY\polygon") arcpy.PolygonToRaster_conversion(r"IN_MEMORY\polygon", "OID", r"IN_MEMORY\raster") arcpy.CopyRaster_management(r"IN_MEMORY\raster", newPhoto + "\\" + dict[key]) firstTime = "False" else: arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "OBJECTID = " + str(key)) df.panToExtent(lyr.getSelectedExtent()) XMAX = df.extent.XMax XMIN = df.extent.XMin YMAX = df.extent.YMax YMIN = df.extent.YMin pnt1 = arcpy.Point(XMIN, YMIN) pnt2 = arcpy.Point(XMIN, YMAX) pnt3 = arcpy.Point(XMAX, YMAX) pnt4 = arcpy.Point(XMAX, YMIN) array = arcpy.Array() array.add(pnt1) array.add(pnt2) array.add(pnt3) array.add(pnt4) array.add(pnt1) polygon = arcpy.Polygon(array) arcpy.CopyFeatures_management(polygon, r"IN_MEMORY\polygon") arcpy.PolygonToRaster_conversion(r"IN_MEMORY\polygon", "OID", r"IN_MEMORY\raster") arcpy.CopyRaster_management(r"IN_MEMORY\raster", newPhoto + "\\" + dict[key]) del mxd # Clear the selection arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION") list = [] with arcpy.da.SearchCursor(lyr, ["PHOTO"]) as cursor: for row in cursor: list.append(row[0]) # Copy original photo to the new photo directory, replacing the raster created previously for photo in list: shutil.copy(photo, newPhoto) spatial_ref = arcpy.Describe(lyr).spatialReference # Project each raster env.workspace = newPhoto for raster in arcpy.ListRasters("*"): arcpy.DefineProjection_management(raster, spatial_ref)
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.