创建变量' workspace'在Python中使用Arcpy模块时无助(ArcGIS 10.5.1)
我正在使用Python投影DEM文件。我使用的代码附加了下面:
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]]")
以上代码可以重新投影DEM,但没有存储在分配的工作空间中。对我的新手搜索进行了一些搜索,显示文件存储在我的用户名(Windows)下的“临时”文件夹中。
使用arcpy.env.workspace
完成工作,但我想如何使上述代码工作。先感谢您。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
arcpy.env.workspace =“ e:\\ oneedrive \\ accital \\ phd \\ philemon \\ apease_3_(型号)\\ sime_data”
>而不是裸体
工作区
变量Use
arcpy.env.workspace = "E:\\OneDrive\\Academic\\PhD\\Philemon\\phase_3_(model)\\useful_data"
instead of naked
workspace
variable是
%workspace%
在有效在您的系统上?
您无需设置
arcpy.env.workspace
。您应该能够做到这一点:Is
%Workspace%
ina valid Windows environment variable on your system?
You don't necessary need to set
arcpy.env.workspace
. You should be able to do this: