|
POST
|
I ran a test run, and although the fields are populated, their units aren't in miles. I must be missing something simple... I am using Arc10, and I have converted to an appropriate equal distance projection. Regards... I am not sure how much influence the dataframe has on the field calculator. I suspect it only uses the native projection and units of the feature class when you just put !Shape.Length!. If you are OK with the original projection of the feature class, at 10 I believe if you choose the Python 9.3 option in the Model Builder Field Calculator tool you can adjust units by using: !Shape.Length@Miles! # or substitute any other appropriate units for Length. I am not sure how to emulate the geometry calculator's ability to apply the dataframe projection to feature classes that were stored using a different projection through the field calculator (At least not in Python. At 9.3 VBA would do it, but not at 10 using VB script).
... View more
10-21-2011
10:10 AM
|
0
|
0
|
9443
|
|
POST
|
Richard, the field calculation for !SHAPE.LENGTH! / 5280 # does not work. It produces a syntax error when ran on an empty field through field calculation. Any thoughts? What version of ArcGIS are you using and are you doing this in Desktop or with Model Builder. This should work for ArcGIS 9.3 and up, although you may have to change the case of the words to mixed case for 10 when ESRI started to make Python case sensitive. At 10 you can do: !Shape.Length@miles! # to get miles At 9.2 I think you can only use Python in Model Builder and the syntax might be !Shape!.Length or some other variant. Check the help files, since there should be something on this for 9.2. If you will not be exporting to a Python script and running it directly in Model Builder you can use VBA in an advanced calculation at 9.2, where the syntax would be: Parser: VBA Pre-Logic Code: Dim dblLength as double Dim pCurve as ICurve Set pCurve = [SHAPE] dblLength = pCurve.Length / 5280 Expression: dblLength
... View more
10-20-2011
06:46 AM
|
0
|
0
|
2133
|
|
POST
|
Thanks for you quick reply, although am not certain I'm following your logic precisely. And yes, I am using feature classes. When calculating without model builder, I create the two fields to house mileage (total miles and need miles), use calculate geometry to populate the segmets mileage, and then perform frequency analysis to summarize the values of the HUC 12s. Using model builder, should I be using calculate field prior to utilizing frequency, and what calculation would work for empty fields? Thanks again! I overcomplicated the calculation. It can be done as a simple calculation: Parser: Python Expression: !SHAPE.LENGTH! / 5280 # assumes base units is in feet and you want miles. The above calculation is done using the Field Calculator tool and does what the Calculate Geometry tool does in ArcMap, so you would use it the same way that you use the Calculate Geometry tool in your desktop process. This Field Calculator expression is what you had to do in ArcMap versions that existed when you had no Calculate Geometry option. With the Total_Miles and Need_Miles values calculated you would run the Frequency tool the same way you do now. You should run a calculation on Need_Miles to populate it with 0 on all records that are Null and that you do not want to be in the subset that has Mileage calcuated into the Need_Miles field prior to running Frequency, unless you find that the Frequency tool does what you want when these values are Null.
... View more
10-19-2011
08:10 PM
|
0
|
0
|
2133
|
|
POST
|
I've tried all of the suggestions without any luck. The only way that I can get it to extract the data is if I use: !shape.firstpoint! What's worse is that I have to have the field type set to text! So, I end up with: -92.298060755811 41.6208860260915 in my destination field. I have been able to populate my desired fields from these fields and convert it to a double, but it has been a real pain. I'm running ArcInfo 9.2 does that make a difference on the syntax? Thanks At 9.2 you could not use a method to access the X or Y component of the coordinate directly. That capability first appeared at 9.3. You had to parse the coordinates to get each desired coordinate separated and cast them to a float for directly calculating them to a pair of double fields. That avoids first saving the whole string to a text field. I don't have access to 9.2 anymore, but as I recall the syntax works something like: float(!shape.firstpoint![0]) # for X coordinate. float(!shape.firstpoint![1]) for Y coordinate.
... View more
10-19-2011
04:24 PM
|
0
|
0
|
2112
|
|
POST
|
Hello: I am attempting to calculate linear mileage of stream data for three predefined fields in model builder. The conceptual approach is to calculate all segments mileage in the first field (total_miles), then calculate a fraction of the records in another field (need_miles), and finally, calculate the percentage of the two in the final field (percentage). I'll use frequency to agregate the segments to their respective HUC 12 areas. The problem I am having, is how to calculate geometry (linear mileage) in model builder? I can't seem to locate the tool that may be dragged to model builder. Thanks so much in advance!!!! A few ways to do this. Sum the Length value in the frequency in whatever units they are listed (assming this is a geodatabase and not a shapefile), then do the conversion to miles at the join and calculation stage. If you are using a shapefile, first calculate a field called MILES using the Field Calculator tool. The python calculation to get the length of a line and make the appropriate units conversion is: Parser: Python Pre-Logic Code: def Output(Length): return Length / 5280 # assumes that shape length is in Feet and is being converted to Miles. Expression: Output(!SHAPE.LENGTH!) now sum the MILES field values in your frequency and you can get the all of the fields filled in that you need.
... View more
10-19-2011
03:26 PM
|
0
|
0
|
2133
|
|
POST
|
I am using shapefiles, does that matter? I think the problem is in the fact that the fc variable is a numeric value and not a feature class because it has been converted to an enumerated value. The CreateFeatureLayer expects fc to be an actual feature class and not a number. Separte the enumeration variable i from the fc variable. Try the code below:
arcpy.env.workspace = 'C:\\GIS_DATA\\' # or r 'C:\GIS_DATA\'
mxd = arcpy.mapping.MapDocument("Current")
fclist = arcpy.ListFeatureClasses()
i = 0
for fc in fclist:
i += 1
arcpy.CreateFeatureLayer_management(fc, "layer_%i" % i)
... View more
10-19-2011
02:15 PM
|
0
|
0
|
3327
|
|
POST
|
If your field contains string/text data, there is no need for the len method in Python since string data is an "iterable". For example >>> a = "abcdefghijklmnop"
>>> b = a[:-4]
>>> b
'abcdefghijkl'
>>> Dan: I am not really a Python programmer and my expression above would not work anyway because I didn't notice (in my quick check of some Python websites) that I needed the colon to indicate to take everything from the beginning of the string to the second position. Thanks for correcting my Python ignorance and showing another example of where Python is more elegant than VB Script.
... View more
10-16-2011
01:38 PM
|
0
|
0
|
10055
|
|
POST
|
Thank you very much. Yes I thought about this possibility. The Linear Referencing model we use is not suitable for Network Analyst (Route not connected) and it's managed externaly, we can't modify it. However I can create a network that interconnect my LRS model and define rules and direction of travel (for a motorway it shouldn't be to hard). Then I can create a geoprocessing tool that draws the "shortest route" based on the user defined "start" and "end" points and relocate the linear result on my LRS Route Model. It's sounds a bit like a makeshift job and I wanted to know if anyone knows another way of doing it. If by your Routes are not connected you mean that you do not have intersection breaks, that is not necessary for Network Analyst. It can detect and use joins where lines cross if you configure it that way. Also if you can create a network that interconnects your LRS model that should work equally well as an input to Network Analyst. Also the resulting route you want will not be able to keep the original measures of your Routes without being screwed up anyway, and you would have to use a Route transfer tool to take events from one Route and apply them to the other to match between these new Routes and your original Routes. The bigger problem is that you do not control the network, so some method of incremental updates of a derivative in-house network would be necessary to integrate it with Network Analyst. That is acheivable by making a copy of the original network and adding a field that keeps track of the end coordinates and length of each line, which can be calculated on your copy and joined to your own in-house-network. Using that field you can easily detect lines that have changed each time you get a new update of the Routes. Again, your idea that this is somehow a simple geoprocessing tool to create is incorrect. The amount of time you will spend to orient the routes, identify join points and then deal with the user failing to follow your orientations when they set beginning and ending points alone will give you headaches. I doubt Python can really do the interface you want. Every step you have described that you would do with your network is how you set up Network Analyst and Network Analyst has already overcome all of the logic it takes to traverse a network from any point to any point, even on networks without line breaks at each intersection, so again why reinvent the wheel?
... View more
10-16-2011
01:10 PM
|
0
|
0
|
826
|
|
POST
|
Just in case you ever need to use the field calculation in a Python script, to do the same thing in Python you would also use the len() function. For example: !input![len(!input!)-4] or rstrip(!input![len(!input!)-3]) (Keep in mind that whitespace characters count, so in your examples "BN14 5RY" is 8 characters long, not 7 and "BN1 5RY" is 7 characters long, not 6.)
... View more
10-16-2011
07:50 AM
|
0
|
0
|
10055
|
|
POST
|
Hello, I have postcodes which I need to cut down from say BN14 5RY to only BN14. I cannot simply use the 'left(input, n)' equation as some postcodes are only 6 figures long such as BN1 5RY and I always need the first 3/4 characters. Does anyone know a way to delete the last 3 characters? Thanks in advance. You can use the left() function if you combine it with the len() function. This will do what you want (I assumed you also want to get rid of the space character and not just the last three non-whitespace characters): left(input, len(input) - 4) or rtrim(left(input, len(input) - 3)) The len() function is normally used in combination with the left(), mid() and right() functions to control starting points, ending points and number of character values when doing string parsing.
... View more
10-16-2011
07:07 AM
|
2
|
0
|
10055
|