def georef(chm_dir, link_dir): """ Georeferencing CHM output from each band of the Parrot Sequoia to the Mavic rgb data. First param is the directory where CHM are stored assuming a "Cover/Reference Id/CHM for each band" structure. Second is where the .txt files; products of georeferencing (in GUI) a Sequoia orthophoto to the Mavic ortho in ArcGIS. """ ## Looping through covers for cover in os.listdir(chm_dir): ## Looping through referebce IDs for refID in os.listdir(os.path.join(chm_dir, cover)): warp_dir = (os.path.join(chm_dir, cover, refID, "warped")) try: os.mkdir(warp_dir) except: pass for item in os.listdir(os.path.join(chm_dir, cover, refID)): infile = os.path.join(chm_dir, cover, refID, item) outfile = os.path.join( warp_dir, os.path.splitext(item)[0][:-5] + "wrp.tif") link_file = os.path.join(link_dir, cover, refID + ".txt") if "rgb" in item: shutil.copy(infile, warp_dir) print(item) ## Georectification elif item.endswith(".tif"): arcpy.WarpFromFile_management(infile, outfile, link_file, "POLYORDER1") print(infile, outfile, link_file)
def georeferencing(self): import arcpy if os.path.isfile(self.pathOutput+"gcp.txt"): print ("Georeferencing output from GCPs") files=os.listdir(self.pathOutput) for file in files: if ".tif" in file: try: arcpy.WarpFromFile_management( self.pathOutput+file, self.pathOutput+"georef_"+file, self.pathOutput+"gcp.txt", "POLYORDER1", "BILINEAR") except: print ("Error georeferencing "+file) else: print ("No GCP file found.")
# GDBworkspace = r'E:/ArcPyscript/SZCoordinateTool/test.gdb' staticGDB = r'./test.gdb' saveToGDB = r'./data.gdb' inputLinkFeatures = os.getcwd() + '\\' + 'newszto54114.txt' inputFeatures = staticGDB + "\\" + 'SZbasemapnewSZ' output54114 = saveToGDB + "\\" + 'pySZbasemapnew54114' outputWGS84 = saveToGDB + "\\" + 'pySZbasemapnewSZ84' # inputFeatures = arcpy.GetParameterAsText(0) # outputWGS84 = arcpy.GetParameterAsText(1) # output54114 = arcpy.GetParameterAsText(2) Web_Mercator = r"PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]" Beijing_1954_114 = r"PROJCS['Beijing_1954_3_Degree_GK_CM_114E',GEOGCS['GCS_Beijing_1954',DATUM['D_Beijing_1954',SPHEROID['Krasovsky_1940',6378245.0,298.3]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',114.0],PARAMETER['Scale_Factor',1.0],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]" arcpy.env.overwriteOutput = True arcpy.env.qualifiedFieldNames = "UNQUALIFIED" try: arcpy.AddMessage("Start!") arcpy.WarpFromFile_management(inputFeatures,output54114,inputLinkFeatures,'POLYORDER1') arcpy.AddMessage("WarpFromFile_management!") arcpy.ProjectRaster_management(output54114, outputWGS84, Web_Mercator, geographic_transform="54to84") arcpy.AddMessage("ProjectRaster_management!") except arcpy.ExecuteError: errorMsgs = arcpy.GetMessages(2) arcpy.AddError(str(errorMsgs)) arcpy.AddMessage("Failed!") pass
if "HaritaPX3=" in part: a12= part.split('=')[1] if "RasterPY4=" in part: a13= part.split('=')[1] if "RasterPX4=" in part: a14= part.split('=')[1] if "HaritaPY4=" in part: a15= part.split('=')[1] if "HaritaPX4=" in part: a16= part.split('=')[1] dosya1.write(a1+","+a2+","+a3+","+a4+"\n"+a5+","+a6+","+a7+","+a8+"\n"+a9+","+a10+","+a11+","+a12+"\n"+a13+","+a14+","+a15+","+a16+"\n") dosya1.close() if not arcpy.Exists(exportname): dosya=workspace1+"\\"+rstname[xox] arcpy.AddMessage("\nÇalýþýlan Dosya " + str(dosya)) arcpy.WarpFromFile_management(dosya,exportname,dreadi,"POLYORDER1","NEAREST") arcpy.DefineProjection_management(exportname,prj) if not arcpy.Exists(exportname1): dosya1=workspace1+"\\DRE\\"+rstname[xox] arcpy.AddMessage("\nÇalýþýlan Dosya " + str(dosya1)) arcpy.WarpFromFile_management(dosya1,exportname1,don,"POLYORDER1","NEAREST") arcpy.DefineProjection_management(exportname1,prj) except: arcpy.AddError("\nHata Hesaplamalarda" + arcpy.GetMessages(2)) raise Exception except: arcpy.AddError("\nError running script") raise Exception
#!usr/bin/python import arcpy import sys import logging # staticGDB = r'./static.gdb' # saveToGDB = r'./data.gdb' # inputFeatures = staticGDB + "\\" + 'SZbasemap84' # inputLinkFeatures = staticGDB + "\\" + 'Link54114toSZ' # outputFeatures = saveToGDB + "\\" + 'SZbasemap54114' inputFeatures = arcpy.GetParameterAsText(0) outputFeatures = arcpy.GetParameterAsText(1) Web_Mercator = r"PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]" Beijing_1954_114 = r"PROJCS['Beijing_1954_3_Degree_GK_CM_114E',GEOGCS['GCS_Beijing_1954',DATUM['D_Beijing_1954',SPHEROID['Krasovsky_1940',6378245.0,298.3]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Gauss_Kruger'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',114.0],PARAMETER['Scale_Factor',1.0],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]" arcpy.env.overwriteOutput = True arcpy.env.qualifiedFieldNames = "UNQUALIFIED" try: arcpy.AddMessage("Start!") arcpy.ProjectRaster_management(inputFeatures, "in_memory"+ "\\" + 'temp', Beijing_1954_114,geographic_transform="84to54") arcpy.AddMessage("ProjectRaster_management!") arcpy.WarpFromFile_management( "in_memory"+ "\\" + 'temp',outputFeatures,'./54114tonewsz.txt','POLYORDER1') arcpy.AddMessage("WarpFromFile_management!") except arcpy.ExecuteError: errorMsgs = arcpy.GetMessages(2) arcpy.AddError(str(errorMsgs)) arcpy.AddMessage("Failed!") pass