Error in Iterate Raster - Model Builder

2611
8
01-04-2017 06:48 AM
ThallitaOliveira
New Contributor

Hello everyone.

I'm trying to run a model in Model Builder, but without sucess. I have two landscapes rasters (p1 and p2 - as a test, because in fact I have 400 files) to be iterated, which I want the model completely run over them. The model has many steps, and this error appears on the second one.

The first step is [(1) Inteiro]: convert raster (p1 r p2) to integer (pintft).

*The input and output files path are: 

Input: p1.img 

Output: C:\Redes\FT\pintft_%Name%

The second step is [(2) Raster to Polygon]: convert raster (pintft) to polygon (ppolyft).

*The input and output files path are: 

Input: pintft

Output: C:\Redes\FT\ppoly_ft_%Name%.shp


Executing ((1) Inteiro): Int C:\Redes\FT\p1.img C:\Redes\FT\pintft_p1.img
Executing ((2) Raster to Polygon): RasterToPolygon C:\Redes\FT\pintft_p1.img C:\Redes\FT\ppoly_ft_p1.img.shp NO_SIMPLIFY Value
ERROR 010157: Unable to open feature class C:\Redes\FT\ppoly_ft_p1.img.
Failed to execute ((2) Raster to Polygon).

The error affirm that was unable to open feature class C:\Redes\FT\ppoly_ft_p1.img. But, really, there isn't no raster named "ppoly_ft_p1.img", once the raster input is the "pintft". Someone can highlight to me how can I solve this problem? 

I'm doubt about the inline variable substitution too, if the file path are correct.

ps.: The circle FT are the workspace.

Thanks.

0 Kudos
8 Replies
XanderBakker
Esri Esteemed Contributor

It appears that is is trying to create a featureclass (shapefile) with the name C:\Redes\FT\ppoly_ft_p1.img.shp. The name includes two extensions which could work (check if the file was created with that name!). However, when opening the resulting shapefile it throws "ERROR 010157: Unable to open feature class C:\Redes\FT\ppoly_ft_p1.img". Probably due to the extension included in the name of the shapefile. Is it possible to truncate the extension of the .img file before supplying it to the output name for the shapefile?

Honestly, I would have switched to Python for complexer models, which would make ik a lot easier to detect (and avoid) errors. 

ThallitaOliveira
New Contributor

Hi Xander.

I agree that the problem can be about the file name. I don't know how to truncate the extension of the .img file. Can you explain me, please? Could be a possibility.

I don't have experience in Python language, just in R language. The construction of the model in Model Builder was much easier, but the iteration is being complicated...

Best regards.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Since you have experience in R, I would suggest to invest in learning Python. You can gain a lot of productivity with learning Python and there is even a bridge to connect Python to R in ArcGIS. 

Unfortunately, I do not have much experience with Model Builder. I normally use Python to automate my processes and especially when things get a little more complicated it is easier to use Python for this purpose, but it will require to learn Python. I tried to search for an option to split the extension from a name in Model Builder and did not found it (it may exist though). So I tried to do something similar, iterate raster (type Erdas Imagine) in a folder and do something with the name to create an output. 

What I saw in your model is that you are not using the Name as precondition for the next step (in my case Raster to Polygon). When you do you can use it in the definition of the output name for the featureclass. However, this will include the extension ".img". To avoid this I created a simple Python script:

def main():
    import os, arcpy
    name_ext = arcpy.GetParameterAsText(0)
    name, ext = os.path.splitext(name_ext)
    arcpy.AddMessage("Name: '{0}'".format(name))
    arcpy.SetParameterAsText(1, name)

if __name__ == '__main__':
    main()

... that will read a string containing the extension and return the name without extension. 

Using this script I added the script in the toolbox to create a new "scripting tool":

The parameters are defined as follows:

Both input and output are are of type String and for the output the direction is defined as "Output". 

I can drag and drop the script tool to my model and connect it in the model:

Please note that the output featureclass name refers to the %NameOut% variable.

