Select to view content in your preferred language

multiple shapefiles from create random points

1945
9
Jump to solution
05-14-2013 01:20 PM
JacobGjesdahl
Emerging Contributor
Hello, I'm trying to run a model that will make viewsheds for almost 4000 points and then make a table of areas in different land uses within each viewshed (each point is a row in this final table).  I have the model all built and working fine for one point, but I don't know how to "split" the rows of the input table into new shapefiles.  To start with I have a polygon file of lots and I want to assign a random point to each polygon.  However, when I tried to go into properties and change it to a list of values, the result was the same - lots of points within one shapefile, when what I want is almost 4000 shapefiles each containing one point.  I see two possible solutions to this: where I get the tool to recognize the shapefile as multiple inputs rather than 1 input, or where I first split the shapefile into 4000 shapefiles, then run the tool with a list input.  However, I think the list input only allows 50 inputs, so it seems like the first option would be the way.

Sorry if this is an obvious question (or conversely impossible to understand), I'm fairly new to model builder.

Thanks,
Jacob Gjesdahl
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Alum
Chris is right, your syntax is messing things up. The error message is because python is not recognizing your variables as raster layers but just as garden-variety strings.

To get this to work, you must rename your model element names to remove the percent symbols (right click / rename). They were automatically named that way as you were creating them, I know, but ModelBuilder gets very confused  when percents are used in the model element names, since model variables are used as model element names surrounded by percent symbols.

Then, in Raster Calculator, you can make a more sane expression using the raster layers listed in the upper left corner -- something like:
Con( (("value_be2" == 0) & ("value_hh" == 0) & ("value_no" == 1)) |     (("value_no" == 1) & ("value_be" == 1) & ("value_hh" == 1)), 1, 0)


I can simplify your expression, too:
Con( "value_no" == 1 &      ((("value_be2" == 0) & ("value_hh" == 0)) |     (("value_be" == 1) & ("value_hh" == 1))), 1, 0)

View solution in original post

0 Kudos
9 Replies
ChristopherBlinn1
Deactivated User
Hello Jacob,

Have you looked into iterating your point shapefile first?

You can iterate the OBJECTID field, which can then be used in a select by attribute process.  This will ensure you select each row, one at a time.

From here you have options.  Either copying the selection to a new shapefile, or using it inside of the rest of your model.  You can even use %i% or your iteration %value% to uniquely name the outputs.

If you create individual shapefiles, then you can use an additional iterator (inside of a new model) to iterate each shapefile into your current model.

Hope this helps!

Best,
Chris B.
0 Kudos
JacobGjesdahl
Emerging Contributor
Great, I think I got it now.
0 Kudos
JacobGjesdahl
Emerging Contributor
Actually, one more problem I thought I could figure out on my own, but I couldn't.

I have this as my expression on raster calculator:
Con(( ("%%value%_be2%" == 0) & ("%%value%hh%" == 0) & ("%%value%no%" == 1) ) | ( ("%%value%be%" == 1) & ("%%value%no%" == 1) & ("%%value%hh%"== 1) ), 1, 0)

But it gives me the attached error.  It seems that the problem is that it's not referencing the real rasters I want it to, but I couldn't figure out how to get those actual rasters into the raster calculator.  Do you know how to do this?

Thanks,
Jacob
0 Kudos
ChristopherBlinn1
Deactivated User
Jacob,

Alright, let me try and dissect your expression a bit:

Are you adding the %value% variable into another variable to create the raster name? Raster names shouldn't need the extra set of %% around them.

For example, you have "%%value%_be2%".  For the sake of argument, if we say %value% equals 'input1', is your raster name actually, 'input1_be2'?  If so, you should just put "%value%_be2".

I know this is a 10.0 help page, but it applies to 10.1 in terms of naming rasters in the raster calculator..

In that case, this expression may work (untested):

Con(( ("%value%_be2" == 0) & ("%value%hh" == 0) & ("%value%no" == 1) ) | ( ("%value%be" == 1) & ("%value%no" == 1) & ("%value%hh"== 1) ), 1, 0)


Hope this helps!

Best,
Chris B.
0 Kudos
JacobGjesdahl
Emerging Contributor
No, I'm afraid I tried that too, and it didn't work.
0 Kudos
ChristopherBlinn1
Deactivated User
Jacob,

Unfortunately without seeing your model (and python script behind the model), I cannot address your issue any further.

If possible, please attach the python script to your model in a zipped folder, and I can take a further look.

Thanks,
Chris B.
0 Kudos
JacobGjesdahl
Emerging Contributor
Attached is the python as well as the model in picture form.
0 Kudos
curtvprice
MVP Alum
Chris is right, your syntax is messing things up. The error message is because python is not recognizing your variables as raster layers but just as garden-variety strings.

To get this to work, you must rename your model element names to remove the percent symbols (right click / rename). They were automatically named that way as you were creating them, I know, but ModelBuilder gets very confused  when percents are used in the model element names, since model variables are used as model element names surrounded by percent symbols.

Then, in Raster Calculator, you can make a more sane expression using the raster layers listed in the upper left corner -- something like:
Con( (("value_be2" == 0) & ("value_hh" == 0) & ("value_no" == 1)) |     (("value_no" == 1) & ("value_be" == 1) & ("value_hh" == 1)), 1, 0)


I can simplify your expression, too:
Con( "value_no" == 1 &      ((("value_be2" == 0) & ("value_hh" == 0)) |     (("value_be" == 1) & ("value_hh" == 1))), 1, 0)
0 Kudos
JacobGjesdahl
Emerging Contributor
Great!  Thank you very much - the rename was the ticket and it seems to work fine now.
0 Kudos