Dynamic Value increase for each new line

534
2
Jump to solution
01-26-2013 02:02 PM
ThomasStanley-Jones
New Contributor III
Hello,

I'm trying to set up ArcMap 10.0 (ArcInfo License, SpatialAnalyst Extension) so that as I create new lines in a feature class, the value in a field will increase sequentially.  I've been playing with the Attribute Assistant (very neat).  It has a GENERATE_ID function that does what I want, but I can't control the sequence size.  The value goes up by 1, but I want to make it go up by 300, or 50, depending on which kind of line I'm creating.  As an example, the "LineNumber" field will equal "0", "300", and "600" if I draw 3 lines and set the sequence to be 300 and to start at 0. 

Does anyone know how I can do this with any available tool? 

Any input would be appreciated, Thanks!
0 Kudos
1 Solution

Accepted Solutions
T__WayneWhitley
Frequent Contributor
So you are adding new lines (records) to an existing feature class table that is already partially loaded with features?...and what about the actual geometry for those features - when does that get loaded?

If I understand your problem, this would be relatively easy to do with a python cursor, probably an insertcursor.  So that would likely be set up as a script tool for you to input your parameters when you decide to insert a number of records - at runtime, you'd specify sequence size, what number you want to start from, and either the number of records you want or number in the sequence you want to stop at.  Say, you specify to add 10 records, increment by 2, starting with 4 - then you'd need this output sequence:

4, 6, 8, 10, 12, 14, 16, 18, 20, 22

In fact, there is already simple python looping that can readily do just that - nothing fancy.  In case you don't recognize the output below, this was tested within IDLE, a python Integrated Development Environment (IDE) that ships with your ArcGIS.  This was the interactive result, printing the incremented 'i' values that could be written to your table:
>>> for i in range(4, 24, 2):  print i    4 6 8 10 12 14 16 18 20 22


As you can see, the trick is in specifying the parameters for 'range' above, range(4, 24, 2), where '4' is the start, '24' is the upper bound value, and '2' is the step value...but how do you know what the upper bound value should be?

Well based on your input for the script tool (remember, for this example it was specified as 10 records, increment by 2, starting with 4), then 10(2) + 4 = 24 or this:
>>> start = 4 >>> numRecords = 10 >>> step = 2 >>>  >>> upperbound = numRecords*step + start >>> print upperbound 24 >>> for i in range(start, upperbound, step):  print i    4 6 8 10 12 14 16 18 20 22 >>>   >>> # demonstrate changing the input params:  >>> start = 200 >>> step = 40 >>> numRecords = 7  >>> # same code, different input values, based on new input params  >>> upperbound = numRecords*step + start >>> for i in range(start, upperbound, step):  print i    200 240 280 320 360 400 440 >>> 


Hope that makes sense - just don't know how you intend to enter the feature geometry...you'll have to fill in more the nature of the problem - of course there are means to insert geom as well to accommodate this situation, just need a better idea what you're dealing with.

If you are interested in this approach (this Python approach), then you should probably post again in the Python forum, referring to this thread.  Probably a good idea to leave this thread here as it is, just in case there is a more appropriate 'other' kind of solution, perhaps without the custom code.

Enjoy,
Wayne

View solution in original post

0 Kudos
2 Replies
T__WayneWhitley
Frequent Contributor
So you are adding new lines (records) to an existing feature class table that is already partially loaded with features?...and what about the actual geometry for those features - when does that get loaded?

If I understand your problem, this would be relatively easy to do with a python cursor, probably an insertcursor.  So that would likely be set up as a script tool for you to input your parameters when you decide to insert a number of records - at runtime, you'd specify sequence size, what number you want to start from, and either the number of records you want or number in the sequence you want to stop at.  Say, you specify to add 10 records, increment by 2, starting with 4 - then you'd need this output sequence:

4, 6, 8, 10, 12, 14, 16, 18, 20, 22

In fact, there is already simple python looping that can readily do just that - nothing fancy.  In case you don't recognize the output below, this was tested within IDLE, a python Integrated Development Environment (IDE) that ships with your ArcGIS.  This was the interactive result, printing the incremented 'i' values that could be written to your table:
>>> for i in range(4, 24, 2):  print i    4 6 8 10 12 14 16 18 20 22


As you can see, the trick is in specifying the parameters for 'range' above, range(4, 24, 2), where '4' is the start, '24' is the upper bound value, and '2' is the step value...but how do you know what the upper bound value should be?

Well based on your input for the script tool (remember, for this example it was specified as 10 records, increment by 2, starting with 4), then 10(2) + 4 = 24 or this:
>>> start = 4 >>> numRecords = 10 >>> step = 2 >>>  >>> upperbound = numRecords*step + start >>> print upperbound 24 >>> for i in range(start, upperbound, step):  print i    4 6 8 10 12 14 16 18 20 22 >>>   >>> # demonstrate changing the input params:  >>> start = 200 >>> step = 40 >>> numRecords = 7  >>> # same code, different input values, based on new input params  >>> upperbound = numRecords*step + start >>> for i in range(start, upperbound, step):  print i    200 240 280 320 360 400 440 >>> 


Hope that makes sense - just don't know how you intend to enter the feature geometry...you'll have to fill in more the nature of the problem - of course there are means to insert geom as well to accommodate this situation, just need a better idea what you're dealing with.

If you are interested in this approach (this Python approach), then you should probably post again in the Python forum, referring to this thread.  Probably a good idea to leave this thread here as it is, just in case there is a more appropriate 'other' kind of solution, perhaps without the custom code.

Enjoy,
Wayne
0 Kudos
ThomasStanley-Jones
New Contributor III
Thank you for the idea, I hadn't thought of implemnting something this way.  I need to be able to update the attributes during an editing session.  To make this work I'll make a script tool with a button on the editing toolbar so when a group of lines has been created,
-make sure they are selected
-click on the button to run this script
-choose the feature class
-set the beginning number
-set the interval
-and run the tool

Only the features that were selected will be updated.  Yeah, this will work perfectly, thanks a lot!
0 Kudos