Exemplo n.º 1
0
    def saveTracks(self, filename):    
        driverName = "GeoJSON"
        driver = ogr.GetDriverByName(driverName)

        if driver is None:
            logger.error("%s driver not available." % driverName)
            return        
        # Create the output GeoJSON
        outDataSource = driver.CreateDataSource(filename)
        
        if outDataSource is None:
            logger.error('Could not create file %s' % filename)
            return
        
        srs = osr.SpatialReference()
        srs.ImportFromEPSG(4326)        
        
        outLayer = outDataSource.CreateLayer('tracks', srs, ogr.wkbLineString, ["COORDINATE_PRECISION=6","WRITE_BBOX=YES"] )
        
        field_color = ogr.FieldDefn("color", ogr.OFTString)
        field_color.SetWidth(12)
        outLayer.CreateField(field_color)
        outLayer.CreateField(ogr.FieldDefn("opacity", ogr.OFTReal))
        outLayer.CreateField(ogr.FieldDefn("weight", ogr.OFTReal))
        outLayer.CreateField(ogr.FieldDefn("opacity", ogr.OFTReal))
        field_popup = ogr.FieldDefn("popup", ogr.OFTString)
        field_popup.SetWidth(128)
        outLayer.CreateField(field_popup)
                
        for i, t in enumerate(self.tracks):
            outFeature = ogr.Feature(outLayer.GetLayerDefn())

            outFeature.SetField("weight", DEFAULT_LINE_WIDTH)
            outFeature.SetField("opacity", 0.9)
            outFeature.SetField("color", track_colors_karkonosze[i])
            outFeature.SetField("popup", self.track_names[i])

            geom2180 = tools.from4326to2180(t)
            geom2180s = geom2180.Simplify(10)

            # Set new geometry
            outFeature.SetGeometry(tools.from2180to4326(geom2180s))
            
            # Add new feature to output Layer
            outLayer.CreateFeature(outFeature)
            outFeature.Destroy()

        logger.info('%d tracks saved to ''%s''' % (len(self.tracks), os.path.basename(filename)))   
        outDataSource.Destroy()
Exemplo n.º 2
0
def _saveSimpleTrack(outLayer, geom, srs, popup, color="#4385f5"):
    
    outFeature = ogr.Feature(outLayer.GetLayerDefn())

    outFeature.SetField("color", color)
    outFeature.SetField("weight", DEFAULT_LINE_WIDTH)
    outFeature.SetField("opacity", 0.9)
    outFeature.SetField("popup", popup)
        
    # Set new geometry
    outFeature.SetGeometry(tools.from2180to4326(geom))
    
    # Add new feature to output Layer
    outLayer.CreateFeature(outFeature)
    outFeature.Destroy()
Exemplo n.º 3
0
    def saveSlices2GeoJson(filename, sliced_track):

        # Create the output Driver
        outDriver = ogr.GetDriverByName('GeoJSON')
        
        # Create the output GeoJSON
        outDataSource = outDriver.CreateDataSource(filename)
        
        if outDataSource is None:
            print 'Could not create file'
        
        srs = osr.SpatialReference()
        srs.ImportFromEPSG(4326)        
        
        outLayer = outDataSource.CreateLayer('track', srs, ogr.wkbLineString )
        
        field_color = ogr.FieldDefn("color", ogr.OFTString)
        field_color.SetWidth(12)
        outLayer.CreateField(field_color)
        outLayer.CreateField(ogr.FieldDefn("opacity", ogr.OFTReal))
        outLayer.CreateField(ogr.FieldDefn("section", ogr.OFTInteger))
        
        i=0;
        for line in sliced_track:
            # create a new feature
            outFeature = ogr.Feature(outLayer.GetLayerDefn())

            outFeature.SetField("opacity", 0.8)
            outFeature.SetField("section", i%2==0)
            
            if (i%2==0):
                outFeature.SetField("color", '#e51c55')
            else:
                outFeature.SetField("color", '#800f31')
                
            # Set new geometry
            outFeature.SetGeometry(tools.from2180to4326(line))
            
            # Add new feature to output Layer
            outLayer.CreateFeature(outFeature)
            outFeature.Destroy
            
            i += 1
        
        # Close DataSources
        outDataSource.Destroy()
