简体   繁体   中英

create variable 'workspace' not helping while using arcpy module in python (ArcGIS 10.5.1)

I am using python to project a dem file. The code I used is attached below:

import arcpy
arcpy.env.overwriteOutput = True

# Script arguments
Input_dem = "E:\\OneDrive\\Academic\\PhD\\Philemon\\phase_3_(model)\\dem_raw\\Mago_raw.tif"
Workspace = "E:\\OneDrive\\Academic\\PhD\\Philemon\\phase_3_(model)\\useful_data"
Output_Coordinate_System = "PROJCS['WGS_1984_UTM_Zone_46N',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',93.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]" # provide a default value if unspecified

# Local variables:
reprojected = "%Workspace%\\reprojected"

# Process: Project Raster
arcpy.ProjectRaster_management(Input_dem, reprojected, Output_Coordinate_System, "NEAREST", "87.6969856825158 87.6969856825151", "", "", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")

The above code does the job of reprojecting the dem, but is not being stored in the assigned workspace. A little search with my novice search showed that the files are stored in the 'temp' folder under my username (windows).

using arcpy.env.workspace gets the job done, but I want to how to get the above code working. Thank you in advance.

使用arcpy.env.workspace = "E:\\OneDrive\\Academic\\PhD\\Philemon\\phase_3_(model)\\useful_data"而不是裸workspace变量

Is %Workspace% in

reprojected = "%Workspace%\\reprojected"

a valid Windows environment variable on your system?


You don't necessary need to set arcpy.env.workspace . You should be able to do this:

reprojected = Workspace + "\\reprojected"  # Python 2.7 / ArcMap

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM