AnsweredAssumed Answered

How can I use geometry method snapToLine to find new coordinates?

Question asked by rastrauch Champion on Feb 8, 2016
Latest reply on Feb 10, 2016 by rastrauch

Using 10.3.1.

From Geometry—Help | ArcGIS for Desktop


I'm probably missing something basic here, but given a polyline, and a point do I use snapToLine(in_point) and how do I capture the new point (in a python script)?


I've tested using arcpy.Near_analysis, which will work, but the description sounds more like what I need.  This is a small part of a bigger script.....which I'm now trying using a numpy array.  A general description, given my FC of classified points, I grab the first point...create the contour....snap the point to the contour and split at the point...then go a given distance in each direction along the line, split and create a transect...capture the coordinates at the three points. Previously I had this in Avenue and I'm updating, and adding new features, of course.  There's a bit more to it, but that's a general description for anyone interested.


Fwiw, I'll include my test script (I'll clean it up once I get this figured out...lots of stuff not being used in in this part.)


import os
import numpy as np
from numpy.lib import recfunctions as rfn  
import arcpy
from arcpy import env
from import *
#from ADFGUtils import *
#from gpdecorators import *

# Check out any necessary licenses

# Set the Geoprocessing environment...
initialSR = arcpy.SpatialReference(3338)
geoSR = arcpy.SpatialReference(4269)

theWorkspace = r'C:\_beartest\Prep.gdb'
arcpy.env.workspace = theWorkspace
arcpy.env.overwriteOutput = True    
inStudy = r'C:\_beartest\Prep.gdb\Unit20A_boundary'
arcpy.env.Extent = inStudy

inDEM = r"C:\_beartest\Unit20Araster.gdb\elevExtent"  # clip later or \elevClip ..
rasterGDB, rasterFile = os.path.split(inDEM)
arcpy.env.snapRaster = inDEM
outContour = arcpy.os.path.join(theWorkspace, "c3")
outContour2 = arcpy.os.path.join(theWorkspace, "c4")

inPts = r'C:\_beartest\Prep.gdb\Pts1_3338'   # arcpy.ListFeatureClasses("Pts*3338*", "Point")
minTrans = '5000 Meters'    
maxTrans = '20000 Meters'
length, unit = maxTrans.split(" ")
halfTrans = int(length) / 2
flatOption = "fishnet"    

nearSearchRadius = "1000 Meters"
location = "LOCATION"    
angle = "ANGLE"
tmpPt = arcpy.os.path.join(theWorkspace, "tmpPt")

tmpRoute = arcpy.os.path.join(theWorkspace, "tmpRoute")    

field_names = "*"
arr = arcpy.da.FeatureClassToNumPyArray(inPts, field_names, "", initialSR)
dtypes = arr.dtype
arr2 = (np.array(arr, dtype=dtypes)).view(np.recarray) 

cnt = 0
while  cnt < 10:
    print("{0} PtID {1} elev: {2}".format(cnt, arr2.PtID[cnt], arr2.elev_ft[cnt]))
    transtype = arr2.TransType[cnt]
    ptID = arr2.PtID[cnt]
    elevM = arr2.elev_m[cnt]
    origX = arr2.Shape[cnt][0]
    origY = arr2.Shape[cnt][0]
    if transtype == "Riparian":
        print("this is a Riparian")
    elif cnt == 9:
        print("this is a {0}".format(transtype))
        ContourList(inDEM, outContour, elevM) 
        ptGeom = arcpy.PointGeometry(arcpy.Point(origX, origY, 0, 0, ptID))
        #nearPt = arcpy.Near_analysis(ptGeom, outContour, nearSearchRadius, "LOCATION", "ANGLE")
        #newPt = outContour.snapToLine(ptGeom)
    cnt += 1


variables of interest:  ptGeom, outContour


Hopefully it is something I'm just overlooking.