Exemplo n.º 4
0
    def saveMileage2GeoJson(filename, mileage):
        driverName = "GeoJSON"
        driver = ogr.GetDriverByName(driverName)

        if driver is None:
            logger.error("%s driver not available." % driverName)
            return        
        # Create the output GeoJSON
        outDataSource = driver.CreateDataSource(filename)
        
        if outDataSource is None:
            logger.error('Could not create file %s' % filename)
            return
        
        srs = osr.SpatialReference()
        srs.ImportFromEPSG(4326)        
        
        outLayer = outDataSource.CreateLayer('mileage', srs, ogr.wkbLineString )
        
        field_color = ogr.FieldDefn("color", ogr.OFTString)
        field_color.SetWidth(12)
        outLayer.CreateField(field_color)
        outLayer.CreateField(ogr.FieldDefn("size", ogr.OFTReal))
        
        i=0;
        for point in mileage:
            # create a new feature
            outFeature = ogr.Feature(outLayer.GetLayerDefn())

            outFeature.SetField("color", '#e51c55')
            outFeature.SetField("size", 4)
                
            # Set new geometry
            outFeature.SetGeometry(tools.from2180to4326(point))
            
            # Add new feature to output Layer
            outLayer.CreateFeature(outFeature)
            outFeature.Destroy
            
            i += 1
        
        # Close DataSources
        outDataSource.Destroy()
        logger.info('%d mileage point written to %s' % (i, filename))
Exemplo n.º 5
0
def _saveMileage(outLayer, points, srs, distance, color="#4385f5"):
    color_first = "#ffe168"
    color_last = "#f48159"

    for i, pt in enumerate(points):
        rr = DEFAULT_LINE_WIDTH-2
        cc = color
        fc = color_first
         
        pp = "%dkm" % (i*distance/1000)
         
        if i == 0:
            cc = fc = color_first
            rr = DEFAULT_START_STOP_SIZE
            pp = "start"
        elif i == len(points) - 1:
            cc = fc = color_last
            rr = DEFAULT_START_STOP_SIZE
            pp = "koniec"
        
        outFeature = ogr.Feature(outLayer.GetLayerDefn())
    
        outFeature.SetField("radius", rr)
        outFeature.SetField("color", cc)
        outFeature.SetField("fillColor", fc)
        outFeature.SetField("weight", 2)
        outFeature.SetField("opacity", 0.9)
        outFeature.SetField("fillOpacity", 0.9)

        outFeature.SetField("popup", pp)

            
        # Set new geometry
        outFeature.SetGeometry(tools.from2180to4326(pt))
        
        # Add new feature to output Layer
        outLayer.CreateFeature(outFeature)
        outFeature.Destroy

    logger.info('%d mileage points written.' % len(points))
Exemplo n.º 6
0
 def getPointAtTimestamp(self, tstamp):
     
     for i in range(len(self.trackpoints)-1):
         if (self.trackpoints[i].timestamp <= tstamp and  self.trackpoints[i+1].timestamp >= tstamp):
             
             delta = (self.trackpoints[i+1].timestamp - self.trackpoints[i].timestamp).total_seconds()
             
             if delta <= 1 :
                 return self.trackpoints[i].point2180.Clone()
             
             r = (tstamp - self.trackpoints[i].timestamp).total_seconds() / delta
             tp1 = self.trackpoints[i].point2180
             tp2 = self.trackpoints[i+1].point2180
             xr = tp1.GetX() + r * (tp2.GetX() - tp1.GetX())
             yr = tp1.GetY() + r * (tp2.GetY() - tp1.GetY())
             
             point = ogr.Geometry(ogr.wkbPoint)
             point.AddPoint(xr, yr)
             
             return tools.from2180to4326(point)
     
     return None