langsam bin ich mit meinem Latein am ende... habe selber in arcgis(geografische Informationssoftware) polylinien digitalisiert und möchte Entferungen der einzelnen Koordinaten einer Polylinie berechnen. Basiert alles auf dem sog. WGS84-Ellipsoid.
Was ich nicht verstehe, warum die unten markierte Schleife exakt immer ZWEIMAL durchlaufen wird und der nächste Datensatz(es sind mehr als zwei) nich auch berechnet wird, kann da kein logikfehler erkennen... die folgenden polylinien in dem shapefile sind haargenau vom selben typ wie die ersten beiden.
Code: Alles auswählen
# -*- coding: cp1252 -*-
import arcgisscripting, math
gp = arcgisscripting.create(9.3)
gp.Workspace = r"C:\Users\XXX\Desktop\pipeline_shape\\"
fc = "eigene_pipes.shp"
desc = gp.Describe(fc)
rows = gp.SearchCursor(fc)
row = rows.Next()
feat = row.shape
line_x = [] #Neue Liste für X-Koordinaten
line_y = [] #Neue Liste für Y-Koordinaten
line_xy = [line_x,line_y]
distanzen = []
def polyline(): #Funktion um die einzelnen Koordinaten(X,Y) zu bekommen und zu speichern
a = 0
while a < feat.PartCount:
array = feat.GetPart(a)
array.Reset
pnt = array.Next()
#print pnt
while pnt:
print pnt.x, pnt.y
line_x.append(pnt.x)
line_y.append(pnt.y)
pnt = array.Next()
a = a + 1
def berechnung(): #Formel für Entferungsmessung basierend auf dem WGS84-Ellipsoid
pi = 3.14159265
f = 0.003352811
a = 6378.137
F = (line_x[0]+line_x[1])/2.0
G = (line_x[0]-line_x[1])/2.0
l = (line_y[0]-line_y[1])/2.0
#print "F: "+str(F),"G: "+str(G),"l: "+str(l)
#Umrechnung in Bogenmaß (Radiant),Python erwartet sin,cos wert als radiant/bogenmaß
F = (pi/180.0)*F
G = (pi/180.0)*G
l = (pi/180.0)*l
#print "F: "+str(F),"G: "+str(G),"l: "+str(l)
S = (math.sin(G)*math.sin(G))*(math.cos(l)*math.cos(l)) + (math.cos(F)*math.cos(F))*(math.sin(l)*math.sin(l))
#print "S: "+str(S)
C = (math.cos(G)*math.cos(G))*(math.cos(l)*math.cos(l)) + (math.sin(F)*math.sin(F))*(math.sin(l)*math.sin(l))
#print "C: "+str(C)
w = math.atan(math.sqrt(S/C))
#print "w: "+str(w)
D = 2.0*w*a
#print "D: "+str(D)
R = (math.sqrt(S*C))/w
#print "R: "+str(R)
H1 = (3.0*R-1)/(2.0*C)
#print "H1: "+str(H1)
H2 = (3.0*R+1)/(2.0*S)
#print "H2: "+str(H2)
dist = D*(1.0 + f*H1*((math.sin(F)*math.sin(F)))*(math.cos(G)*math.cos(G))) - (f*H2*(math.cos(F)*math.cos(F))*(math.sin(G)*math.sin(G)))
print "Distanz: "+str(round(dist))+" km"
distanzen.append(dist)
for xy in line_xy:
b = 0
polyline()
while b == 0:
berechnung()
line_x.remove(line_x[0]) #erste indexposition löschen, damit nächster abstand berechnet werden kann
line_y.remove(line_y[0])
if len(line_x) == 1:
line_x.remove(line_x[0]) #Liste leeren für nächste Polyline
line_y.remove(line_y[0])
b = b + 1
row = rows.Next()
distanzen.sort()
print distanzen[0:]
distanzen.reverse()
print distanzen[0:]

Ausgabe ungefähr so:
x,y
x,y
x,y
x,y
Distanz: 123.44 km
Distanz: 432.22 km
Distanz: 12.44 km
Distanz: 65.22 km
[12.44,65.22,123.44,432.22]
.
.
.
.