I wonder if we have an easier solution on this topic since it's 10 years later and Arc Pro is here.
import arcpy, time # Define a function to 'handle' 2 input point XYZ coords, computing the distance between. def Dist3d(x1,y1,z1,x2,y2,z2): deltaX = x1 - x2 deltaY = y1 - y2 deltaZ = z1-z2 distance = (deltaX**2 + deltaY**2 + deltaZ**2)**0.5 return distance # Your shapefile (change the pathname accordingly). shp = r'F:\Well_Bore\Well_Bore.shp' # The point distance of interest, in this case, 10170.0 ptDistOfInterest = 10170.0 # Open a cursor, fetching the 1st row feature geometry. rows = arcpy.SearchCursor(shp) row = rows.next() feat = row.Shape # Listing a few properties, just curious... # For the line feat in this thread: print feat.type # prints 'polyline' print feat.isMultipart # prints 'False' print feat.partCount # prints '1' print feat.length # prints '7034.13303256' print feat.length3D # prints '16108.56262561997' pointBgn = feat.firstPoint print pointBgn.Z # prints '0.0' pointEnd = feat.lastPoint print pointEnd.Z # prints '-9381.4961999999941' # The 'getPart' method returns an array of points. theGeomPtArray = feat.getPart(0) print theGeomPtArray.count # prints '197' # Initializing a cumulative distance variable. cumulativeD = 0.0 # Looping on the array, computing the distances, breaking at 10170.0... for i in range(theGeomPtArray.count - 1): pt1 = theGeomPtArray.getObject(i) pt2 = theGeomPtArray.getObject(i + 1) x1,x2 = pt1.X, pt2.X y1,y2 = pt1.Y, pt2.Y z1,z2 = pt1.Z, pt2.Z cumulativeD += Dist3d(x1, y1, z1, x2, y2, z2) if cumulativeD > ptDistOfInterest: k = i break # Need to know the break point: print k # prints '124' # Need to know the current cumulative distance: print cumulativeD # prints '10193.8322556' # Need to fetch the 2 point objects from the array. # The point distance specified is on this segment. ptBrk = theGeomPtArray.getObject(k) print ptBrk.X, ptBrk.Y, ptBrk.Z # (2059018.4176586419, 254935.63821481168, -9491.9726999999984) ptBrkNext = theGeomPtArray.getObject(k+1) print ptBrkNext.X, ptBrkNext.Y, ptBrkNext.Z # (2059003.0216920525, 254967.06695772707, -9491.7893999999942) # Assign to vars to pass to the dist function... x1,y1,z1 = ptBrkNext.X, ptBrkNext.Y, ptBrkNext.Z x2,y2,z2 = ptBrk.X, ptBrk.Y, ptBrk.Z segDistance = Dist3d(x1, y1, z1, x2, y2, z2) print segDistance # prints '34.9976465974' # The break in the loop exit value for cumulativeD included the segment. # ...so the current segment has to be 'backed off' (subtracted). priorDist = cumulativeD - segDistance print priorDist # prints '10158.834609' # Then, the distance to add from prior point: addDist = 10170.0 - priorDist print addDist # prints '11.1653910146' # And with that, we compute the proportion for interpolation... proportion = addDist/segDistance print proportion # prints '0.319032623624' # Proceed with the interpolation - X, Y, and Z: Xonseg = proportion*(x1 - x2) + x2 Yonseg = proportion*(y1 - y2) + y2 Zonseg = proportion*(z1 - z2) + z2 # This is your point of interest, the coordinates: print Xonseg # prints '2059013.5058430277' print Yonseg # prints '254945.66500912118' print Zonseg # prints '-9491.91422132' # Pause in order to read the output. time.sleep(10)
# Additional code, append the result to WellPointZM, # for visual inspection purposes of the above code. WellPointZM = r'F:\Well_Bore\WellPointZM.shp' # First create a pt obj, using coordinates. # This uses coords computed in previous code above... pnt = arcpy.Point(Xonseg, Yonseg, Zonseg) insertPt = arcpy.InsertCursor(WellPointZM) addPT = insertPt.newRow() addPT.Shape = pnt insertPt.insertRow(addPT) del insertPt # the cursor to 'unlock'
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.