Failed to execute (RastertoPolygon) Syntax error at or near symbol SPACE

4853
3
Jump to solution
05-21-2015 03:30 AM
RobertBeno
New Contributor

I'm converting series of raster to polygon using RastertoPolygon in arcpy.

#import the module
import arcpy
from arcpy.sa import *
from arcpy import env
arcpy
.CheckOutExtension("Spatial")
env
.overwriteOutput = True

#set the workspace
env
.workspace = r"C:\thesis\for sampling\sampling_outputs\raster_per_biogeoregion"

#Get a list of rasters and convert to shapefile
for raster in arcpy.ListRasters("*Luzon_*.tif", "TIF"😞
  
print raster #check the presence of rasters
  arcpy
.RasterToPolygon_conversion(raster, raster.replace("tif", "shp"), "NO_SIMPLIFY")
print "Finish converting all the rasters to polygon"

After several checks on the syntax, formatting, I've always been stuck with this error:

Traceback (most recent call last😞
File "C:\Users\brentiebark\Dropbox\Python Scripts and mxds\batch_convert_raster_to_polygon_simple.py", line 14, in <module>
arcpy
.RasterToPolygon_conversion(raster, raster.replace("tif", "shp"), "NO_SIMPLIFY")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\conversion.py", line 178, in RasterToPolygon
raise e
ExecuteError: ERROR 010328: Syntax error at or near symbol SPACE.
ERROR
010267: Syntax error in parsing grid expression.
Failed to execute (RasterToPolygon).

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Robert Beno ,

Neil Ayres  suggestion might be right. Using spaces and special characters in paths might cause problems, especially when you use rasters.

When you post code, could you please use syntax highlighting for your code (see: Posting Code blocks in the new GeoNet ). If I copy your code and paste it into PyScripter it points out an error on line 14 where you are missing a space to indent the line and align the code with line 13.

Other observations:

  • you import the sa module, but you don't use it
  • you check out a spatial analyst extension but you don't use it
  • if the extension tif of a raster would be TIF, it will fail

View solution in original post

3 Replies
NeilAyres
MVP Alum

Just a guess, can you remove spaces from your directory path and try again.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Robert Beno ,

Neil Ayres  suggestion might be right. Using spaces and special characters in paths might cause problems, especially when you use rasters.

When you post code, could you please use syntax highlighting for your code (see: Posting Code blocks in the new GeoNet ). If I copy your code and paste it into PyScripter it points out an error on line 14 where you are missing a space to indent the line and align the code with line 13.

Other observations:

  • you import the sa module, but you don't use it
  • you check out a spatial analyst extension but you don't use it
  • if the extension tif of a raster would be TIF, it will fail
SepheFox
Frequent Contributor

Yes, it looks to me like line 14 is not indented properly. It should be consistent with the indenting for the print line above it.