Ignore:
Timestamp:
08/29/12 00:50:34 (5 years ago)
Author:
jjr8
Message:

Working on enhancements to the CreatePointsAlongLines? tool for bbest.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/SpatialAnalysis/Points.py

    r1029 r1030  
    366366                fieldsToCopy2 = [f.lower() for f in fieldsToCopy] 
    367367                if distanceField is not None and distanceField.lower() in fieldsToCopy2: 
    368                     raise ValueError(_(u'The Distance Travelled Field To Create may not be named %(name)s because that is a field of the input lines that you requested be copied to the points. Please specify a different name for the Distance Travelled Field To Create.') % {u'name': distanceField}) 
     368                    raise ValueError(_(u'The Distance Traveled Field To Create may not be named %(name)s because that is a field of the input lines that you requested be copied to the points. Please specify a different name for the Distance Traveled Field To Create.') % {u'name': distanceField}) 
    369369                if pointTimeField is not None and pointTimeField.lower() in fieldsToCopy2: 
    370370                    raise ValueError(_(u'The Time Field To Create may not be named %(name)s because that is a field of the input lines that you requested be copied to the points. Please specify a different name for the Time Field To Create.') % {u'name': pointTimeField}) 
     
    374374            if distanceField is not None: 
    375375                if pointTimeField is not None and pointTimeField.lower() == distanceField.lower(): 
    376                     raise ValueError(_(u'The Distance Travelled Field To Create field and the Time Field To Create field may not have the same name.')) 
     376                    raise ValueError(_(u'The Distance Traveled Field To Create field and the Time Field To Create field may not have the same name.')) 
    377377                if elapsedField is not None and elapsedField.lower() == distanceField.lower(): 
    378                     raise ValueError(_(u'The Distance Travelled Field To Create field and the Elapsed Time Field To Create field may not have the same name.')) 
     378                    raise ValueError(_(u'The Distance Traveled Field To Create field and the Elapsed Time Field To Create field may not have the same name.')) 
    379379                 
    380380            if pointTimeField is not None and elapsedField is not None and elapsedField.lower() == pointTimeField.lower(): 
     
    418418                    interval *= 0.9144 
    419419                else: 
    420                     raise ValueError(_(u'"%(unit)s" is an unknown linear unit. Please use feet, kilometers, meters, miles, nautical miles, or yards.') % {u'unit': unit}) 
     420                    raise ValueError(_(u'"%(unit)s" is an unknown unit. Please use days, decimal degrees, feet, hours, kilometers, meters, miles, minutes, nautical miles, seconds, or yards.') % {u'unit': unit}) 
    421421 
    422422            # Create the output feature class. 
     423 
     424            Logger.Info(_(u'Creating output feature class %(output)s.') % {u'output': outputFeatureClass}) 
    423425 
    424426            from GeoEco.ArcGIS import GeoprocessorManager 
     
    452454                i += 1 
    453455 
    454             if temporalInterval: 
    455                 outputTable.AddField(u'PointTime', u'datetime') 
     456            if distanceField is not None: 
     457                distanceField = gp.ValidateFieldName(distanceField, outputFeatureClass) 
     458                outputTable.AddField(distanceField, u'float64') 
     459                destFields.append(distanceField) 
     460 
     461            if pointTimeField is not None: 
     462                pointTimeField = gp.ValidateFieldName(pointTimeField, outputFeatureClass) 
     463                outputTable.AddField(pointTimeField, u'datetime') 
     464                destFields.append(pointTimeField) 
     465 
     466            if elapsedField is not None: 
     467                elapsedField = gp.ValidateFieldName(elapsedField, outputFeatureClass) 
     468                outputTable.AddField(elapsedField, u'float64') 
     469                destFields.append(elapsedField) 
    456470 
    457471            # If the caller requested that the remaining distance on a 
     
    472486 
    473487                trackLengths = {} 
     488                trackDurations = {} 
    474489                gotLine = False 
    475490                trackID = None 
     
    489504                            trackIsValid = True 
    490505 
    491                             if temporalInterval: 
    492                                 trackLength = datetime.timedelta(0) 
    493                             else: 
    494                                 trackLength = 0. 
     506                            trackLength = 0. 
     507                            trackDuration = datetime.timedelta(0) 
    495508 
    496509                        if not trackIsValid: 
    497510                            continue 
    498511 
    499                         if temporalInterval: 
     512                        trackLength += cls._GetLineLength(linesSR, unit, selectCursor, temporalInterval) 
     513 
     514                        if startTimeField is not None and endTimeField is not None: 
    500515                            duration = selectCursor.GetValue(endTimeField) - selectCursor.GetValue(startTimeField) 
    501516                            if duration < datetime.timedelta(0): 
    502517                                trackIsValid = False            # The duration of a line is not allowed to be less than zero. We will report a warning about this later. 
    503518                                continue 
    504                             trackLength += duration 
    505                         else: 
    506                             trackLength += cls._GetLineLength(linesSR, unit, selectCursor, temporalInterval) 
     519                            trackDuration += duration 
    507520                finally: 
    508521                    del selectCursor 
     
    510523                if gotLine: 
    511524                    trackLengths[trackID] = trackLength 
     525                    if startTimeField is not None and endTimeField is not None: 
     526                        trackDurations[trackID] = trackDuration 
    512527 
    513528                # Now, for each track, calculate the interval that 
     
    516531                perTrackInterval = {} 
    517532 
    518                 for trackID, length in trackLengths.items(): 
    519                     if temporalInterval: 
     533                if temporalInterval: 
     534                    for trackID, length in trackDurations.items(): 
    520535                        intervalInSeconds = interval.microseconds * 0.000001 + interval.seconds + interval.days * 86400. 
    521536                        lengthInSeconds = length.microseconds * 0.000001 + length.seconds + length.days * 86400. 
     
    524539                        else: 
    525540                            perTrackInterval[trackID] = datetime.timedelta(seconds = lengthInSeconds / (lengthInSeconds // intervalInSeconds + 1)) 
    526  
    527                     elif length % interval == 0: 
    528                         perTrackInterval[trackID] = length / interval 
    529                     else: 
    530                         perTrackInterval[trackID] = length / (length // interval + 1) 
    531  
    532                     Logger.Debug(_(u'Track %r: length = %r, interval = %r') % (trackID, length, perTrackInterval[trackID])) 
     541                        Logger.Debug(_(u'Track %r: length = %r, interval = %r') % (trackID, length, perTrackInterval[trackID])) 
     542                else: 
     543                    for trackID, length in trackLengths.items(): 
     544                        if length % interval == 0: 
     545                            perTrackInterval[trackID] = length / interval 
     546                        else: 
     547                            perTrackInterval[trackID] = length / (length // interval + 1) 
     548                        Logger.Debug(_(u'Track %r: length = %r, interval = %r') % (trackID, length, perTrackInterval[trackID])) 
    533549 
    534550            # Open an insert cursor on the output feature class and a 
     
    552568                            fieldValues[destFields[i]] = selectCursor.GetValue(sourceFields[i]) 
    553569 
    554                         if temporalInterval: 
     570                        if distanceField is not None: 
     571                            fieldValues[distanceField] = None 
     572                        if pointTimeField is not None: 
     573                            fieldValues[pointTimeField] = None 
     574                        if elapsedField is not None: 
     575                            fieldValues[elapsedField] = None 
     576 
     577                        if startTimeField is not None and endTimeField is not None: 
    555578                            startTime = selectCursor.GetValue(startTimeField) 
    556579                            endTime = selectCursor.GetValue(endTimeField) 
     580                            currentTime = startTime 
    557581                        else: 
    558582                            startTime = None 
    559583                            endTime = None 
     584                            currentTime = None 
    560585 
    561586                        # If there are multiple tracks, get the track 
     
    568593                        if trackIDField is not None: 
    569594                            newTrackID = selectCursor.GetValue(trackIDField) 
    570                             if newTrackID != trackID and pointsAtLineEnds and trackIsValid and (temporalInterval and distanceSincePoint > datetime.timedelta(0) or not temporalInterval and distanceSincePoint > 0) and endX is not None: 
     595                            if newTrackID != trackID and pointsAtLineEnds and trackIsValid and (temporalInterval and durationSincePoint > datetime.timedelta(0) or not temporalInterval and distanceSincePoint > 0) and endX is not None: 
    571596                                Logger.Debug('Track %r: Writing end point' % trackID) 
    572                                 cls._InsertPointForLine(endX, endY, endTime, insertCursor, destFields, fieldValues) 
     597 
     598                                if distanceField is not None: 
     599                                    fieldValues[distanceField] = distanceSinceStart 
     600                                if pointTimeField is not None: 
     601                                    fieldValues[pointTimeField] = endTime 
     602                                if elapsedField is not None: 
     603                                    fieldValues[elapsedField] = durationSinceStart 
     604 
     605                                cls._InsertPointForLine(endX, endY, insertCursor, destFields, fieldValues, elapsedUnit) 
    573606 
    574607                        # If this line is the start of a new track, 
     
    582615                            trackIsValid = True 
    583616                            startOfTrack = True 
    584                              
    585                             if temporalInterval: 
    586                                 distanceSincePoint = datetime.timedelta(0) 
    587                             else: 
    588                                 distanceSincePoint = 0. 
     617 
     618                            distanceSinceStart = 0. 
     619                            durationSinceStart = datetime.timedelta(0) 
     620                            distanceSincePoint = 0. 
     621                            durationSincePoint = datetime.timedelta(0) 
    589622 
    590623                            Logger.Debug('Track %r: Started' % trackID) 
    591624 
    592                             # Calculate the distance to the first 
     625                            # Calculate the interval to the first 
    593626                            # point (excluding the point that is on 
    594627                            # the starting end of the line, if the 
    595628                            # caller requested points on the ends). If 
    596629                            # the caller caller requested that the 
    597                             # remaining distance on a track should be 
     630                            # remaining interval on a track should be 
    598631                            # distributed evenly among all points, the 
    599                             # the distance will be specific to this 
     632                            # the interval will be specific to this 
    600633                            # track. If there are points at the line 
    601                             # ends, the distance will simply be the 
     634                            # ends, the interval will simply be the 
    602635                            # track-specific point interval. If not, 
    603636                            # then the distace will be one-half of 
    604637                            # that interval. 
    605638                            # 
    606                             # If the remaining distance should not be 
    607                             # distributed evenly, then the distance to 
     639                            # If the remaining interval should not be 
     640                            # distributed evenly, then the interval to 
    608641                            # the first point is simply the point 
    609642                            # interval requested by the caller. 
     
    611644                            if distributeRemainder: 
    612645                                if pointsAtLineEnds: 
    613                                     distanceToNextPoint = perTrackInterval[trackID] 
     646                                    intervalToNextPoint = perTrackInterval[trackID] 
    614647                                else: 
    615                                     distanceToNextPoint = perTrackInterval[trackID] / 2 
     648                                    intervalToNextPoint = perTrackInterval[trackID] / 2 
    616649                            else: 
    617                                 distanceToNextPoint = interval 
    618  
    619                         # If the remainder of the track is invalid 
    620                         # (because the caller specifeid a temporal 
    621                         # unit and a prior line on this track had a 
    622                         # negative duration), skip this line. 
     650                                intervalToNextPoint = interval 
     651 
     652                        # If the remainder of the track is invalid, 
     653                        # skip this line. 
    623654 
    624655                        if not trackIsValid: 
     
    626657                            continue 
    627658 
    628                         # If the caller specified a temporal unit, 
     659                        # If the caller specified time fields but 
     660                        # either one is NULL, the remainder of this 
     661                        # track is invalid. 
     662                         
     663                        if startTimeField is not None and startTime is None: 
     664                            Logger.Warning(_(u'For the track with %(trackIDField)s of %(trackID)s, the line with %(oid)s of %(value)r has a %(f1)s that is NULL. This is not allowed; it prevents the calculation of the duration of this line. No further points will not be generated along this track.') % {u'trackIDField': trackIDField, u'trackID': str(trackID), u'oid': linesTable.OIDFieldName, u'value': selectCursor.GetOID(), u'f1': startTimeField}) 
     665                            trackIsValid = False 
     666                            continue 
     667                             
     668                        if endTimeField is not None and endTime is None: 
     669                            Logger.Warning(_(u'For the track with %(trackIDField)s of %(trackID)s, the line with %(oid)s of %(value)r has a %(f1)s that is NULL. This is not allowed; it prevents the calculation of the duration of this line. No further points will not be generated along this track.') % {u'trackIDField': trackIDField, u'trackID': str(trackID), u'oid': linesTable.OIDFieldName, u'value': selectCursor.GetOID(), u'f1': endTimeField}) 
     670                            trackIsValid = False 
     671                            continue 
     672 
     673                        # If the caller specified time fields, 
    629674                        # calculate the duration of this line. 
    630675 
    631                         if temporalInterval: 
     676                        if endTime is not None and startTime is not None: 
    632677                            duration = endTime - startTime 
    633                             Logger.Debug('Track %r: Duration of line = %r, distance to next point = %r.' % (trackID, duration, distanceToNextPoint)) 
    634  
    635                             # If the duration is negative, flag this 
    636                             # track as invalid and generate no further 
    637                             # points along it. 
     678                            Logger.Debug('Track %r: Duration of line = %r.' % (trackID, duration)) 
     679 
     680                            # If the duration is zero or negative, 
     681                            # flag this track as invalid and generate 
     682                            # no further points along it. 
    638683                             
    639                             if duration.seconds < 0 and duration.days < 0: 
     684                            if duration <= datetime.timedelta(0): 
    640685                                if trackIDField is None: 
    641                                     Logger.Warning(_(u'The line with %(oid)s of %(value)r has a %(f1)s that is greater than %(f2)s. This is not allowed; it would mean the line had a negative duration. No further points will be generated.') % {u'oid': linesTable.OIDFieldName, u'value': selectCursor.GetOID(), u'f1': startTimeField, u'f2': endTimeField}) 
     686                                    Logger.Warning(_(u'The line with %(oid)s of %(value)r has a %(f1)s that is greater than or equal to %(f2)s. This is not allowed; it would mean the line had a negative or zero duration. No further points will be generated.') % {u'oid': linesTable.OIDFieldName, u'value': selectCursor.GetOID(), u'f1': startTimeField, u'f2': endTimeField}) 
    642687                                else: 
    643                                     Logger.Warning(_(u'For the track with %(trackIDField)s of %(trackID)s, the line with %(oid)s of %(value)r has a %(f1)s that is greater than %(f2)s. This is not allowed; it would mean the line had a negative duration. No further points will not be generated along this track.') % {u'trackIDField': trackIDField, u'trackID': str(trackID), u'oid': linesTable.OIDFieldName, u'value': selectCursor.GetOID(), u'f1': startTimeField, u'f2': endTimeField}) 
     688                                    Logger.Warning(_(u'For the track with %(trackIDField)s of %(trackID)s, the line with %(oid)s of %(value)r has a %(f1)s that is greater than or equal to %(f2)s. This is not allowed; it would mean the line had a negative or zero duration. No further points will not be generated along this track.') % {u'trackIDField': trackIDField, u'trackID': str(trackID), u'oid': linesTable.OIDFieldName, u'value': selectCursor.GetOID(), u'f1': startTimeField, u'f2': endTimeField}) 
    644689                                trackIsValid = False 
    645690                                continue 
    646691 
    647692                            # Divide the length of this line by its 
    648                             # duration to get the rate of travel. Then 
    649                             # multiply this by the temporal distance 
     693                            # duration to get the rate of travel. 
     694 
     695                            rate = cls._GetLineLength(linesSR, unit, selectCursor, temporalInterval) / (duration.microseconds * 0.000001 + duration.seconds + duration.days * 86400.) 
     696 
     697                            # If we are using a temporal interval, 
     698                            # multiply this by the temporal interval 
    650699                            # to the next point to get the spatial 
    651700                            # distance along this line to that point. 
    652701 
    653                             rate = cls._GetLineLength(linesSR, unit, selectCursor, temporalInterval) / (duration.microseconds * 0.000001 + duration.seconds + duration.days * 86400.) 
    654                             spatialDistanceToNextPoint = rate * (distanceToNextPoint.microseconds * 0.000001 + distanceToNextPoint.seconds + distanceToNextPoint.days * 86400.) 
    655  
    656                             Logger.Debug('Track %r: Read new line: rate = %r, spatial distance to next point = %r' % (trackID, rate, spatialDistanceToNextPoint)) 
    657  
    658                         # Iterate through the line's segments. 
     702                            if temporalInterval: 
     703                                distanceToNextPoint = rate * (intervalToNextPoint.microseconds * 0.000001 + intervalToNextPoint.seconds + intervalToNextPoint.days * 86400.) 
     704                                Logger.Debug('Track %r: Rate = %r, temporal interval to next point = %r, spatial distance to next point = %r' % (trackID, rate, intervalToNextPoint, distanceToNextPoint)) 
     705 
     706                        # Iterate through the line's parts. 
    659707 
    660708                        geometry = selectCursor.GetGeometry() 
     
    677725 
    678726                                if startOfTrack and pointsAtLineEnds: 
    679                                     cls._InsertPointForLine(part.GetX(i-1), part.GetY(i-1), startTime, insertCursor, destFields, fieldValues) 
     727                                    if distanceField is not None: 
     728                                        fieldValues[distanceField] = distanceSinceStart     # Will always be 0. 
     729                                    if pointTimeField is not None: 
     730                                        fieldValues[pointTimeField] = startTime 
     731                                    if elapsedField is not None: 
     732                                        fieldValues[elapsedField] = durationSinceStart      # Will always be datetime.timedelta(0) 
     733                                         
     734                                    cls._InsertPointForLine(part.GetX(i-1), part.GetY(i-1), insertCursor, destFields, fieldValues, elapsedUnit) 
    680735                                 
    681736                                startOfTrack = False 
     737 
     738                                # Generate points along this part until the remaining interval on this part is less than 
     739                                # the interval to the next point. 
    682740 
    683741                                currentX = part.GetX(i-1) 
     
    687745 
    688746                                while True: 
     747 
     748                                    # Calculate the spatial distance to the end of this part. 
     749                                     
    689750                                    distanceToEnd = cls._GetDistance(currentX, currentY, endX, endY, linesSR, unit, temporalInterval) 
     751 
     752                                    # If the interval is not temporal (i.e. it is spatial): 
    690753                                     
    691754                                    if not temporalInterval: 
     755 
     756                                        # Check whether the distance to the end of the part is less than the distance to 
     757                                        # the next point. If so, break out of the while loop, so we go on to the next 
     758                                        # part. 
     759                                         
     760                                        if distanceToEnd < intervalToNextPoint: 
     761                                            distanceSincePoint += distanceToEnd 
     762                                            distanceSinceStart += distanceToEnd 
     763                                            intervalToNextPoint -= distanceToEnd 
     764 
     765                                            if endTime is not None and startTime is not None: 
     766                                                delta = datetime.timedelta(seconds=distanceToEnd / rate) 
     767                                                durationSincePoint += delta 
     768                                                durationSinceStart += delta 
     769                                                currentTime += delta 
     770 
     771                                            break 
     772 
     773                                        # The distance to the end of the part is greater than or equal to the distance 
     774                                        # to the next point. We want to create the point. Compute its coords and update 
     775                                        # our accumulators. 
     776 
     777                                        pointX, pointY = cls._GetNextPointCoords(currentX, currentY, endX, endY, intervalToNextPoint, linesSR, unit, temporalInterval) 
     778 
     779                                        distanceSinceStart += intervalToNextPoint 
     780                                        if endTime is not None and startTime is not None: 
     781                                            delta = datetime.timedelta(seconds=intervalToNextPoint / rate) 
     782                                            durationSinceStart += delta 
     783                                            currentTime += delta 
     784 
     785                                    # Otherwise (the interval is temporal): 
     786 
     787                                    else: 
     788 
     789                                        # Although the interval is temporal, we have to proceed along the line in 
     790                                        # spatial coordinates. Previously we used the rate of travel to compute the 
     791                                        # spatial distance to the next point from the temporal interval. Check whether 
     792                                        # the distance to the end of the part is less than the distance to the next 
     793                                        # point. If so, break out of the while loop, so we go on to the next part. 
     794                                         
    692795                                        if distanceToEnd < distanceToNextPoint: 
    693796                                            distanceSincePoint += distanceToEnd 
     797                                            distanceSinceStart += distanceToEnd 
    694798                                            distanceToNextPoint -= distanceToEnd 
     799 
     800                                            delta = datetime.timedelta(seconds=distanceToEnd / rate) 
     801                                            durationSincePoint += delta 
     802                                            durationSinceStart += delta 
     803                                            currentTime += delta 
     804                                            intervalToNextPoint -= delta 
     805 
    695806                                            break 
    696807 
     808                                        # The distance to the end of the part is greater than or equal to the distance 
     809                                        # to the next point. We want to create the point. Compute its coords and update 
     810                                        # our accumulators. 
     811 
    697812                                        pointX, pointY = cls._GetNextPointCoords(currentX, currentY, endX, endY, distanceToNextPoint, linesSR, unit, temporalInterval) 
    698                                         cls._InsertPointForLine(pointX, pointY, None, insertCursor, destFields, fieldValues) 
    699  
    700                                         currentX = pointX 
    701                                         currentY = pointY 
    702  
    703                                         distanceSincePoint = 0 
    704                                         if distributeRemainder: 
    705                                             distanceToNextPoint = perTrackInterval[trackID] 
    706                                         else: 
    707                                             distanceToNextPoint = interval 
    708  
     813 
     814                                        distanceSinceStart += distanceToNextPoint 
     815                                        durationSinceStart += intervalToNextPoint 
     816                                        currentTime += intervalToNextPoint 
     817 
     818                                    # Insert the point and reset the distance and duration accumulators. 
     819 
     820                                    if distanceField is not None: 
     821                                        fieldValues[distanceField] = distanceSinceStart 
     822                                    if pointTimeField is not None: 
     823                                        fieldValues[pointTimeField] = currentTime 
     824                                    if elapsedField is not None: 
     825                                        fieldValues[elapsedField] = durationSinceStart 
     826 
     827                                    cls._InsertPointForLine(pointX, pointY, insertCursor, destFields, fieldValues, elapsedUnit) 
     828 
     829                                    currentX = pointX 
     830                                    currentY = pointY 
     831 
     832                                    distanceSincePoint = 0. 
     833                                    durationSincePoint = datetime.timedelta(0) 
     834 
     835                                    if distributeRemainder: 
     836                                        intervalToNextPoint = perTrackInterval[trackID] 
    709837                                    else: 
    710                                         if distanceToEnd < spatialDistanceToNextPoint: 
    711                                             distanceSincePoint += datetime.timedelta(seconds=distanceToEnd / rate) 
    712                                             distanceToNextPoint -= datetime.timedelta(seconds=distanceToEnd / rate) 
    713                                             spatialDistanceToNextPoint -= distanceToEnd 
    714                                             break 
    715  
    716                                         pointX, pointY = cls._GetNextPointCoords(currentX, currentY, endX, endY, spatialDistanceToNextPoint, linesSR, unit, temporalInterval) 
    717                                         cls._InsertPointForLine(pointX, pointY, endTime - datetime.timedelta(seconds=distanceToEnd / rate) + distanceToNextPoint, insertCursor, destFields, fieldValues) 
    718  
    719                                         currentX = pointX 
    720                                         currentY = pointY 
    721  
    722                                         distanceSincePoint = datetime.timedelta(0) 
    723                                         if distributeRemainder: 
    724                                             distanceToNextPoint = perTrackInterval[trackID] 
    725                                         else: 
    726                                             distanceToNextPoint = interval 
    727                                         spatialDistanceToNextPoint = rate * (distanceToNextPoint.microseconds * 0.000001 + distanceToNextPoint.seconds + distanceToNextPoint.days * 86400.) 
     838                                        intervalToNextPoint = interval 
     839 
     840                                    if temporalInterval: 
     841                                        distanceToNextPoint = rate * (intervalToNextPoint.microseconds * 0.000001 + intervalToNextPoint.seconds + intervalToNextPoint.days * 86400.) 
    728842 
    729843                            if not isMultipart: 
     
    735849                    # the last track, insert the end point. 
    736850                     
    737                     if pointsAtLineEnds and trackIsValid and (temporalInterval and distanceSincePoint > datetime.timedelta(0) or not temporalInterval and distanceSincePoint > 0) and endX is not None: 
     851                    if pointsAtLineEnds and trackIsValid and (temporalInterval and durationSincePoint > datetime.timedelta(0) or not temporalInterval and distanceSincePoint > 0) and endX is not None: 
    738852                        Logger.Debug('Track %r: Writing end point' % trackID) 
    739                         cls._InsertPointForLine(endX, endY, endTime, insertCursor, destFields, fieldValues) 
     853 
     854                        if distanceField is not None: 
     855                            fieldValues[distanceField] = distanceSinceStart + distanceSincePoint 
     856                        if pointTimeField is not None: 
     857                            fieldValues[pointTimeField] = endTime 
     858                        if elapsedField is not None: 
     859                            fieldValues[elapsedField] = durationSinceStart + durationSincePoint 
     860 
     861                        cls._InsertPointForLine(endX, endY, insertCursor, destFields, fieldValues, elapsedUnit) 
    740862 
    741863                finally: 
     
    748870 
    749871    @classmethod 
    750     def _InsertPointForLine(cls, pointX, pointY, pointTime, insertCursor, destFields, fieldValues): 
     872    def _InsertPointForLine(cls, pointX, pointY, insertCursor, destFields, fieldValues, elapsedUnit): 
    751873        from GeoEco.Datasets import CollectibleObject 
    752874        insertCursor.SetGeometry(CollectibleObject._ogr().CreateGeometryFromWkt('POINT(%r %r)' % (pointX, pointY))) 
    753875        for field in destFields: 
    754             insertCursor.SetValue(field, fieldValues[field]) 
    755         if pointTime is not None: 
    756             insertCursor.SetValue(u'PointTime', pointTime) 
     876            if isinstance(fieldValues[field], datetime.timedelta): 
     877                if elapsedUnit == u'days': 
     878                    insertCursor.SetValue(field, float(fieldValues[field].days) + fieldValues[field].seconds / 86400. + fieldValues[field].microseconds / 86400. * 0.000001) 
     879                elif elapsedUnit == u'hours': 
     880                    insertCursor.SetValue(field, fieldValues[field].days * 24. + fieldValues[field].seconds / 3600. + fieldValues[field].microseconds / 3600. * 0.000001) 
     881                elif elapsedUnit == u'minutes': 
     882                    insertCursor.SetValue(field, fieldValues[field].days * 1440. + fieldValues[field].seconds / 60. + fieldValues[field].microseconds / 60. * 0.000001) 
     883                else: 
     884                    insertCursor.SetValue(field, fieldValues[field].days * 86400. + float(fieldValues[field].seconds) + fieldValues[field].microseconds * 0.000001) 
     885            else: 
     886                insertCursor.SetValue(field, fieldValues[field]) 
    757887        insertCursor.InsertRow() 
    758888 
     
    22392369 
    22402370By default, the tool will create a field named Distance on the feature 
    2241 class and populate it with the total distance travelled from the start 
    2242 of the track. The field name is specified by the Distance Travelled 
     2371class and populate it with the total distance traveled from the start 
     2372of the track. The field name is specified by the Distance Traveled 
    22432373Field To Create parameter (under Additional Options). If a temporal 
    22442374unit is specified for the Interval Unit parameter, the distance 
    2245 travelled will be in the units of the underlying coordinate system: 
     2375traveled will be in the units of the underlying coordinate system: 
    22462376either decimal degrees for angular (a.k.a. geographic) coordinate 
    22472377systems, or the linear unit (typically meters) for projected 
    22482378coordinate systems. If a non-temporal unit is specified, the distance 
    2249 travelled will be in that unit. 
     2379traveled will be in that unit. 
    22502380 
    22512381Depending on what you specify for other parameters of the tool, 
     
    24682598    typeMetadata=UnicodeStringTypeMetadata(canBeNone=True), 
    24692599    description=_( 
    2470 u"""Point field to receive the total distance travelled from the start 
     2600u"""Point field to receive the total distance traveled from the start 
    24712601of the track. 
    24722602 
    24732603If a temporal unit is specified for the Interval Unit parameter, the 
    2474 distance travelled will be in the units of the underlying coordinate 
     2604distance traveled will be in the units of the underlying coordinate 
    24752605system: either decimal degrees for angular (a.k.a. geographic) 
    24762606coordinate systems, or the linear unit (typically meters) for 
    24772607projected coordinate systems. If a non-temporal unit is specified, the 
    2478 distance travelled will be in that unit. 
     2608distance traveled will be in that unit. 
    24792609 
    24802610The field will be created with the double-precision floating point 
    24812611data type."""), 
    2482     arcGISDisplayName=_(u'Distance travelled field to create'), 
     2612    arcGISDisplayName=_(u'Distance traveled field to create'), 
    24832613    arcGISCategory=_(u'Additional options')) 
    24842614 
Note: See TracChangeset for help on using the changeset viewer.