+ Reply to Thread
Results 1 to 19 of 19

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

  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,731
    Points
    596
    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,731
    Points
    596
    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!!

  7. #7
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,731
    Points
    596
    Answers Provided
    65


    0

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

    Alice,

    Progress

    So, had you emptied and deleted the ShapeFiles.gdb FGDB--resetting prior to the run?

    Or, was the duplicate feature class name occurring during the same script run? If so, what exactly do you have in your IMAGES folder? Just the PNGs? Any chance the os.path.splitext(filename) is not making the filename unique, possibly extra periods in the image name? Maybe capture a screen shot of the directory and post it.

    Again, you may need to adjust the parsing logic to only attempt the RasterToPolygon on the .PNG by testing the file extension before passing through the filename_zero.

    And set a print(Output_polygon_features) statement to keep track on the console while running; or as bwreilly suggested on the GIS Stackexchange thread, run inside the debug module pdb.run() to step through. You should be able to see when the duplicate is occurring.

    And I'll split a hair here to say that if you are still using the File Geodatabase as the output container for your geoprocessing you are not creating Shapefiles rather they are Feature Classes. But get the script fully working before worrying about that distinction.

    Stuart
    Last edited by vsfoote; 12-10-2010 at 05:36 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

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


    0

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

    Thank you! Im not in the office again until monday so i will test it all then! Thank you again for your help!!! I will let you know what happens - im sure it is something with pathnames and where im saving everything! Screen shots to come!

  9. #9
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,731
    Points
    596
    Answers Provided
    65


    0

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

    Alice,

    OK, will look to continue with it Monday.

    And once you get it all worked out please consider posting the clean script up in code brackets for benefit of the next poor soul..

    Stuart

    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

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


    0

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

    Hello!! I checked all the filenames etc and they are all the same!

    Ive saved some print screen of the contents of the files and the error message i am getting and here is the code!

    Thank you again for being so helpful!

    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:/J040083"
    
    gp.CreateFileGDB ("D:/J040083", "ShapeFiles.gdb")
    
    folder = "D:/J040083/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:/J040083/ShapeFiles.gdb/" + "SH_" + filename_zero
                # Process: Raster to Polygon...
    
                INPUT_RASTER = os.path.join(root + "/" + filename_zero + ".png")
    
                gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features)
    
                Distance__value_or_field_ = "5"
                Raster_Buffer_shp = "D:/J040083/ShapeFiles.gdb/" + "SB_" + filename_zero
    
                # Process: Buffer...
                gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE")
    Attached Files

  11. #11
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,731
    Points
    596
    Answers Provided
    65


    0

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

    Alice,

    I read the errors and looked at the listing of the IMAGES folder, and can see there are no duplicate file names and no file types other than .PNG. Although, you may have some issue with splitting of the "LG_landelijk+hoogspanningsnet_Tennet+TSO+B.V._0000579962_10G179920.png" named image file.

    The only question that still comes to mind... are you working with an open ArcCatalog session while debugging, and are you backing out of the ShapFiles.gdb folder and deleting or renaming the geodatabase. I.e., starting fresh before attempting an additional run through the python script? If not, you should or you'll get errors similar to these.

    So, do that. and also insert these print statements

    print(INPUT_RASTER)
    print(Output_polygon_features)
    print(Raster_Buffer_shp)
    where they are declared in the script. They'll allow you to follow progress in the console as the script executes.

    Stuart

    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

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


    0

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

    Brilliant news! The script works now, the problem was that i was viewing the files in arc catalog, and outside of arccatalog there were other .aux and .xml files which were causing the error i think!!

    Here is the new improved script
    Code:
    #--------------------- IMPORT --------------------------------------------------
    import sys, string, os, arcgisscripting
    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")
    
    #--------------------- INPUT ---------------------------------------------------
    gp.workspace = "D:/J040083"
    gp.CreateFileGDB ("D:/J040083", "ShapeFiles.gdb")
    folder = "D:/J040083/IMAGEFILES"
    
    #--------------------- SCRIPT --------------------------------------------------
    gp.OverWriteOutput = 1 # overwrite existing files (1 = True, 0 = False)
    
    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]
            extension = str.upper(filename_split[1])
    
            try:
                first_2_letters = str.upper(filename_zero[0] + filename_zero[1])
            except:
                first_2_letters = "XX"
    
            if first_2_letters == "LG" and extension == ".PNG":
                Output_polygon_features = "D:/J040083/ShapeFiles.gdb/" + "SH_" + filename_zero
                print (Output_polygon_features)
                # Process: Raster to Polygon...
    
                INPUT_RASTER = os.path.join(root + "/" + filename_zero + ".png")
                print (INPUT_RASTER)
    
                gp.RasterToPolygon_conversion(INPUT_RASTER, Output_polygon_features)
    
                Distance__value_or_field_ = "5"
                Raster_Buffer_shp = "D:/J040083/ShapeFiles.gdb/" + "SB_" + filename_zero
                print (Raster_Buffer_shp)
    
                # Process: Buffer...
                gp.Buffer_analysis(Output_polygon_features, Raster_Buffer_shp, Distance__value_or_field_, "FULL", "ROUND", "NONE")

    and i did have a problem with the files with + in them, so i made a script to replace any +s with _s!

    Thank you soooo much for your help!

  13. #13
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,731
    Points
    596
    Answers Provided
    65


    0

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

    Alice,

    Good news

    So now make it pretty --

    1) as noted before these snippets come from saving the script out of the original model builder run and should be removed...
    # 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")
    2) using the overwrite is a good idea,
    gp.OverWriteOutput = 1 # overwrite existing files (1 = True, 0 = False)
    but I'm not certain of its behavior regards the preceding gp.CreateFileGDB ("D:/J040083", "ShapeFiles.gdb") will it clobber it or throw an error?

    3) to be more "Pythonic" the os.path.join syntax could be changed
    INPUT_RASTER = os.path.join(root, filename_zero + ".png")

    4) You're not working with Shapefiles, rather Polygon Feature Classes in a File Geodatabase. Since you kept the model builder naming outputs it might be better to instead rename the FGDB, i.e. BufferedFeatures.gdb or something more descriptive.

    5) your buffer is FULL, do you need LEFT (outside) or RIGHT (inside) the extracted polygon features (unfortunately only available if you are on an ArcInfo level Desktop license). It is also in pixels, 5 which with FULL is doubled to a width of 10 pixels. And to work in geospatial values you may need to treat the rasters as projected during the buffering--or could project the feature class at your next analysis step.

    6) the script is not especially robust as you've found. Probably need to handle more cases, e.g. files with extensions other than .PNG, or different raster types, as well as filename oddities--plus signs and periods being a problem for consistent results with Python os.path.splitext().

    7) finally, you'd indicated you wanted Shapefiles as the outcome. You don't have them yet but can easily convert with a loop through the FGDB using the FeatureClassToShapefile_conversion geoprocessing command.

    Otherwise congratulations! You can get on with your analysis and get to it all the faster on the next problem set.

    Stuart
    Last edited by vsfoote; 12-14-2010 at 06:20 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

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


    0

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

    Thank you!

    I have made some of the changes you suggested to make it look nice, and i am going to look into the feature class to shapefile conversion, and adding in the name change function into the script itself!

    I dont think overwrite is actually doing anything in the script because it still gives an error if i dont delete the shapefile.gdb, so i will remove it!

    I need the buffer to be by 5 meters either side (the .png files are pipelines, cables etc underground and need to be avoided by 5 meters either side for soil investigations!). Should i change the "5" to "5 meters", if this means 5 pixels - i assume thats not the same as 5 meters!

  15. #15
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,731
    Points
    596
    Answers Provided
    65


    0

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

    Alice,

    OK. Better role up your sleeves...

    So, we haven't discussed it but what is the source of your .PNG rasters? In any case, you'll have two choices on buffering them in a geospatial context within your GIS:
    1) spatially georeference the raster prior to extracting the polygon/polyline buffers as feature classs by including a .WLD, .PGW, or .pngw ESRI Grid "World file" for each raster. Once geospatialy registered you could specify a 5 meter buffer--it could be 1 pixel, 2 pixels, or even 10 pixels depending on the resolution of the raster. Each raster image will require its own unique world file. And you'll probably want to pick a "projection" with planar units in meters--like UTM. A big down side is that your Python script will need to be modified considerably to robustly include the world files, georegister the image and apply a projection/spatial reference to be used during the raster to polygon extraction.

    2) the second choice is to project the buffer feature classes, defining a projection, after they have been extracted from the raster. You'll need to establish a set of X,Y control points in a meter planar unit projection--again probably UTM, to overlay on each polygon as control for the projection. Project the points and apply the same to the buffer polygon. Do you have GPS points from your pipeline and utility data? Perhaps do the rastertopolygon buffer at .5 pixel. and then once projected, perform another buffer to be 5 meters.
    The first is the more traditional approach, and is MUCH simpler to implement--but you'll have to rework your Python script.

    Another suggestion would be to drop the direct RasterToPolygon based buffer geoprocessing and instead perform a RasterToPolyline feature extraction. And then buffer the polyline feature--your pipelines and other underground utilities. You'd still want to georeference and register the rasters into a planer unit projection--like UTM for accuracy of the buffer. And would need to establish "World file" details for each image, again what is the source of the PNGs--do they provide spatial reference of some sort?

    An alternative to geoprocessing from the PNG would be to convert each image to GeoTIFF with embeded spatial registration, the RasterToPolygon or even RasterToPolyline with subsequent buffering could consume it. Perhaps the latest FWTools GDAL build gdal_translate tool could be incorporated into an "os" call in the script, or done ahead of time. Maybe too much?

    Stuart
    Last edited by vsfoote; 12-15-2010 at 08:56 AM. Reason: gdal_translate not transform...

    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

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


    0

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

    wow!! I am not back in the office until the new year now - so i will look into all of this then and get back to you!! thank you sooo much for your help you have saved my life!!!

  17. #17
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,731
    Points
    596
    Answers Provided
    65


    0

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

    No worries, and good health for the new year...

    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

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


    0

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

    Stuart,

    merry christmas and happy new year!

    The problem i am facing is this: the .png files i have come with no other information. They are usually opened in a programme called "Klic", along with other data in .pdf format which the client needs. The client now wants these klic files (the .png files) to be imported into ArcMap where they need to be georeferenced. The only data i have for the .png files are in .xml files (i dont really grasp what these are to be honest!) But apparently they have co-ordinates in them, so I dont really have any concept of how long the pipelines are!!

    I had initially tried a rastertopolyline conversion - but with some of the files that didnt work, even manually! I think it is due to the fact that some .png files are funny shapes, or that they are counting the background as a part of the shape!

    How do i create a world file and attach it to the raster?

    I feel so guilty for taking up so much of your time!! If you ever have a problem i can help you with (probably not) i would do the same!!!

    Thank you!!!!

  19. #19
    V Stuart Foote

    Join Date
    Apr 2010
    Posts
    1,731
    Points
    596
    Answers Provided
    65


    0

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

    Alice,

    Welcome back, fun and happy holidays?

    So, before you can get back to scripting the creation of your buffers, you MUST correctly establish the projection and registration details for each PNG image you want to process.

    So, I'm guessing that your Klic application is the Arcadis Klic viewer and you are dealing with PNG derived from GBKN (Grootschalige Basiskaart Nederland) projected in Dutch RD--EPSG 28992 (worked in ArcGIS as RD New coordinate system) or from other European imagery in WGS84 GCS lat/long.

    In any case, the projection details you need are likely available as metadata contained in the XML and PDF files accompanying each image. The XML will be well structured and tagged, although probably not GeoXML. But you will need to study it along with any metadata in the PDF for each PNG image, and from the metadata determine where to position each image in real world coordinates. Fortunately, all the images will probably be in the same projection and the needed information will be encoded the same for all the file sets. You just have to figure out how. You may be given an upper left and lower right coordinate set, or an upper left--a pixel size--and a rotation, or even all four corners of the image.

    If you are allowed to post a sample of the XML and an excerpt from the PDF along with a PNG raster and we may be able to help. But you might post that as a new thread on the Imagery and Raster Data forum to get the right folks helping to tease out the georeference details.

    Then, once you assemble the registration data for the PNGs, you can either convert them to GeoTIFFs (with a GDAL script) or create an ESRI Grid World file for each.

    And finally, you can get back to the geoprocessing of a 5m buffer.

    You will have several options once you are able to access the georeferenced image with ArcGIS.

    And you can bring each into an ArcMap feature editing session and digitize a centerline of each pipeline. Or, you can return to your gp.RasterToPolygon_conversion(), or perhaps try the RasterToPolyline_conversion() tool. The key will be that by having georeference of each image, you'll then be able to work with accurate measurements in meters rather than just image pixels.

    One additional scripting option if you have ArcGIS 10 would be the new Image Classification tools for either unsupervised or supervised with training. A more sophisticated way to extract the pipeline detail out of the PNG raster and pass on for RasterToPolygon or RasterToPolyline conversion.

    If someone at the office has ERDAS or ENVI image analysis suite they really are better tools for doing the same feature extractions.

    Stuart
    Last edited by vsfoote; 01-05-2011 at 02:38 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

+ 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