0

I am running a lengthy script to post-process raster channel paths into polylines so I can measure their length using Add Geometry. Script runs well until I go to convert the rasters to lines using the Raster to Polyline tool in arcpy, shapefiles are output when the error is overwritten but attribute tables are empty and they can't be drawn in arcmap. Input Raster is integer type, data has coordinate system, channel paths are 1's and all other cells are nodata. Shapefiles are missing the optional .sbn and .sbx supporting files.

I have tried running the Raster To Polyline tool from within ArcMap and it works fine.

Workarounds accepted. Script is long so a snippet where failure occurs is below.

arcpy.env.workspace = CPC_rename  #sets workspace
CPC_lines = CPC_rename + '\\' + folder7  # sets output workspace
rasters = arcpy.ListRasters('*', 'TIF')  # Lists Rasters
for x in range(0, len(rasters)):  # set up a for loop
    linesOut = os.path.join(CPC_lines) + '\\' + rasters[x] + '.shp' # setup the output file   
    arcpy.SetSeverityLevel(0)  # override the 999999 error so it runs all the way through
    arcpy.RasterToPolyline_conversion(rasters[x], linesOut , "ZERO", 0, "NO_SIMPLIFY", "Value")  # apply the arcpy tool
    print 'something' # print something to confirm its running
3
  • Try using os.path.join for all paths. For example change CPC_lines = CPC_rename + '\\' + folder7 to os.path.join(CPC_rename, folder7). What gets printed out with print linesOut
    – Bera
    Commented Feb 13, 2020 at 7:38
  • 1
    what is rasters? It's being treated as a string on the linesOut line but then a raster on RasterToPolygon line... os.path.join joins the fragments together so assuming rasters are strings of the file names os.path.join(CPC_lines,rasters[x] + '.shp') might be more appropriate but shapefiles must not contain non alphanumeric characters except for the underscore, that sounds like what's going on here you're trying to create raster.tif.shp which causes the 999999 so perhaps os.path.join(CPC_lines,os.path.splitext(rasters[x])[0] + '.shp') to just use the name part of the TIFF file will help. Commented Feb 13, 2020 at 7:38
  • You're both spot on. Print linesOut was giving me a "raster.tif.shp", which I was having trouble cleaning up, but Michael's solution helped me do that. Include your solutions as an answer and I will happily upvote them and accept as answers.
    – Z Geo P
    Commented Feb 13, 2020 at 20:26

1 Answer 1

1

We cannot see what CPC_rename and folder7 are set to, and consequently it is possible that CPC_lines is an ill-formed or otherwise inappropriate workspace name.

I believe that I have often seen ERROR 999999 when the name of a workspace being written to is either ill-formed or otherwise inappropriate.

1
  • Folder names are all good. It was how I was dealing with the linesOut string. linesOut was outputting a "raster.tif.shp" which was causing the problem. os.path.join(CPC_lines,os.path.splitext(rasters[x])[0] + '.shp') solved the problem.
    – Z Geo P
    Commented Feb 13, 2020 at 20:29

Your Answer

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

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