Select to view content in your preferred language

passing the output of a tool as input to another

3534
6
Jump to solution
12-15-2015 08:15 AM
KONPETROV
Frequent Contributor

Hello I have the following code (its a bit big but very simple), and the problem I am facing is that I cannot pass the raster rcls to the Create Spatially Balanced tool, unless I add it to Table of Contents (lines 32- 42). I am building a new tool, so I don't want to interrupt the proccess by adding something to the Talbe of Contents, cracking my tool to 2 tools. The "values" and "num_pnts" variable (line 13-14) show the number of points that will be created. Thanks in advance.

import arcpy
import os
from arcpy import env
from arcpy.sa import *


#workspace = arcpy.GetParameterAsText(0)
workspace = "C:/Results/ArcMap/Visibility/Calc_View/"


# arithmos simion kai viewsheds
#value = arcpy.GetParameterAsText(1)
values = 2
num_pnts = int(values)


#height_val = arcpy.GetParameterAsText(2)
height_val = 100
height = int(height_val)


#demodel = arcpy.GetParameterAsText(3)
#demMAXResult = arcpy.GetRasterProperties_management(demodel, "MAXIMUM")
#demMAXResult = arcpy.GetRasterProperties_management(demodel, "MINIMUM")
demMAXResult = arcpy.GetRasterProperties_management("C:/Results/ArcMap/Visibility/Calc_View/tin2ras3g_1", "MAXIMUM")
demMINResult = arcpy.GetRasterProperties_management("C:/Results/ArcMap/Visibility/Calc_View/tin2ras3g_1", "MINIMUM")
demMAX = demMAXResult.getOutput(0)
demMIN = demMINResult.getOutput(0)
LIMIT = float(demMAX) - height


# Reclassify
outReclass = Reclassify("tin2ras3g_1", "Value", RemapRange([[float(demMIN),LIMIT,1],[LIMIT,demMAX,0]]), "NODATA")
outReclass.save("C:/Results/ArcMap/Visibility/Calc_View/rcls")

n = 0
for i in range(num_pnts):
    n += 1
    # Spatially Balanced Points
    inRaster = "rcls"
    outPoints = "C:/Results/ArcMap/Visibility/Calc_View/point" + str(n)
    arcpy.CreateSpatiallyBalancedPoints_ga(inRaster, 1, outPoints)
0 Kudos
1 Solution

Accepted Solutions
KONPETROV
Frequent Contributor

Problem solved at line 40 at the variable inRaster, it must be imported the path of the reclassified raster like that:

inRaster = "C:/Results/ArcMap/Visibility/Calc_View/rcls"

I don't know why, it is the first time I am doing it, but only by that it works.

View solution in original post

6 Replies
Luke_Pinner
MVP Regular Contributor

The help (ArcGIS Help (10.2, 10.2.1, and 10.2.2) ) states the 1st parameter "in_probability_raster" should be a Raster Layer or a Mosaic Layer, not a Raster Dataset.

When you add the Raster Dataset to the TOC, you create a Raster Layer which works in the tool.

Try creating a Raster Layer with the Make Raster Layer (Data Management) ​tool and pass that as the "in_probability_raster" parameter.

KONPETROV
Frequent Contributor

I tried it your way but although I put again  workspace = ... and the makeRasterLayer_management("rcls", "rclsLayer, "") I get only an

Parameters are not valid. ERROR 000865: Input raster: rcls does not exist. Failed to execute (MakeRasterLayer).

The code after the reclassification can run only if I put rcls to the table of contents, something influences that but I don't know why?

0 Kudos
NeilAyres
MVP Alum

Here inRaster is just a string.

# Spatially Balanced Points

  •     inRaster = "rcls" 
  •     outPoints = "C:/Results/ArcMap/Visibility/Calc_View/point" + str(n) 
  •     arcpy.CreateSpatiallyBalancedPoints_ga(inRaster, 1, outPoints)

Why not just use your raster object outReclass.

KONPETROV
Frequent Contributor

Neil I also tried to put

inRaster = "outReclass"

....

....

but with no result.

0 Kudos
NeilAyres
MVP Alum

Kon,

here you are assigning the variable inRaster to the string "outReclass"

Not the raster object which is outReclass.

But yes, you can save it and put the full pointer to it, as you have indicated.

KONPETROV
Frequent Contributor

Problem solved at line 40 at the variable inRaster, it must be imported the path of the reclassified raster like that:

inRaster = "C:/Results/ArcMap/Visibility/Calc_View/rcls"

I don't know why, it is the first time I am doing it, but only by that it works.