-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.

bad_coder
  • 11,289
  • 20
  • 44
  • 72

2 Answers2

2

Use arcpy.env.workspace = "E:\\OneDrive\\Academic\\PhD\\Philemon\\phase_3_(model)\\useful_data" instead of naked workspacevariable

Abdeslem SMAHI
  • 453
  • 2
  • 12
  • I had actually extracted the script from a model made from modelbuilder in Arcmap. The model seems to be working fine and giving me the desired results with the 'workspace' variable. However when I export the model as script, it stops working as desired. But your solution seems to help as I mentioned before. Wanted to know if there is any thing I am missing because for which I am not able to get the above code working. – Nyigam Bole Jun 29 '22 at 10:44
0

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
Thomas
  • 8,357
  • 15
  • 45
  • 81