|
POST
|
dear rfairhur24. i have some issues with script you have provided to me, now, its ok with arcgis 10 version but its giving error in 10.1 version. arcgis 10 have python version 2.6.5 while arcgis 10.1 have python version 2.7.2. so script in python 2.7.2 version show some error in script like indent error like somethin. please could you fix the compatibility errors please. i try my hard to do this but i am not hero of python like you. thanks for response No error here and I originally wrote it using ArcGIS 10.1 and it is using Python 2.7.2 on my system, so that is not the problem. The Python version makes no difference. None of the code I wrote would break between those versions. Again, you need to screenshot what you are doing for me to troubleshoot this, since there are no indent errors in the code I am using. Even a single extra or missing space character will break the code, so I can only spot it from a screenshot. My code could not cause an indent error as I wrote it and the ArcGIS version or Python version could not cause that kind of error. So screenshot please.
... View more
09-23-2013
10:38 PM
|
0
|
0
|
1741
|
|
POST
|
Hi guys, ran into this problem yesterday. Is there any other way besides converting to VB expressions? Cheers Edit: Reread original post and see that there is a bug. So I guess Python is not an option with the PDF workflow. JScript is also supposed to be an option, but either way it means a rewrite from Python. I just happen to be very used to VB Script, so translating most non-spatial code is not too much of a problem for me.
... View more
09-23-2013
04:06 PM
|
0
|
0
|
2289
|
|
POST
|
I need to calculate a date field of a FGDB raster catalog (but I guess it could be any table or fc for that matter). The field I need to convert is a string that contains date values in the format: '2013-09-23 10:01:50' or for your Python referenced format it is: '%Y-%m-%d %H:%M:%S' My problem is that (I think) the ESRI Date field has trouble with really early dates. For example, this how could I correctly set a date field value with this string: '0001-01-01 00:00:00' Yes, that is year "1". When I run the code below, it calculates the field but this example value above is set to '1/1/2001', dropping the hh:mm:ss and always starts in the 21st century. I need the date field to save it as the original string, but stored as a date --- I am using the Time Slider to create time-series animations and it is very finicky about using dates. Any help is appreciated! fld = "_dateText_str" updFld = "_dateText_str_Converted" cursor = arcpy.UpdateCursor(ras) for row in cursor: strVal = row._dateText_str dtVal = datetime.datetime.strptime(strVal, '%Y-%m-%d %H:%M:%S') row.setValue(updFld, dtVal) cursor.updateRow(row) The File Geodatabase date field only supports dates from 12/31/1899 forward. I know this because the internal representation of the data is a number (exposed through the Summary Statistics tool). I know the internal representation of July 28, 2013 is 41483 days, which only allows 113 years back to day 0. The date field does not support negative numbers internally. I verified that the number of days between 12/31/1899 and 7/28/2013 is 41483 in Excel. So you will not be able to use an fgdb date field to do what you want. This should be documented with the other field data type descriptions and limitations in the help, but it isn't.
... View more
09-23-2013
06:35 AM
|
0
|
0
|
1403
|
|
POST
|
I got the code to work just fine. It calculated 15 in the MMONOTONIC field. Seems like I do not have monotonicity. How can I correct this? Simplify the line? I switched RID to 1 and re-generated the Event Table (attached). I zoomed into points 13 and 14 and there doesn't appear to be any complex curving here. A rating of 15 is the most messed up it can get and there is no way you can expect the measures to behave as though you had a simple monotonic route as the input. Some measures are increasing, others are decreasing, others are identical next to each other and others are unassigned. The measure order is true to the measure distribution on the route and your events give some clue how the route is actually pieced together in the underlying geometry, so that if you sorted the points in order by number that will show how the measures are assigned actually along the route. Such errors are almost always due to bad topology at very small detail levels. In an edit session I would inspect the sketch properties to see if the Route is singlepart or multipart. It is almost certainly multipart and joined together in a random segment order. So lines are skipped and then reverse direction and double back. To find out how many parts your line is made up of add a long field called Parts and calculate it with a simple Python calculation of: !Shape.PartCount! Assuming you have multiple parts I would probably use the explode tool in the Advanced Editing toolbar or the MultiPart to SinglePart tool to break the Route back up to its original component lines. The original lines are probably both overlapping each other and not touching exactly end to end to begin with. Bad topology like that will definitely mess up the measures and the way the Route is pieced together by the Create Route tool. No lines can overlap each other or cross over each other and all nearly coincident ends must actually touch end to end to avoid errors. To fix that I would convert it all to a file geodatabase feature class within a dataset and build a topology with rules for single part, no dangles, no crossings, and no overlaps and use the topology tools to fix the lines. If you don't want to go with the topology option, use either the Integrate tool or the Snap tool on the singlepart lines to make sure they join end to end without overlaps. Running the Intersect tool with the lines option would show you where line segments overlap. Running the Intersect tool again and with the points option where they cross or connect end to end. Once that is fixed I would build the Route using the Create Route tool with the Upper Right or Lower Left orientation Option (assuming the line does not curve around to another direction trend at the actual ends of the overall line).
... View more
09-20-2013
03:41 PM
|
0
|
0
|
12652
|
|
POST
|
Yes, the Route ID of the trail is zero. So it seems that the RID field of the Events is populated appropriately. I ran the code you provided using field calculator in a new "MMONOTONIC" field (long integer) and recieved error 999999 (attached). Maybe because I only have one route represented by one record? The attached image also shows the section of the trail where the calculation jumps and the attribute table of the route layer. For reference, this distance between the 13th and 14th point is about 500 meters. Here is a screen shot of how the calculation should look for the MMONOTONIC field. The codeblock only shows the beginning of the code, but the full code in my post code block is in that area. I ran this calculation on my 30K+ routes and it worked fine. I have not tested the code on actual NaN values in the route measures, so if the code fails NaN measures would be my suspected cause. You can see the route MMonotonic value using the Get Route Locations tool in the Customize Linear Referencing commands area. Go ahead and screen shot the sorted event table so I can see what the actual events and values are. Expand the tableview to full screen so I can see all of it. I personally would not use an ID of 0, since that can confuse blank values in a shapefile with real values, since both will defualt to 0. Also zoom into the 13 and 14 points. Complex curving routes can cause 2 locations to be chosen by the tool within the search radius and then randomly pick which it wants to keep.
... View more
09-20-2013
02:03 PM
|
0
|
0
|
12652
|
|
POST
|
I just added the calculation to a model and it performed perfectly for 30,000+ routes each with between 1 to 182 sequenced events. Here are screen shots of my calculation (part 1 and 2 to scroll the full code in the code block). So if you duplicate that set up exactly it should work.
... View more
09-20-2013
01:51 PM
|
0
|
0
|
5348
|
|
POST
|
Sort by RID and then by measure and be sure all of the events have the same RID values. The RID field includes zeros for each record. Maybe this is a clue to the problem? Is your actual Route ID for your trail 0? If not, these records are not located events and probably have a 0 measure, which would fall at the beginning of the route. However, I would have thought the events that did not locate properly would have been dropped by the tool, so I am not sure why you have these records at all if they are not actual events. Thank you for the code. I do have some Python experience. However, I am not sure how I would implement/modify this code for my situation. Can this be used in the Python window in ArcMap or would it require IDLE (or other)? Would I reference my data by defining a variable named "feat" which points to my point feature class? This is a Field Calculation not a Python script and it is for the Routes not the points. It is just to make sure the Route measures are well formed. Right click the MMONOTONIC field I told you to add to the Routes and choose the Calculate Field. Then input the calculation. Each step is listed from top to bottom of the field calculator tool and there are 4 things you need to set. No modification of the code is needed. It just ensures that there are no hdden problems in your routes and become more important when you start dealing with large datasets, such as the 30,000+ routes I deal with.
... View more
09-20-2013
01:07 PM
|
0
|
0
|
12652
|
|
POST
|
Hi, I am attempting to measure the distance between sites (points; n=50) that were sampled along a trail using the Linear Referencing tools. I created a "route" from my trail feature class (line; dissolved into one single feature) and was able to run the Locate Features Along Route tool without any errors. I then ran Make Route Event Layer so that I could view my points after they had been "snapped" to the trail, which all looked great. The problem I am having is with the values in the Measure Field, which is supposed to list the distance at which each point exists along the trail. I sorted the Measure Field in descending order and expected that my sites would then be listed in the order in which they appear along the trail, and this is the case for the first 12 sites. However, the 13th site listed is the one at the opposite end of the trail and then the remaining sites are listed in sequential order and meet back up with the 12th site. I checked to see if this could be explained due to the values being measured from the other end of the trail, but this didn't add up. So basically, it seems that the Measure Field was not calculated properly. I would greatly appreciated any insight into this. Many thanks in advance! Are multiple trails in your route feature class? Did you use the get nearest route or keep all locations option with the Get Rotue Locations tool? Are you sure the 13th event was linked to the same route as the others? Sort by RID and then by measure and be sure all of the events have the same RID values. Are you sure you have a simple monotonic route (all measures increase on each successive vertex)? Is the Route a singlepart feature or multipart feature? Does the trail loop back on itself or have branches? Any complexity to the route will cause odd results, so that is the first thing to eliminate. Just because everything is merged together does not mean that the route measures are properly formed. Did you manually calculate the measures or use the Create Route tool to assign measures? Here is code that will fill in a field to rate the MMonotonicity of your routes. Add a long field called MMONOTONIC to your routes and calculate it with this formula (any result other than 1 is potentially bad): Parser: Python Show Codeblock: Checked Pre-Logic Script Code: def MMonotonicity(feat):
partnum = 0
# Count the number of points in the current multipart feature
partcount = feat.partCount
pntcount = 0
mmonotonicity = 0
lastM = -100000000
# Enter while loop for each part in the feature (if a singlepart feature
# this will occur only once)
#
while partnum < partcount:
part = feat.getPart(partnum)
pnt = part.next()
# Enter while loop for each vertex
#
while pnt:
pntcount += 1
if lastM < pnt.M and lastM != -100000000:
mmonotonicity = mmonotonicity | 1
if lastM == pnt.M and lastM != -100000000:
mmonotonicity = mmonotonicity | 2
if lastM > pnt.M and lastM != -100000000:
mmonotonicity = mmonotonicity | 4
if not pnt.M:
mmonotonicity = mmonotonicity | 8
lastM = pnt.M
pnt = part.next()
# If pnt is null, either the part is finished or there is an
# interior ring
#
if not pnt:
pnt = part.next()
partnum += 1
return mmonotonicity Expression: MMonotonicity( !Shape!) The MMonotonicy values of the calculation and their domain translations are: 1 = Strictly Increasing 2 = All Measures are Level 3 = Increasing with Levels 4 = Strictly Decreasing 5 = Increasing and Decreasing 6 = Decreasing with Levels 7 = Increasing and Decreasing with Levels 8 = All Measures are NaN 9 = Increasing with NaN 10 = Measures with Levels and NaN only 11 = Increasing with Levels and Nan 12 = Decreasing with NaN 13 = Increasing and Decreasing with NaN 14 = Decreasing with Levels and NaN 15 = Increasing and Decreasing with Levels and NaN
... View more
09-20-2013
11:13 AM
|
3
|
0
|
12652
|
|
POST
|
jdrvar;329266 wrote: I changed the text to match my field name. My field name is TextString. So, my line of script reads: "(" + !TextString! + ")"QUOTE] addParentheses = "(" + !TextString! + ")" returns a Syntax Error. I know the field name and type are correct, therefore, believed the expression to be correct. That left the concatenation of parentheses. But, the concatenation worked within Field Calculator. Then, I went back reread the posts and tried adding a second variable; expression = (!TextString!). Which also created a Syntax Error. So, I removed the exclamation points from the addParentheses variable. Removing the exclamation points, the script runs, and replaces existing text with parentheses. But, I want to concatenate the existing text with parentheses. Any suggestions?
TextString = arcpy.GetParameterAsText(0)
addParentheses = "(" + TextString + ")"
cursor = arcpy.da.UpdateCursor(History, ["TextString"])
for row in cursor:
row[0] = addParentheses
cursor.updateRow(row)
del row
del cursor Well this is nothing like a Field Calculation, so of course the !TextString! won't work. I did not know you were going to this kind of script. Just use the updatecursor itself to do this. FieldName = arcpy.GetParameterAsText(0)
cursor = arcpy.da.UpdateCursor(History, [FieldName])
for row in cursor:
row[0] = "(" + row[0] + ")"
cursor.updateRow(row)
del row
del cursor The input parameter would be any text field name. So choose "TextString" in that parameter. Or forget the parameter and hard code the field name. cursor = arcpy.da.UpdateCursor(History, ["TextString"])
for row in cursor:
row[0] = "(" + row[0] + ")"
cursor.updateRow(row)
del row
del cursor
... View more
09-20-2013
10:51 AM
|
0
|
0
|
3524
|
|
POST
|
There is a geoprocessing way to do this. 1. If your data is not already sorted by CID values, first run the Sort tool with the sort fields being the CID field and the ObjectID field. I will call the output "Sorted" 2. On the sorted output add a long field called something like Sequence. 3. Calculate the Sequence field to be equal to the ObjectID. 4. Do a Summary Statistics of the Sorted feature class using the CID field as the case field and the Min of the Sequence field as the summary. I will call the output "Summary". 5. Make the sorted output a Feature Layer. 6. Join the sorted feature layer as the target and the summary as the join table on the common CID fields. 7. Calculate the Sequence field to be: Sorted.Sequence - Summary.Min_Sequence + 1 8. Remove the Join. The Sequence field will now contain a sequential ID that restarts the numbering at 1 for each CID value. Null values in the CID field would potentially mess this up, but I think it would handle that correctly.
... View more
09-20-2013
03:56 AM
|
0
|
0
|
5348
|
|
POST
|
hello everyone the script given in response to my post by rfairhur24 is not working well i tried it many ways i request rfairhur24, please try it and then send me back. i try hard to get job done with this script but its not working. i also request the other user or expert to please do me favor and just post something different and new for this task. i also request rfairhur24 please provide me stand alone python script that can work like a tool, any thing that could work batter. there is another option that i have each route have single unique ID named CID. for every route CID is different like for route no 1. points CID is 1, for route no.2 CID is 2 same is true for 23 routes. i am looking for a scripts that generate the sequential ID for each CID. best regards Nadeem Fareed Do me a favor and screen shot your actual calculation input as I requested. The only test you showed me a screen shot for had a definite error in the way you transferred my code to the Field Calculator. Since the code I provided works when I input it into the field calculator (tested on over 10,000 unique Route IDs each with between 1 and 300 sequenced events, so more than an adequate test to say it should work for your small data set), I want to eliminate user failure as the reason for your failed attempts to make my code work and a screen shot would be the best way to do that. I would screen shot my calculation for you, but at the moment I cannot access my system remotely to do that. Are you sure there are absolutely no Null values in the CID field? If there were the calculation would fail. So on the off chance that is the problem I have added code below to deal with that situation. Any standalone script I would write would be based on the same code, so before I go to the trouble of trying to come up with any other script code try setting the calculation up exactly as shown below and screen shot your Field Calculator set up and results so I can verify you correctly transferred the calculation to the Field Calculator first. It should be: Parser: Python Show Codeblock: Checked Pre-Logic Script Code: recDict = {}
def autoIncrement(CID):
global recDict
pStart = 1 # adjust start value, if required
pInterval = 1 # adjust interval value, if required
if not CID:
CID = "Null"
if CID in recDict:
recDict[CID] = recDict[CID] + pInterval
else:
recDict[CID] = pStart
return recDict[CID] Expression: autoIncrement(!CID!)
... View more
09-20-2013
03:32 AM
|
0
|
0
|
5348
|
|
POST
|
Here is the model I ran and a test set of data. The screenshots got a little out of order. The first screenshot is the model. The third screenshot shows the input polygons (CornerTouch layer shown). The second screenshot shows the 1 foot buffer distance output which creates a single shape (MapBuffer layer shown). Then after using the multipart to single part tool and the Spatial Join tool (MapBuffer2 layer and MapParcels layers respectively, not shown) I used the Dissolve tool (4th screenshot with MapDissolve layer shown) to achieve the final result. The central green polygon in the MapDissolve layer is one multipart polygon feature that contains 3 polygon parts that only touch each other at a single point. The other two shapes are separate single part polygon features because they do not touch any other polygon at even a point. The final output has no buffer, so it is a pure dissolve of the original input shapes.
... View more
09-18-2013
03:57 PM
|
0
|
0
|
12068
|
|
POST
|
sorry for the confusion, and I appreciate your reply. To answer your question, I have actual elevations in the "us_elev" and "ds_elev" fields. FOr instance, US could be 501.00 and DS could be 499.9, indicating that I want the arrow pointing to the lower number. Forgive my ignorance, as I am really new at this! Mike These two fields do not tell you the orientation of the flow direction of your line, since the values are not clearly assigned to the beginning or end of the line. All you know is one end is higher than the other, but not which end is up and which is down. Either the line had to be drawn consistently downstream or consistently upstream to know which end of the line to point toward, or you have to have actual Z coordinate values assigned to the line geometry to find out which end is the lower end. Orientation has to be intentionally established when creating line features and cannot be determined simply by looking at two fields that have no clear no correlation to the line ends. Potentially using linear referencing to create routes that combine the sewer line chains together as events could tell you how the lines are oriented, but that takes about two dozen geoprocessing steps to manipulate the lines and end points to derive the line orientation. It is not something that is in a ready made help file and I would have to write out custom instructions for you to follow. That is beyond what I can offer at this time.
... View more
09-18-2013
11:17 AM
|
0
|
0
|
1623
|
|
POST
|
so I had to draw them in the direction of flow for that to work? I was hoping I could just use the arrow to point to the "ds_elev" (for downstream) field. Not possible? I never said that and in fact my post said the exact opposite. Regardless of how you drew the lines to begin with, you can determine the flow direction from correctly assigned Z values with a simple binary field. Once the lines are classified with a simple binary value, then you have the choice of using either that binary field value to symbolize the lines without reorienting them or actually reorienting the lines. You never said what your fields contained and I assumed the Z values were on the line geometry. I have no idea what your ds_elev field contains, so I don't know if it can be used or not. If your ds_elev field contains actual Z values, then it should not be directly used for symbology, since it is not a predictable value. If ds_elev is just a Z value number that gives no indication of which end of the line it is associated with, then that is not sufficient for solving this problem. But from actual Z values that are correctly associated to the ends of your lines, you can derive a field that sets up a simple binary indicator of flow direction with yes/no, true/false, 0/1 or any other binary values. If ds_elev is a yes/no, true/false, 0/1 or other binary indicator of whether the lines are with or against the downstream flow, set up the Symbology as Categories on that field and use a Cartographic line to add arrowheads to point the appropriate direction based on that field. Once you have a field that simplifies the classification of the line flow direction, then there is also a Flip tool that could actually use selections based on that value to reorient the upstream oriented lines if you wanted them to actually point downstream. Use of the Flip tool is optional and your lines do not actually have to point downstream to symbolize them correctly.
... View more
09-18-2013
06:20 AM
|
0
|
0
|
1623
|
|
POST
|
I am using a shape file for my sewer lines, each line has an upstream elevation and a downstream elevation field. Is there a way to show my line pointing to the downstream elevations, thus showing the flow of the sewer line? Thanks for any help you can give. It can be done if either the lines were digitized to point in the flow direction or if the lines contain an attribute that indicates whether the digitized direction is with or against the flow direction. I would add 2 double fields to calculate the From and To end Z values. The formula in the Field Calculator is a Python calculation of either Shape.FirstPoint.Z! (From Z) or !Shape.LastPoint.Z! (To Z). Where the From Z value is greater than the To Z value the flow is with the digitized line direction and where the opposite is true, the flow is against the digitized direction. You then would have the option of actually flipping the lines to orient them with flow direction, or leaving them as digitized and adding and calculating another field to indicate how the lines are oriented. If you use the field then you would use a Value Classification symbols that uses two separate symbols and the appropriate arrowhead direction to fit the flow direction field value.
... View more
09-16-2013
02:46 PM
|
0
|
0
|
1623
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-24-2026 11:37 PM | |
| 1 | 03-24-2026 08:01 PM | |
| 7 | 02-23-2026 08:34 AM | |
| 1 | 03-31-2025 03:25 PM | |
| 1 | 03-28-2025 06:54 PM |
| Online Status |
Offline
|
| Date Last Visited |
07-09-2026
12:59 AM
|