1

A colleague made a ArcPy tool for me which worked last year, but now it wont complete. I don't know what's different except maybe I moved the tool or it's output to a new location. It say's it get stuck on line 60, which I think is the code below "#Create bearing distance to line feature". My data seems to be QC'd, in that all of the UTMs should be fine, the bearings are all between 0-359, the pairIDs are all matched (although there is one pair that I deleted, so there is no pairID 41 at all).

Anybody have any tips on what could be the error?

I hope the code looks like it does in notepad, I had to space everything out 4 times like an idiot. Here is the error code btw

Executing: FindIntersectionPointsFromBearings E:\PIJA_GIS\TelObs2017.shp E:\PIJA_GIS\PIJA_Locs.gdb\TelInters2017 Easting Northing Distance_m MILES Bearing12 DEGREES NEWID
Start Time: Fri Oct  5 14:38:22 2018
Running script FindIntersectionPointsFromBearings...
Failed script FindIntersectionPointsFromBearings...

Traceback (most recent call last):
  File "E:\GEOG\PinyonJayProject\ArpyScriptTool\FindIntersectionPointsFromBearings.py", line 60, in <module>
    bearingField, bearingUnits, 'GEODESIC', idField)
  File "c:\arcgisd\desktop10.6\arcpy\arcpy\management.py", line 2488, in BearingDistanceToLine
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000308: Invalid field type
ERROR 000308: Invalid field type
Failed to execute (BearingDistanceToLine).


Failed to execute (FindIntersectionPointsFromBearings).
Failed at Fri Oct  5 14:38:23 2018 (Elapsed Time: 0.96 seconds)

Tool code

#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      jacpete
#
# Created:     31/10/2017
# Copyright:   (c) jacpete 2017
# Licence:     <your licence>
#-------------------------------------------------------------------------------

#Import modules
import arcpy, os
from arcpy import env

#Data files to change paths of
#bring in data to arcpy (the table with all the points

#pointFile = r"E:\PIJA_GIS\PIJA_Locs.gdb\TelemTool\AllPoints"
pointFile = arcpy.GetParameterAsText(0)

#outputFile = r"E:\PIJA_GIS\PIJA_Locs.gdb\TelemTool\IntersectionPoints"
outputFile = arcpy.GetParameterAsText(1)

#xField = "East_Obs"
xField = arcpy.GetParameterAsText(2)

#yField = "North_Obs"
yField = arcpy.GetParameterAsText(3)

#distanceField = "Distance__m_"
distanceField = arcpy.GetParameterAsText(4)

#distanceUnits = "MILES"
distanceUnits = arcpy.GetParameterAsText(5)

#bearingField = "Bearing"
bearingField = arcpy.GetParameterAsText(6)

#bearingUnits = "DEGREES"
bearingUnits = arcpy.GetParameterAsText(7)

#idField = "PairID"
idField = arcpy.GetParameterAsText(8)


#Set up environment
env.overwriteOutput = True


#Set up scratch folder
defScratchGDB = arcpy.env.scratchFolder + os.path.sep + "TempBearingIntersections.gdb"
arcpy.Delete_management(defScratchGDB)
arcpy.CreateFileGDB_management(arcpy.env.scratchFolder, "TempBearingIntersections.gdb")


#Create bearing distance to line feature
lineFile = defScratchGDB + os.path.sep + "LineFile"
arcpy.BearingDistanceToLine_management(pointFile, lineFile, xField, yField, distanceField, distanceUnits, bearingField, bearingUnits, 'GEODESIC', idField)

#create list of unique PairID
uniPairID = []

with arcpy.da.SearchCursor(lineFile, idField) as cursor:
for row in cursor:
    if row[0] not in uniPairID:
        uniPairID.append(row[0])

del row
del cursor


#Make lineFile a layer
lineLyr = defScratchGDB + os.path.sep + "LineLyr"
arcpy.MakeFeatureLayer_management(lineFile, lineLyr)

#Create Feature Dataseta to hold points temporarily
arcpy.CreateFeatureDataset_management(defScratchGDB, "TempMultiPnts", pointFile) ##############
arcpy.CreateFeatureDataset_management(defScratchGDB, "TempSinglePnts", pointFile)

#Create Blanks for list of warning ID's
Under2List = []
Over2List = []
NotIntersectedList = []

#loop pairIDs to select the pair lines
for Pid in uniPairID:

currentPlace = uniPairID.index(Pid) + 1

arcpy.AddMessage("Running: " + str(currentPlace) + "/" + str(len(uniPairID)))

#select features by unique pairID
arcpy.SelectLayerByAttribute_management(lineLyr, "NEW_SELECTION", '"' + idField + '" = ' + str(Pid))

pointCount = int(arcpy.GetCount_management(lineLyr).getOutput(0))

#Check for point pairs
if pointCount < 2:
    #arcpy.AddWarning("Warning: Point Pair ID- " + str(Pid) + " has less than 2 point pairs. It's output is skipped. Check Pair ID" + str(Pid) + " for missing values.")
    Under2List.append(Pid)
elif pointCount > 2:
    #arcpy.AddWarning("Warning: Point Pair ID- " + str(Pid) + " has greater than 2 point pairs. It's output is skipped. Check Pair ID" + str(Pid) + " for extra values.")
    Over2List.append(Pid)
