1

I am running this script to perform simple raster algebra on the pycharm interpretor...

    import arcpy
arcpy.env.overwriteOutput = True
from arcpy.sa import *

# Specify the input raster
inRaster = "C:/user/dark7/desktop/lesson1/USGS_NED_one_meter_x47y367_CA_SanDiegoQL2_2014_IMG_2016.img"
cutoffElevation = 200

# Check out the Spatial Analyst extension
arcpy.CheckOutExtension("Spatial")

# Make a map algebra expression and save the resulting raster
outRaster = Raster(inRaster) > cutoffElevation
outRaster.save("C:/user/dark7/desktop/lesson1/SD_hiev")

# Check in the Spatial Analyst extension
arcpy.CheckInExtension("Spatial")

I receive this error...

Traceback (most recent call last):
  File "C:/Users/dark7/PycharmProjects/untitled/practice script.py", line 16, in <module>
    outRaster = Raster(inRaster) > cutoffElevation
RuntimeError: ERROR 000732: Input Raster: Dataset C:/user/dark7/desktop/lesson1/USGS_NED_one_meter_x47y367_CA_SanDiegoQL2_2014_IMG_2016.img does not exist or is not supported

Process finished with exit code 1

I have already checked to make sure that the spatial analyst extension is enabled in my copy of arc and the data I want to use is not opened in any applications when I ran the script. Does anyone know how to fix this problem? I looked into other peoples questions and modified a few things but I keep receiving the error.

closed as off-topic by user2856, PolyGeo Oct 3 '18 at 9:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – user2856, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What happens if you put in if arcpy.Exists(inRaster): arcpy.AddMessage('Raster exists')? The raster might be broken, can you open the raster in ArcCatalog or ArcMap? I think you need to put that expression into a Con statement: outRaster = arcpy.sa.Con(Raster(inRaster) > cutoffElevation,1,0) which will give you a binary raster which is 1 where inRaster greater than 200 and 0 where inRaster is less than or equal to 200. Are you meaning to save as type GRID in your save statement? Omitting the extension saves as a GRID which works but is a little antiquated. – Michael Stimson Oct 3 '18 at 1:38
  • 1
    I could open the raster in both ArcCatalog and ArcMap first thing I checked! Thanks for the tip with the con statement I'll use that again! But it was a really simple and stupid error. I typed User instead of Users in my path. – Liam Bean Oct 3 '18 at 2:42
  • I typed User instead of Users in the pathnames. – Liam Bean Oct 3 '18 at 2:42
0

There are a couple of methods in the os lib that might help, specifically os.path.join and os.environ.get. Considering you're using Windows you can get the environment variable USERPROFILE which is set by Windows (and your system administrator) so is fairly reliable:

import os
inRaster = os.path.join(os.environ.get('USERPROFILE'),"desktop/lesson1/USGS_NED_one_meter_x47y367_CA_SanDiegoQL2_2014_IMG_2016.img")

In this case it would help to get the location of your user profile from the operating system, thus avoiding the misspelling, though it's probably not a good idea to get into the practice of storing GIS data on your desktop.

Using os.path.join to concatenate fragments of paths avoids common problems with path manipulation so it's a good practice to get used to using this method while you're learning; there are other helpful os methods that will potentially save some pain later on.

Not the answer you're looking for? Browse other questions tagged or ask your own question.