POST
|
Is anyone aware of a way to add cogo fields to a feature class using a stand alone script?
... View more
06-16-2014
09:29 AM
|
0
|
5
|
964
|
POST
|
I am looking for some help with some logic regarding ensuring line A crosses line B perpendicularly. SO far my approach has been to 1)generate points at the intersections 2)Get bearing from segment of line B where intersection occurs. 3) calculate a perpendicular bearing I wish to take this bearing and extend it to line A then trim and clean. The attached image and script should help explain. I also am interested in easier logic if someone has done this before? Thanks in advance... Image: [ATTACH=CONFIG]34487[/ATTACH]
fclist = arcpy.ListFeatureClasses("Simplified_LCP_*","Line")
for fc in fclist:
arcpy.MakeFeatureLayer_management(sps_lines, "feature_layer")
lyrfile = arcpy.SelectLayerByLocation_management("feature_layer","INTERSECT",fc,"#","NEW_SELECTION")
arcpy.AddGeometryAttributes_management("sps_lines_fl","LINE_BEARING")
count = int(arcpy.GetCount_management(lyrfile).getOutput(0))
if count > 0:
# Print Intersecting line and number of intersections
print "While examining {0}, {1} intersections were found." .format(fc,count)
arcpy.Intersect_analysis([fc,sps_lines],Modified(fc),"ALL","#","POINT")
for row in arcpy.da.SearchCursor("sps_lines_fl","BEARING"):
bearing = row[0]
if bearing >= 0 and bearing <= 270:
# Print intersecting line and bearing of sps line at intersection
perp = bearing + 90
print "{0}, Perpendicular value is: {1}" .format (fc, perp)
else:
perp = (bearing + 90) - 360
print "{0}, Perpendicular value is: {1}" .format (fc, perp)
... View more
06-10-2014
02:23 PM
|
0
|
0
|
734
|
POST
|
Thanks Adam! I like that. I have a tendency to try things the hard way:)
... View more
06-05-2014
01:57 PM
|
0
|
0
|
472
|
POST
|
Thanks a million Richard! This did exactly what I'd hoped. I used the distance method to add some error handling for SE/NW lines.
Expression1 = "Output(!Shape.FirstPoint!, {0},{1})" .format(minX, minY)
Expression2 = "Output(!Shape.FirstPoint!, {0},{1})" .format(maxX, minY)
codeblock1 = """def Output(FirstPoint, MinX, MinY):
XDif = round(float(FirstPoint.X), 4) - round(float(MinX), 4)
YDif = round(float(FirstPoint.Y), 4) - round(float(MinY), 4)
Length = math.hypot(XDif, YDif)
FPX = round(float(FirstPoint.X), 4)
FPY = round(float(FirstPoint.Y), 4)
return "{%(LEN)012.4f}{%(FX)012.4f}{%(FY)012.4f}" % {'LEN':Length, 'FX': FPX, 'FY': FPY}"""
codeblock2 = """def Output(FirstPoint, MaxX, MinY):
XDif = round(float(FirstPoint.X), 4) - round(float(MaxX), 4)
YDif = round(float(FirstPoint.Y), 4) - round(float(MinY), 4)
Length = math.hypot(XDif, YDif)
FPX = round(float(FirstPoint.X), 4)
FPY = round(float(FirstPoint.Y), 4)
return "{%(LEN)012.4f}{%(FX)012.4f}{%(FY)012.4f}" % {'LEN':Length, 'FX': FPX, 'FY': FPY}"""
if bearing > 180 and bearing < 270:
arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock)
elif bearing > 0 and bearing < 90:
arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock)
elif bearing > 90 and bearing < 180:
arcpy.CalculateField_management("pts_dissolve","Sort", Expression2,"PYTHON_9.3",codeblock2)
else:
arcpy.CalculateField_management("pts_dissolve","Sort", Expression2,"PYTHON_9.3",codeblock2)
... View more
06-04-2014
01:29 PM
|
0
|
0
|
301
|
POST
|
Thanks Adam! I think your right on. Somehow I still generated an empty dataset and script failed? Here was the error message. Any thoughts? Error: Traceback (most recent call last): File "G:\Xcel\Route Tool\Southwest\Least Cost Paths(2).py", line 319, in <module> main() File "G:\Xcel\Route Tool\Southwest\Least Cost Paths(2).py", line 259, in main arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "") File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\conversion.py", line 288, in RasterToPolyline raise e ExecuteError: ERROR 010151: No features found in G:\Xcel\Route Tool\Southwest\Results.gdb\LCP_4. Possible empty feature class. Failed to execute (RasterToPolyline).
count = 0
while count < 10:
Output_polyline = os.path.join(savepath + "\\Results.gdb" + "\\LCP_" + str(count))
End_Raster = os.path.join(savepath + "\\Scratch.gdb" + "\\End_Raster_" + str(count))
#Raster to Polyline
arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1))
arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "")
#check to see if the new Output_polyline is empty, and break if so:
if int(arcpy.management.GetCount(Output_polyline).getOutput(0)) == 0:
#you could also delete the empty feature class if you want
#arcpy.management.Delete(Output_polyline)
break
... View more
06-03-2014
09:08 AM
|
0
|
0
|
472
|
POST
|
I am trying to stop the script below once an empty feature class is generated. I have worked out the following which I imagine to be close? But still receive an error: ExecuteError: ERROR 010151: No features found in G:\Xcel\Route Tool\Southwest\Results.gdb\LCP_4. Possible empty feature class I think the script should explain what I am trying to accomplish? count = 0 while count < 10: Output_polyline = os.path.join(savepath + "\\Results.gdb" + "\\LCP_" + str(count)) End_Raster = os.path.join(savepath + "\\Scratch.gdb" + "\\End_Raster_" + str(count)) #Raster to Polyline arcpy.AddMessage("Saving Least Cost Path {0}..." .format(count + 1)) arcpy.RasterToPolyline_conversion(get_LCP(count), Output_polyline, "ZERO", "0", "SIMPLIFY", "") # List line feature classes in Results.gdb fclist = arcpy.ListFeatureClasses("*","Line",savepath + "\\Results.gdb") for fc in fclist: lcpcount = arcpy.GetCount_management(fc) if lcpcount == 0: break
... View more
06-03-2014
06:40 AM
|
0
|
4
|
1052
|
POST
|
Thanks Richard! I got this to work using the first process you described. I would be curoius to see a function used to calculate that euclidean field? Here is what worked for me. arcpy.AddField_management("pts_dissolve","Sort","TEXT", 50)
Expression = "Output(!Shape.FirstPoint!)"
codeblock = """def Output(FirstPoint):
FPX = round(float(FirstPoint.X), 4)
FPY = round(float(FirstPoint.Y), 4)
return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY}"""
arcpy.CalculateField_management("pts_dissolve","Sort", Expression,"PYTHON_9.3",codeblock)
... View more
05-30-2014
01:17 PM
|
0
|
0
|
301
|
POST
|
Thanks Richard!, Although I am quite sure you have answered my question already. I am a little unsure about implementing this in a stand alone script. Can you help?
def Output(FirstPoint):
FPX = round(float(FirstPoint.X), 4)
FPY = round(float(FirstPoint.Y), 4)
return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY}
def get_LCP(fc):
return os.path.join(results + '\\Simplified_' + fc)
def main():
points = results + '\\pts'
# Process: Find all stream crossings (points)
#arcpy.Intersect_analysis(lines,'G:\Xcel\Route Tool\Southwest\Results.gdb\pts',"ONLY_FID","#","POINT")
in_features = "'" + lines + "'" + " #"
arcpy.Intersect_analysis(in_features,\
out_feature_class="G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect",\
join_attributes="ONLY_FID",cluster_tolerance="#",output_type="POINT")
# Adds x and y field to points
pts_geometry = arcpy.AddXY_management("G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect")
# Dissolves duplicate points
arcpy.Dissolve_management(pts_geometry,"pts_dissolve","POINT_X;POINT_Y","#","SINGLE_PART","DISSOLVE_LINES")
arcpy.AddField_management("pts_dissolve","Sort","TEXT")
arcpy.CalculateField_management("pts_dissolve","Sort", Output(Shape.FirstPoint),"PYTHON_9.3")
... View more
05-30-2014
10:25 AM
|
0
|
0
|
301
|
POST
|
I have a point Feature Class I am trying to sort. It contains both a "POINT_X" and a "POINT_Y" field. I wish to start from lower left and sort WE_SN. I have a standard license and am therefore limited to a single sort field (excluding shape) while using sort_mgmt(). I therefore am looking to calculate new sort field using "POINT_X" and "POINT_Y". Any suggestions? Thanks in advance.
... View more
05-30-2014
08:44 AM
|
0
|
5
|
515
|
POST
|
Making a feature layer before selection corrected my issue. Thank you both! I would probably save a lot of time by reading the resources first. Glad to know I wasn't the only one out there making this mistake. Lol.
... View more
05-30-2014
08:24 AM
|
0
|
0
|
422
|
POST
|
I have no idea why I can run this tool from tool dialogue but not from the following script? Error Message: Failed to execute. Parameters are not valid. ERROR 000368: Invalid input data. Failed to execute (SelectLayerByLocation). import arcpy import os from arcpy import env env.overwriteOutput = 1 ''' lines = arcpy.GetParameterAsText(0) results = arcpy.GetParameterAsText(1) ''' lines = 'G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip' results = 'G:/Xcel/Route Tool/Southwest/Results.gdb' line_string = '"' + "'" + lines + "'" + " #" + '"' env.workspace = results def main(): points = results + '\\pts' # Process: Find all stream crossings (points) #arcpy.Intersect_analysis(lines,'G:\Xcel\Route Tool\Southwest\Results.gdb\pts',"ONLY_FID","#","POINT") in_features = "'" + lines + "'" + " #" arcpy.Intersect_analysis(in_features,\ out_feature_class="G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect",\ join_attributes="ONLY_FID",cluster_tolerance="#",output_type="POINT") # Adds x and y field to points pts_geometry = arcpy.AddXY_management("G:/Xcel/Route Tool/Southwest/Scratch.gdb/lines_clip_Intersect") # Dissolves duplicate points arcpy.Dissolve_management(pts_geometry,"pts_dissolve","POINT_X;POINT_Y","#","SINGLE_PART","DISSOLVE_LINES") # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script # The following inputs are layers or table views: "pts_dissolve", "LCP_A" arcpy.SelectLayerByLocation_management("pts_dissolve","INTERSECT","LCP_A","400 Feet","ADD_TO_SELECTION")
... View more
05-30-2014
07:29 AM
|
0
|
4
|
629
|
POST
|
Map algebra tools were used in my solution. Thanks Curtis! Here is what worked for me...
# Returns a value of 1 where End_Raster is NoData and 0 End_Raster points.
isNull1 = IsNull(End_Raster)
isNull1.save("isNull1_{0}".format(count))
#Returns LCP minus the end points
#
setNull1 = SetNull(isNull1,get_LCP(count),"Value = 0")
setNull1.save("setNull1_{0}".format(count))
... View more
05-23-2014
07:41 AM
|
0
|
0
|
300
|
POST
|
I believe this method is going to work for me. I will get this syntax in the right places. Thanks Greg!
... View more
05-23-2014
07:15 AM
|
0
|
0
|
375
|
POST
|
You may want to look at chr(). This will return the string version of the numeric value, for example, chr(97) = 'a'. You'd have to look up the value of the character in your encoding and add that to your counter. For example, in ascii, A = 65, B = 66, C = 67...a = 97, b = 98...etc. So in ascii, if your counter starts at 0, add 65 to it so that 0 will become A, 1 will become B, etc. Unicode and other encodings are probably different. Thanks Greg! I am not familiar with these properties. I will spend a little time with the literature and see if I can get something to work. -Noah
... View more
05-13-2014
12:14 PM
|
0
|
0
|
375
|
POST
|
Hi Matt, Thanks for the reply. I probably added to confusion having 6 items in the list. What I am looking for is replacing the count index with the equivalent letter. A instead of 0, B instead of 1, so on and so forth... I hope this helps?
... View more
05-13-2014
11:32 AM
|
0
|
0
|
375
|
Title | Kudos | Posted |
---|---|---|
1 | 11-05-2012 06:00 AM | |
1 | 11-07-2014 12:06 PM | |
1 | 07-02-2014 11:59 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|