setting variables within Model Builder

719
10
11-05-2010 11:22 AM
TimothyHandley
New Contributor
I'm using the Rotate (raster) tool in Model Builder. One of the parameters for this tool is the pivot point. I'd like to have my tool calculate the centroid of the raster, and then pass the coordinates of the centroid to the Rotate tool to use as the pivot point.

Using a short string of tools, I can create a point shapefile with a single point located at the centroid of the original raster. I can also add the x/y coordinates of this point to the attribute table of the point. Unfortunately, I don't know how to get the Rotate tool to use this information.

As a start, I tried right-click-on-Rotate > make variable from parameter > pivot point. While I can type coordinates into this variable, I can't find a way to connect the centroid point to this variable.

Any other ideas? Am I on the right track?
0 Kudos
10 Replies
JosephSheffield
New Contributor III
The easiest way is to run this model from python script.  This way you can get the X and Y coordinates and feed them directly into the Rotate Raster Tool.
0 Kudos
TimothyHandley
New Contributor
I've been trying to avoid learning Python. While I'm sure it's more powerful and flexible, I don't think I'd have much need to use it (GIS is only about 10% of my work). So I was hoping to be able to do this within model builder. That said, it may not be possible, and I'll just have to learn Python, or do without this functionality in my model.

Thanks for the thought. Any other ideas?
0 Kudos
JosephSheffield
New Contributor III
I don't know of another way to build a dynamic model.  Arc will generate 90% of the python code for you, if you export you model to python script.  When I started to learn python this is the process I used, it is really not that bad to learn.  Since, I've learned python is has added a lot of functionality that would normally take a GIS tech hours and hours to do.  Instead, python allows me to script processes and set Arc to run over night, so Arc does not take valuable computer resources during normal office hours.  Thus the process is automated and no human resources are required to run the model.
0 Kudos
TimothyHandley
New Contributor
Thanks. I guess I'll knuckle down and do it.
0 Kudos
JosephSheffield
New Contributor III
Good luck.
0 Kudos
BBicking1
Esri Contributor
I've been trying to avoid learning Python. While I'm sure it's more powerful and flexible, I don't think I'd have much need to use it (GIS is only about 10% of my work). So I was hoping to be able to do this within model builder. That said, it may not be possible, and I'll just have to learn Python, or do without this functionality in my model.

Thanks for the thought. Any other ideas?



If you haven't made any progress with this, Tim, attach your model and I'll take a look.

Barbara Bicking
Geoprocessing Team
0 Kudos
WhereMatters
Occasional Contributor
I tried to pass the pivotpoint by using a small python script that accepted two parameters (x and y coords) and returned a point object. This way i am able to connect the output point object to rotate tool and it accepts that as "PivotPoint" when i drag the variable to rotate tool in model builder.

However, when i execute the model, the rotate tool just ignores this and uses default # option and rotates the raster along the lower left edge.

I have attached a snapshot of the model if it helps.

I want to accomplish this using model builder only and without using Python and this should be possible.
0 Kudos
ShitijMehta
Esri Regular Contributor
Hi Anand,
Check the attachment.

You don't need to convert the raster to Poly and do all that stuff.
Try something like what is shown in the attached image:

here is the code

Expression: (here your Input is the Input Raster variable name - The variable name can be x/y/anything while its value is the path to your raster - read Calculate Value help)

fn(r"%Input%")


Code Block

def fn(input):
import arcpy
myRaster = arcpy.Raster(input)
ext = myRaster.extent
midx = (ext.XMax - ext.XMin) / 2
midy = (ext.YMax - ext.YMin) / 2
return "{0} {1}".format(midx,midy)
0 Kudos
ShitijMehta
Esri Regular Contributor
Sorry it was addressed to  thandley
0 Kudos