+ Reply to Thread
Results 1 to 19 of 19

Thread: Raster to polygon script loop failing!! error 99999!

Hybrid View

  1. #1
    Alice Duff
    Join Date
    Dec 2010
    Posts
    32
    Points
    0
    Answers Provided
    0


    0

    Unhappy Raster to polygon script loop failing!! error 99999!

    Hello!

    I am have already posted this in the general forum but i managed to solve that issue and now i have a new one!

    I keep getting an error 99999 error message at line 37!
    ( gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features, "SIMPLIFY", "VALUE") )
    I am trying to make a script which selects every .png file in a folder beginning with the letters "LG". I then want the scipt create a shapefile, replacing the "LG" with "SH", and then i want the script to buffer that shapefile and rename the buffer with the first 2 letters being "SB"!

    Can anyone see why this isnt working? I am very, very new to this and have been staring at this script pulling out my hair for days!!

    Here is the script:

    Code:
    # ---------------------------------------------------------------------------
    # RASTER2POLYGON.py
    # Created on: Wed Dec 01 2010 12:20:48 PM
    #   (generated by ArcGIS/ModelBuilder)
    # Usage: RASTER2POLYGON <INPUT_RASTER> <Output_polygon_features> <Raster_Buffer_shp>
    # ---------------------------------------------------------------------------
    
    # Import system modules
    import sys, string, os, arcgisscripting
    
    # Create the Geoprocessor object
    gp = arcgisscripting.create()
    
    # Load required toolboxes...
    gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
    gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
    
    # Script arguments...
    
    folder = "D:\\J04-0083\\IMAGEFILES"
    for root, dirs, filenames in os.walk(folder): # returms root, dirs, and files
        for filename in filenames:
            filename_split = os.path.splitext(filename) # filename and extensionname (extension in [1])
            filename_zero = filename_split[0]
    
            try:
                first_2_letters = filename_zero[0] + filename_zero[1]
            except:
                first_2_letters = "XX"
    
            if first_2_letters == "LG":
                Output_polygon_features = "D:\\J04-0083\\ShapeFiles.gdb\\" + "SH_" + filename + ".shp"
    
                # Process: Raster to Polygon...
    
                INPUT_RASTER = os.path.join(root + "\\" + filename_zero + ".png")
                gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features, "SIMPLIFY", "VALUE") 
    
                Distance__value_or_field_ = "5 Meters"
                Raster_Buffer_shp = "SB_" + filename + ".shp"
    
                # Process: Buffer...
                gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE", "")

  2. #2
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,727
    Points
    595
    Answers Provided
    65


    0

    Default Re: Raster to polygon script loop failing!! error 99999!

    Alice,

    Guess no one is going to answer you. So here is my offering.

    1) if you are on ArcGIS 9.3 (you're not on 9.2 are you?) you should create the Geoprocessor object with the 9.3 enhancements.
    gp = arcgisscripting.create(9.3)
    At ArcGIS 10 you can keep the (9.3) arcgisscripting syntax or shift to the more complete ArcPy Site Library.


    2) You don't need to add the ArcToolbox code--those functions are included when you create the Geoprocessor in your Python script. And would cause problems if you were to add the script into a custom toolbox.

    3) Working with the ShapeFiles.gdb File Geodatabase, you either need to have created it outside the script or create it when opening the script with:
    gp.CreateFileGDB ("D:\\J04-0083", "ShapeFiles.gdb")
    4) As scripted the result of the gp.RasterToPolygon is being output as ESRI Feature Classes within the File Geodatabase. But, you're putting your results into a file geodatabase "D:\\J04-0083\\ShapeFiles.gdb" and trying to name them .shp--that doesn't make them shape files. Rather, using the extension actually causes the gp script to throw an error. In your script, just drop the .shp and they'll be properly created as Polygon Feature Class in the geodatabase.

    5) You went the other way with the Buffer_analysis. Output from that was dropping to the file system as Shape files in the D:\\J04-0083 folder. It would have been more consistent to keep both the geoprocessing polygon outputs together in the same format.

    Again, I would drop the .shp extension, and direct the output into the file geodatabase--i.e., change the output path to D:\\J04-0083\\ShapeFiles.gdb.
    Raster_Buffer_shp = "D:/J04-0083/ShapeFiles.gdb/" + "SB_" + filename_zero
    6) Finally, the problem with scripting this way is that you will end up with output from each script run in the working directory. I think the reason you were getting the 99999 errors is probably because you had pieces left over from prior run that had name conflicts. You have to clear things out at each script restart, i.e. empty the working directory, and empty/delete the File Geodatabase.

    Do that and you'll reach the more useful ExecuteErrors.

    7) when you are done creating your buffers, work with them in the File Geodatabase. Or, you can export them to Shapefile if you need that format for some other application.

    Here is your code cleaned up...I find forward slashes more readable than double backslashes, Python keeps it all straight. Also, if your PNG rasters have some projection details you may need world files for them to end up with usable results. I threw together some simple PNGs to test with, so your buffer value of "5 Meters" is set to "5" default pixels.

    Code:
    # ---------------------------------------------------------------------------
    # RASTER2POLYGON.py
    # Created on: Wed Dec 01 2010 12:20:48 PM
    #   (generated by ArcGIS/ModelBuilder)
    # Usage: RASTER2POLYGON <INPUT_RASTER> <Output_polygon_features> <Raster_Buffer_shp>
    # ---------------------------------------------------------------------------
    
    # Import system modules
    import sys, string, os, arcgisscripting
    
    # Create the Geoprocessor object
    gp = arcgisscripting.create(9.3)
    
    # Load required toolboxes...
    #gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
    #gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
    
    # Script arguments...
    
    gp.workspace = "D:/J04-0083"
    
    gp.CreateFileGDB ("D:/J04-0083", "ShapeFiles.gdb")
    
    folder = "D:/J04-0083/IMAGEFILES"
    for root, dirs, filenames in os.walk(folder): # returms root, dirs, and files
        for filename in filenames:
            filename_split = os.path.splitext(filename) # filename and extensionname (extension in [1])
            filename_zero = filename_split[0]
    
            try:
                first_2_letters = filename_zero[0] + filename_zero[1]
            except:
                first_2_letters = "XX"
    
            if first_2_letters == "LG":
                Output_polygon_features = "D:/J04-0083/ShapeFiles.gdb/" + "SH_" + filename_zero
                # Process: Raster to Polygon...
    
                INPUT_RASTER = os.path.join(root + "/" + filename)
                gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features) 
    
                Distance__value_or_field_ = "5"
                Raster_Buffer_shp = "D:/J04-0083/ShapeFiles.gdb/" + "SB_" + filename_zero
    
                # Process: Buffer...
                gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE")
    Post back if you are still stuck.

    Stuart
    Last edited by vsfoote; 12-08-2010 at 06:42 PM. Reason: para 6) cleanup between restarts, handling of File Geodatabase -- empty/delete, rather than just emptying

    If a post is helpful, or answers your question, or simply annoys you because it is WRONG please use the voting tools on the right side to help identify quality content on the Forum.

    Systems Analyst - Geological Sciences
    The University of Texas at San Antonio
    Classroom & Research support
    Adobe, AutoDesk, ESRI, ERDAS, ESI, Exelis Visual, IHS, Mathworks, Oracle, SAS Inst, Schlumberger, Seismic Micro-Technology, Trimble, Wolfram

  3. #3
    Jeff Lee
    Join Date
    Apr 2010
    Posts
    52
    Points
    2
    Answers Provided
    0


    0

    Default Re: Raster to polygon script loop failing!! error 99999!

    If I may add my two cents, it may not be good practice to include hyphen's in directory path (i.e. D:\\J04-0083\\IMAGEFILES) when working with the grid module. A lot of problems can be avoided by eliminating spaces and unusual characters in the directory path.

    http://webhelp.esri.com/arcgisdeskto...output_rasters
    Jeff Lee
    GIS / Data Specialist
    Halton-Hamilton Source Water Protection
    Campbellville, ON
    Canada

    ArcGIS 9.3
    Windows XP Pro

  4. #4
    Alice Duff
    Join Date
    Dec 2010
    Posts
    32
    Points
    0
    Answers Provided
    0


    0

    Smile Re: Raster to polygon script loop failing!! error 99999!

    Thank you so much for your help!

    When i first ran it i got a different error but i removed the "-" from the workspace file name and that error was no longer an issue!

    ..however..

    Now i get a new error which states:

    "error 00860 input raster is not the type of composite geodataset, or does not exist"

    But then i ran raster to polygon manually for the first LG file in the image files folder - which i assume would be the first one the script would process, and it worked perfectly!! The script gets as far as greating the geodatabase but that is it (error on line 40! gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features))

    Im so sorry to take up so much of your time! Thank you so much for debugging my script!!!!

  5. #5
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,727
    Points
    595
    Answers Provided
    65


    0

    Default Re: Raster to polygon script loop failing!! error 99999!

    Alice,

    OK, so this was totally MY fault.

    What did I suggest changing in handling the file name when selecting the PNG images out of the IMAGES folder?

    See it... on line 39? OK, and think what happens if there are any files that are not Raster images, like a .PGW world file, or meta data? You'd be trying to pass them in as rasters, but they may not be.

    So to fix it... could simply revert to your original .PNG image selection logic.

    Change line #39
    Code:
                INPUT_RASTER = os.path.join(root + "/" + filename)
    to read
    Code:
                INPUT_RASTER = os.path.join(root + "/" + filename_zero + ".png")
    
    or even hardcode the path as with the earlier Output_Polygon_features assignment
    
                INPUT_RASTER = "D:/J04-0083/IMAGEFILES/" + filename_zero + ".png"
    And see if that was the problem.

    Also, as was suggested by celenius over on the GIS Stackexchange thread, you could insert a print (<YourVariableName>) statement just after the selection to help debug the script. Comment it out when the logic is correct.

    And thinking about it, maybe this is not robust enough. As it is, you'll need to be sure that only the .PNG image files start with LG--and you won't be able to have the matchiing LG<imagefileName>.PWG colocated in the folder that may be needed for the geoprocessing.

    Maybe since you have the file extension available in filename_split[1] from the os.path.splitext, you could make use of that in another "if ==" to ONLY buffer specific image file types, e.g. PNG, png, JPG, jpeg etc. in the IMAGES folder when running through it.

    Stuart
    Last edited by vsfoote; 12-09-2010 at 06:37 AM.

    If a post is helpful, or answers your question, or simply annoys you because it is WRONG please use the voting tools on the right side to help identify quality content on the Forum.

    Systems Analyst - Geological Sciences
    The University of Texas at San Antonio
    Classroom & Research support
    Adobe, AutoDesk, ESRI, ERDAS, ESI, Exelis Visual, IHS, Mathworks, Oracle, SAS Inst, Schlumberger, Seismic Micro-Technology, Trimble, Wolfram

  6. #6
    Alice Duff
    Join Date
    Dec 2010
    Posts
    32
    Points
    0
    Answers Provided
    0


    0

    Lightbulb Re: Raster to polygon script loop failing!! error 99999!

    success!!! I have successfully made a shapefile and a buffer!! But there is a problem in that at line 47

    Code:
      gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE")
    I get an error saying the the file i am trying to create already exists. This makes me think that something has gone wrong where the script doesnt know what it already has modified so it tried to make the same shapefile and buffer again but it cant because they already exist!!

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts