0

I am trying to convert multiple raster (name of raste: 01_sr, 002_sr....012_sr) to vector through loop function and output of vestor name wil same as of input. but loop function is not working. can anyone guide me on this subject, how to fix this error?

Error Massage: 
Message File Name   Line    Position    
Traceback               
    <module>    <module1>   15      
AttributeError: 'module' object has no attribute 'RasterToPoint_Conversion'             

Code:

import arcpy, os
from arcpy import env
arcpy.env.overwriteOutput = True
env.workspace = "D:\SOLAR-RADIATION-NOAA"
outpoint = r"D:\SOLAR-RADIATION-NOAA"
field = "VALUE"
Rasters = arcpy.ListRasters ()
for inRaster in Rasters:

     outpoint1 = r"D:\SOLAR-RADIATION-NOAA\\"+ "inRaster"

     arcpy.RasterToPoint_Conversion(inRaster, outpoint1, field)

Updated code, still error exist

import arcpy, os
from arcpy.sa import *
from arcpy import env
arcpy.env.overwriteOutput = True
env.workspace = "D:\SOLAR-RADIATION-NOAA"
outpoint = r"D:\SOLAR-RADIATION-NOAA"
field = "VALUE"
Rasters = arcpy.ListRasters ()
for inRaster in Rasters:

     outpoint1 = r"outpoint"+ "inRaster"

     arcpy.RasterToPoint_Conversion(inRaster1, outpoint, field)

Edited Code , Error still not solved

import arcpy, os
from arcpy.sa import *
from arcpy import env
arcpy.env.overwriteOutput = True
env.workspace = "D:\SOLAR-RADIATION-NOAA"
outpoint = r"D:\SOLAR-RADIATION-NOAA"
field = "VALUE"
Rasters = arcpy.ListRasters ()
for inRaster in Rasters:

     outpoint1 = outpoint+ inRaster
     arcpy.AddMessage(inRaster)

     arcpy.RasterToPoint_Conversion(inRaster, outpoint1, field)

1 Answer 1

2

Python is case sensitive, therefore, RasterToPoint_Conversion needs to be replaced with RasterToPoint_conversion

Your other problem is that you are trying to append the raster name with an extension to the output path. I would recommend becoming familiar with path manipulation using os.path.join(). In this example, I isolate (split) the raster iterable name from the extension using ras.split(".")[0].

import arcpy, os
from arcpy.sa import *

arcpy.env.overwriteOutput = True

inws = r"D:\SOLAR-RADIATION-NOAA"
outws = r"D:\SOLAR-RADIATION-NOAA\output_workspace" # Note the new output directory here

arcpy.env.workspace = inws
rasters = arcpy.ListRasters()

for ras in rasters:
     outpoint = os.path.join(outws, ras.split(".")[0] + ".shp")
     arcpy.RasterToPoint_Conversion(ras, outpoint, "VALUE")
9
  • Thank you. I ran the code suggested by you. But i am getting the following error massage Message File Name Line Position Traceback <module> <module2> 14 AttributeError: 'module' object has no attribute 'RasterToPoint_Conversion Commented Aug 27, 2016 at 19:09
  • I've updated the post to include the problem. Essentially, Python is case sensitive and the RasterToPoint_Conversion function needs to be converted to RasterToPoint_conversion. Commented Aug 27, 2016 at 19:26
  • Thank you very much @Aaron Code now successfully running. Commented Aug 27, 2016 at 19:36
  • I have one more problem regarding name of output during conversion of NetCDF to raster, which code now i am using that giving the same output name as input , but i want to write output name like 001_sr, 002_sr..012_sr. Once i upload that issue but not received any suggestion yet. Can i upload it once again now ?? Commented Aug 27, 2016 at 19:40
  • 1
    You can start a counter to do naming like that. Before the for loop, add counter = 1. At the bottom of the for loop add counter += 1. Then simply add a variable in your for loop like: name = "00%_sr.tif" % counter. Insert that variable into your output path like so: os.path.join(outws, name). Commented Aug 27, 2016 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.