elif pointCount == 2:
    #Intersect selected features with output being a point
    MultiPntFile = (defScratchGDB + os.path.sep + "TempMultiPnts" + os.path.sep + "PID" + str(Pid))
    arcpy.Intersect_analysis(lineLyr, MultiPntFile, output_type = "POINT", join_attributes = "ONLY_FID")

    #Check intersection point file for data
    if int(arcpy.GetCount_management(MultiPntFile).getOutput(0)) == 0:
        #arcpy.AddWarning("Warning: Lines from point pair ID- " + str(Pid) + " did not intersect. Its output is skipped. This could be due to the bearing set or the distance parameter not being large enough.")
        NotIntersectedList.append(Pid)
    else:
        #Convert multipoint to single point
        SinglePntFile =(defScratchGDB + os.path.sep + "TempSinglePnts" + os.path.sep + "FinalPID" + str(Pid))
        arcpy.FeatureToPoint_management(MultiPntFile, SinglePntFile)

        #Delete all but first row
        with arcpy.da.UpdateCursor(SinglePntFile, "OBJECTID") as delCursor:
            for delRow in delCursor:
                if delRow[0] != 1:
                    delCursor.deleteRow()

        ##del delRow
        del delCursor

        #add PairID column to new point file and add Pid
        arcpy.AddField_management(SinglePntFile, idField, "LONG")
        arcpy.CalculateField_management(SinglePntFile, idField, Pid, "PYTHON")


#List files in TempPnts Dataset
env.workspace = defScratchGDB
TempPntsFileList = arcpy.ListFeatureClasses(feature_dataset = "TempSinglePnts")

#Merge Points into One Layer
arcpy.AddMessage("Merging Intersection Points. Almost Done.")
arcpy.Merge_management(TempPntsFileList, outputFile)

#Delete Unneeded Fields
arcpy.DeleteField_management(outputFile, ["FID_LineFile", "ORIG_FID"])

#Final Output Completed Message
arcpy.AddMessage("Output completed. Intersection Point File can be found at: " + outputFile)

#Warning Skipped Point ID Messages
if len(Under2List) != 0:
under2Message = "These Pair ID's are don't have a matching pair: "
if len(Under2List) == 1:
    under2Message = under2Message + str(Under2List[0]) + "."
else:
    for u in range(0, len(Under2List)):
        if u != (len(Under2List) - 1):
            under2Message = under2Message + str(Under2List[u]) + ", "
        else:
            under2Message = under2Message + str(Under2List[u]) + "."
arcpy.AddWarning(under2Message + " Check these Pair ID's for missing values. 
Their output was skipped.")

if len(Over2List) != 0:
over2Message = "These Pair ID's have more than 2 points: "
if len(Over2List) == 1:
    over2Message = over2Message + str(Over2List[0]) + "."
else:
    for u in range(0, len(Over2List)):
        if u != (len(Over2List) - 1):
            over2Message = over2Message + str(Over2List[u]) + ", "
        else:
            over2Message = over2Message + str(Over2List[u]) + "."
arcpy.AddWarning(over2Message + " Check these Pair ID's for extra values. 
Their output was skipped.")

if len(NotIntersectedList) != 0:
NotIntersectedMessage = "These Pair ID's did not have a point that 
intersected as the bearing lines are currently drawn: "
if len(NotIntersectedList) == 1:
    NotIntersectedMessage = NotIntersectedMessage + 
str(NotIntersectedList[0]) + "."
else:
    for u in range(0, len(NotIntersectedList)):
        if u != (len(NotIntersectedList) - 1):
            NotIntersectedMessage = NotIntersectedMessage + 
str(NotIntersectedList[u]) + ", "
        else:
            NotIntersectedMessage = NotIntersectedMessage + 
str(NotIntersectedList[u]) + "."
arcpy.AddWarning(NotIntersectedMessage + " This could be due to the bearings set or the distance parameter not being large enough. Their output was skipped.")`
  • the error indicates that the fields in the input are not of the expected (numeric) type. It occurs at arcpy.BearingDistanceToLine_management(... – JGH Oct 16 '18 at 18:41
0

Your issue is with the arcpy function BearingDistanceToLine_management. The field types for certain input fields are not valid. According to the help these fields need to be numeric fields:

x_field

y_field

bearing_field

distance_units and bearing_units must also be string fields.

Check your pointFile input and fix the field types.

  • You were correct! Thank you! You were the only person who was able to figure that out by the error message! – PIJA Oct 24 '18 at 19:40
  • No problem. Please mark my answer as correct. You’ll be bringing my rep to over 9K 🎉 – Emil Brundage Oct 24 '18 at 19:41
0

I had a similar issue a little while back; see this solution: Write array to CSV inside arc script tool (works in pycharm, doesn't work in arc)

Basically, see if this works:

bearingField = float(arcpy.GetParameterAsText(6))
  • I think you were on the right track! I brought this to someone in real life and they told me that some of my data wasn't numeric. Then when the tool ran, it was able to tell me which lines didn't intersect and therefore couldn't complete. Thank you! – PIJA Oct 24 '18 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.