Пример #1
0
#                             "coords" :  [[float(seg[0]),float(seg[1])],
#                                          [float(seg[2]),float(seg[3])]] } )
#                upnodes = r.lrange(node, 0, -1)
#                ordtoggle = False
#		for item in upnodes:
#                    if ordtoggle:
#                        if int(item) >= order:
#                           q.put(lastnode)
#                    else:
#                        lastnode = item    
#		    ordtoggle = not ordtoggle
#        return { "Upstream" : maplist }




if __name__ == '__main__':
#	t = { 1 : [2, 3], 2 : [4, 5], 3 : [6], 4 : [], 5 : [], 6 : [] }
#	bfs(t, 1)
#       maps = loadmaps("NigerShapefiles/NigerRiverDict")
#       print traverse(maps, 220)
        print 'Loading cPickle map'
	bigmap = loadmaps(Const.DICTIONARY)
	print traverseStrahler(bigmap, 1640, 5)  # this should be the same
	print subbasinPerimeter(bigmap, 1640, 5)
#       print 'Connecting to redis'
##	r = redis.StrictRedis(host='localhost', port=6379, db=0)
#       print 'Traversal 1'
#       print traverseStrahlerRedis(r, 220, 7)
#       print traverseStrahlerRedis(r, 1650, 7)
Пример #2
0
import sys
import numpy  # for array
#import redis
from flask import Flask
from subprocess import Popen, PIPE
from reverseproxied import ReverseProxied
from string import rstrip
from random import randrange, shuffle
from preprocess import loadmaps
from bfs import traverse, traverseStrahler, subbasinPerimeter
from idmap import IDmap
from histogram import histogram

# redis appears to be slower than loading maps from
# cPickle!
myMaps = loadmaps(Const.DICTIONARY)

# Use redis 2.6+. Redis 2.4.9 (used by cartodb) does not support StrictRedis().
#r     = redis.StrictRedis(host='localhost', port=6379, db=0)

myIDmap = IDmap(Const.DATABASE, Const.FIELDS)

app = Flask(__name__)
app.wsgi_app = ReverseProxied(app.wsgi_app)


def cell2json(cell, name, fld):
    #   print "cell2json cell type:", type(cell)
    return json.dumps({name: myIDmap.field(cell, fld)})

Пример #3
0
#    print count
#    if count == 1:
#      print 'Intersection succeeds'
#      polygon = intersection

  ring = polygon.GetGeometryRef(0)
  points = ring.GetPointCount()
  # Convert to list
  subbasin = []
  for p in xrange(points):
    lon, lat,  _ = ring.GetPoint(p)
    subbasin.append([lat, lon])  # note reversal to lat lon!
  return { 'polygon': subbasin }





if __name__ == '__main__':
        print 'Loading cPickle map'
	bigmap = loadmaps(Const.DICTIONARY)
#	print 'traversal'
#	print traverseStrahler(bigmap, 1640, 5)  # this should be the same
	print 'perimeter'
	print subbasinPerimeter(bigmap, 1727, 1)
#       print 'Connecting to redis'
##	r = redis.StrictRedis(host='localhost', port=6379, db=0)
#       print 'Traversal 1'
#       print traverseStrahlerRedis(r, 220, 7)
#       print traverseStrahlerRedis(r, 1650, 7)
Пример #4
0
	    index = int((value-mini)/width)
	    if index >= bins:
		index = bins-1  # index correction -- this happens at the last interval
	    frequencies[index] += 1
	    IDValBinList.append((ID, value, index))    
	return (count, frequencies, endpoints, IDValBinList)

def	histogram(maps, myIDmap, key, order, myField, bins):
	"""Returns count, freq array, bin endpints, (ID, Value, Bin) list"""
	return _histo2(_histo1(maps, myIDmap, key, order, myField, bins))

if __name__ == '__main__':
#	t = { 1 : [2, 3], 2 : [4, 5], 3 : [6], 4 : [], 5 : [], 6 : [] }
#	bfs(t, 1)
        print 'Loading cPickle map'
	maps = loadmaps(Const.DICTIONARY)
	print 'cPickle map loaded'
        print _traverseStrahler(maps, 7549, 5)
	print 'loading IDmap'
	myIDmap = IDmap(Const.DATABASE, Const.FIELDS)
#	print 'testing 1st pass of histogram'
#	arglist =  _histo1(maps,myIDmap, 7549, 5, 'GRUMP_Pop_2000',5) 
#	print arglist
#	print 'testing 2nd pass of histogram'
#	count, frequencies, endpoints, _ = _histo2(arglist)
#	print _histo2(arglist)
	import numpy
	import pylab as p
#	count, frequencies, endpoints, _ = histogram(maps, myIDmap, 202, 3, 'GRUMP_Pop_2000', 50)
# bad field produces error case of 0 1 1 -9999.0 -9999.0
#	count, frequencies, endpoints, _ = histogram(maps, myIDmap, 202, 3, 'runoff_10', 50)