This is an option to solve the problem, but I would strongly suggest to look into learning Python. For someone that already knows R, this will not pose a mayor challenge, since Python is one of the easiest programming languages there is.

ThallitaOliveira
New Contributor

Hi Xander.

Thanks a lot for your attention and avaiability to think about a solution. From your answer, I continue looking for some tool to do what you propose and I found! The tool is Parse Path, which make that from a step to another in the model, the output file name have just the variable name and not their extension (using the option "name" in the field "Path type", and put the raster [(1) Inteiro] as inputs and the "Value" [Parse Path output] as a precondition of the Int function). That is, this problem is solved. But now get up a new issue. In the five step [(5) Reclassify cost surface] the model throw a error: 

Executing ((5) Reclassify Cost Surface): Reclassify C:\FT\1p1 VALUE "1 30;2 30;3 5;4 1000000;5 20;6 1;7 1000000;8 1000000;9 NODATA;10 50;11 25;12 10;13 5;14 50;15 1000000;26 NODATA;99 NODATA;128 NODATA" C:\FT\5p1 DATA
Start Time: Sat Jan 07 11:13:41 2017
ERROR 999999: Error executing function.
The table name is invalid.
Failed to execute ((5) Reclassify Cost Surface).

Trying to simplify, I changed the path and files names, and now are:

Input: p1.img or p2.img 

Workspace: C:\FT\

Steps: 1, 2, 3, 4, 5, and so on

Inline variable substitution: %value%, which make reference to the original input file name of that iteration

 

Do you know how I fix it?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Looking at the error message and the missing table error, I notice that your input raster is defined as "C:\FT\1p1". When you don't specify the extension it will assume that the raster is an Esri grid called "1p1" in the folder "C:\FT". An Esri grid raster should not start with a number. Also you classify the raster in a way that is done with integer raster (not floating). Is it really an integer raster?

The output raster is defined as "C:\FT\5p1". Again an Esri grid raster with a non valid name (starting with a number). 

I also notice that in your model you have several steps to add geometry attributes to the featureclass. If you do it once before the select, you wont have to do it multiple times, and, even better, if you write to a featureclass inside a FileGeodatabase these fields will be created automatically.

ThallitaOliveira
New Contributor

Hi Xandre.

Thank you again for the help, its are beign precious. I change the inputs names, substituing numbers for letters, and it works! No errors anymore. The model are running perfectly. I'm very happy. But how life is not a bed of roses, I have a new issue. I have 2 files originally (p1.img and p2.img), upon which I want that all model steps run. There are numeric steps from a to p (a, b, c, ..., etc).  I tryed two iterators: multivalue and raster iterators. The first one return the outputs correctly, for which step, but just for the file p1.img, doesn't run for the file p2.img (first image). The second one generate a kind of loop, running repeatedly and cumulatively on files originating from the landscape p1.img (second image).

I need the model run all step, only once, for files p1 and p2.

Any idea?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Not sure why the first method wouldn't work, is there any (error) message for the second raster?

I assume that you create different output names for the results and have the overwrite output setting set to True to replace intermediate results. Is that correct?

For the second method, it seems that it iterates over all the rasters in a workspace. You could limit this by setting the Raster Format to IMG and the Wildcard to P*:

ThallitaOliveira
New Contributor

Answer your questions: 

- No, no error appears in relation to the p2 file. In fact, the steps model keeps running repeatedly, generating only the results in relation to the p1 file (and, I believe, replacing the already generated outputs), without finish.

- Yes, I  create different output names for the results, that are: a%value%, b%value%, c%value%, d%value%, e%value%, and so on (until "p").

- I'm not sure about the overwrite output setting, but I check the first option of the image below (is this the setting are you talking about?) and ran the model again, without sucess.

- Actually, I don't mark none file as intermediate data, that is, all the output are to be generated by the model.

- I've already done what you proposed about setting the raster format to IMG and the wildcard to p*: no sucess too.

0 Kudos