gpx_reduce.py
changeset 1 5467c893d121
parent 0 8f4668cd868b
child 2 f93786d4f68e
equal deleted inserted replaced
0:8f4668cd868b 1:5467c893d121
    29 '''
    29 '''
    30 
    30 
    31 import datetime
    31 import datetime
    32 import sys
    32 import sys
    33 import time
    33 import time
    34 import pylab as pl
    34 import numpy as sc
    35 import scipy as sc
       
    36 import numpy.linalg as la
    35 import numpy.linalg as la
    37 from math import *
    36 from math import *
    38 from lxml import etree
    37 from lxml import etree
    39 from optparse import OptionParser
    38 from optparse import OptionParser
    40 
    39 
    99     vm = pm - p1
    98     vm = pm - p1
   100     if linel == 0.0:
    99     if linel == 0.0:
   101         return la.norm(vm)
   100         return la.norm(vm)
   102     linem = line / linel
   101     linem = line / linel
   103     
   102     
   104     position = pl.dot(vm, linem) / linel
   103     position = sc.dot(vm, linem) / linel
   105     if position < 0.0:
   104     if position < 0.0:
   106         return la.norm(vm)
   105         return la.norm(vm)
   107     elif position > 1.0:
   106     elif position > 1.0:
   108         return la.norm(pm - p2)
   107         return la.norm(pm - p2)
   109     else:
   108     else:
   226                     distances_squared.append(d_sq)
   225                     distances_squared.append(d_sq)
   227                 else:
   226                 else:
   228                     i1_i2_segment_valid = False
   227                     i1_i2_segment_valid = False
   229                 
   228                 
   230                     # check if connection to any further point i1 is impossible
   229                     # check if connection to any further point i1 is impossible
   231                     d1 = pl.dot(p1 - p2, p1 - p2)
   230                     d1 = sc.dot(p1 - p2, p1 - p2)
   232                     d2 = pl.dot(pm - p2, pm - p2)
   231                     d2 = sc.dot(pm - p2, pm - p2)
   233                     dd = options.max_dist ** 2
   232                     dd = options.max_dist ** 2
   234                     d1d2 = pl.dot(p1 - p2, pm - p2)
   233                     d1d2 = sc.dot(p1 - p2, pm - p2)
   235                     # formula from cosines of point separation angle and cone-opening angles around points
   234                     # formula from cosines of point separation angle and cone-opening angles around points
   236                     if (d1 > dd and d2 > dd and (d1d2 + dd)**2 < (d2 - dd) * (d1 - dd)):
   235                     if (d1 > dd and d2 > dd and (d1d2 + dd)**2 < (d2 - dd) * (d1 - dd)):
   237                         lower_i1_possible = False
   236                         lower_i1_possible = False
   238                         break
   237                         break
   239             
   238             
   381     print 'modified copy written to', ofname
   380     print 'modified copy written to', ofname
   382     
   381     
   383     
   382     
   384     # plot result to screen
   383     # plot result to screen
   385     if options.plot:
   384     if options.plot:
       
   385         import pylab as pl
   386         latm, lonm, elesum = xyz_to_latlonele(sumx, sumy, sumz)
   386         latm, lonm, elesum = xyz_to_latlonele(sumx, sumy, sumz)
   387 
   387 
   388         for trkseg in tracksegs_old:
   388         for trkseg in tracksegs_old:
   389             y_old = []
   389             y_old = []
   390             x_old = []
   390             x_old = []