示例#1
0
        print sql
        sys.exit()

    if verbose:
        print sql
    cu.execute(sql)

    tracksFile = file(basename+'-tracks.dat','w')
    trackNum = 0
    for trackline in cu.fetchall():
        trackNum+=1
        if trackNum % 50 == 0:
            sys.stderr.write('track '+str(trackNum)+'\n')

        track = trackline[0];           #print track
        trackseq = grid.wktLine2list(track);  #print trackseq
        if verbose:
            print 'len',len(trackseq)
            if len(trackseq)<2:
                print 'TOO SHORT: ',track
                sys.exit('crap')
        for pt in trackseq:
            tracksFile.write(str(pt[0])+' '+str(pt[1])+' 0\n')
        #cells = getMultiSegLineCells(bbox,step,trackseq,verbose)
        #print cells
        g.addMultiSegLine(trackseq)

    tracksFile.write('\n')

    g.writeCellsGnuplot(basename+'-cells.dat')
    g.writeArcAsciiGrid(basename+'-grd.asc')
示例#2
0
def main():
    parser = get_parser()
    (options, args) = parser.parse_args()
    verbose = options.verbose
    options_dict = vars(options)

    #print options

    assert options.x_min < options.x_max
    assert options.y_min < options.y_max

    zone = lon_to_utm_zone(options.x_min)
    assert (zone == lon_to_utm_zone(options.x_max))

    params = {'proj': 'utm', 'zone': int(zone)}
    proj = Proj(params)

    ll = proj(options.x_min, options.y_min)
    ur = proj(options.x_max, options.y_max)

    g = grid.Grid(ll[0], ll[1], ur[0], ur[1],
                  stepSize=options.step)  # , verbose=options.verbose)
    basename = options.basename
    g.writeLayoutGnuplot(basename + '-grd.dat')

    # Make sure they are all numbers
    #[int(track) for track in args]
    #tracks = ','.join(args)
    tracks = args

    connectStr = "dbname='{database_name}' user='******' host='{database_host}'".format(
        **options_dict)
    if verbose:
        print 'CONNECT:', connectStr
    cx = psycopg.connect(connectStr)
    cu = cx.cursor()

    print 'FIX: lookup EPSG for UTM zone here rather than hardcoding'

    if options.tracks_file is not None:
        for line in file(options.tracks_file):
            #more_tracks = [int(t) for t in line.split()]
            for item in line.split():
                tracks.append(int(item))

    #cu.execute('SELECT AsText(Transform(track,32619)) FROM tpath WHERE id IN ('+tracks+');')
    #for track_count,track_wkt in enumerate(cu.fetchall()):
    for track_count, track_id in enumerate(tracks):
        if track_count % 200 == 0:
            print 'track_count:', track_count

        cu.execute(
            'SELECT AsText(Transform(track,32619)) FROM tpath WHERE id=%d;' %
            (int(track_id), ))
        track_wkt = cu.fetchone()[0]
        trackseq = grid.wktLine2list(track_wkt)
        if len(trackseq) < 2:
            print 'TOO SHORT: ', track_count, len(trackseq)
            sys.exit('crap')
        g.addMultiSegLine(trackseq)

    print 'track_count:', track_count

    g.writeCellsGnuplot(basename + '-cells.dat')
    g.writeArcAsciiGrid(basename + '-grd.asc')
def main():
    parser = get_parser()
    (options,args) = parser.parse_args()
    verbose = options.verbose
    options_dict = vars(options)


    #print options

    assert options.x_min < options.x_max
    assert options.y_min < options.y_max

    zone = lon_to_utm_zone(options.x_min)
    assert (zone == lon_to_utm_zone(options.x_max) )

    params={'proj':'utm','zone':int(zone)}
    proj = Proj(params)

    ll = proj(options.x_min,options.y_min)
    ur = proj(options.x_max,options.y_max)
    
    g = grid.Grid(ll[0],ll[1], ur[0],ur[1], stepSize=options.step)# , verbose=options.verbose)
    basename=options.basename
    g.writeLayoutGnuplot(basename+'-grd.dat')

    # Make sure they are all numbers
    #[int(track) for track in args]
    #tracks = ','.join(args)
    tracks = args

    connectStr = "dbname='{database_name}' user='******' host='{database_host}'".format(**options_dict)
    if verbose:
        print 'CONNECT:',connectStr
    cx = psycopg.connect(connectStr)
    cu = cx.cursor()

    print 'FIX: lookup EPSG for UTM zone here rather than hardcoding'
    
    if options.tracks_file is not None:
        for line in file(options.tracks_file):
            #more_tracks = [int(t) for t in line.split()]
            for item in line.split():
                tracks.append(int(item))

    #cu.execute('SELECT AsText(Transform(track,32619)) FROM tpath WHERE id IN ('+tracks+');')
    #for track_count,track_wkt in enumerate(cu.fetchall()):
    for track_count, track_id in enumerate(tracks):
        if track_count % 200==0:
            print 'track_count:',track_count
        
        cu.execute('SELECT AsText(Transform(track,32619)) FROM tpath WHERE id=%d;' %(int(track_id),) )
        track_wkt=cu.fetchone()[0]
        trackseq = grid.wktLine2list(track_wkt);
        if len(trackseq)<2:
            print 'TOO SHORT: ',track_count, len(trackseq)
            sys.exit('crap')
        g.addMultiSegLine(trackseq)

    print 'track_count:',track_count

    g.writeCellsGnuplot(basename+'-cells.dat')
    g.writeArcAsciiGrid(basename+'-grd.asc')
示例#4
0
        sys.exit()

    if verbose:
        print sql
    cu.execute(sql)

    tracksFile = file(basename + '-tracks.dat', 'w')
    trackNum = 0
    for trackline in cu.fetchall():
        trackNum += 1
        if trackNum % 50 == 0:
            sys.stderr.write('track ' + str(trackNum) + '\n')

        track = trackline[0]
        #print track
        trackseq = grid.wktLine2list(track)
        #print trackseq
        if verbose:
            print 'len', len(trackseq)
            if len(trackseq) < 2:
                print 'TOO SHORT: ', track
                sys.exit('crap')
        for pt in trackseq:
            tracksFile.write(str(pt[0]) + ' ' + str(pt[1]) + ' 0\n')
        #cells = getMultiSegLineCells(bbox,step,trackseq,verbose)
        #print cells
        g.addMultiSegLine(trackseq)

    tracksFile.write('\n')

    g.writeCellsGnuplot(basename + '-cells.dat')