Ejemplo n.º 1
0
completeQuery = """
    UPDATE """ + config.get('postgres','schema') + "."  + config.get('postgres','sa_fishnet_table') + """ AS sa
    SET 
    state = c.newstate::integer,
    time = c.runtime::float,
    hostname='""" + hostname + """'
    FROM (values
    ('UPDATEVALUES')) AS c(updateid,newstate,runtime)
    WHERE
    sa.id=c.updateid::integer
"""

# connect to database using dbconn connection script
print "Reserving first job"
res = dbconn_quick.run_query(reserveQuery)
print str(len(res)) + " jobs reserved"
count = 0
average = 0

while len(res) > 0:
    resultsToSubmit = []
    for row in res:
        count += 1

        print "Running Area Solar Radiation for row " + str(row['id'])
        start_time = time.clock()

        # add buffer/subtract distance to extent boundaries
        x_min = int(row['xmin']) - buff
        y_min = int(row['ymin']) - buff
Ejemplo n.º 2
0
dem_or_solar = "both"  # dsm, solar, both
######################################################

args = False  # ignore

if (len(sys.argv) < 4 and args):
    print "Usage is exportSolarByCounty <destination_path> <SQL list of counties e.g. ('Watonwan','Ramsey')> <dsm or solar or both>"
else:

    #destdir = sys.argv[1]
    #county = sys.argv[2]
    #dem_or_solar = sys.argv[3]

    county_to_demid = "SELECT countyname AS county, d.id AS demid FROM county c, dem_fishnets d WHERE ST_INTERSECTS(c.the_geom,d.the_geom) AND c.countyname IN " + county + " ORDER BY demid ASC"

    countyres = dbconn_quick.run_query(county_to_demid)

    cur_county = ""
    cur_dem = -1
    for county in countyres:

        if cur_county != county['county']:
            print "Working on county: " + county['county']
            cur_county = county['county']

        try:
            os.makedirs(destdir + county['county'])
            os.makedirs(destdir + county['county'] + '\\Solar')
            os.makedirs(destdir + county['county'] + '\\DSM')
        except OSError as err:
            if err.errno != 17:
#!/usr/bin/env python

import os,subprocess
import glob,dbconn_quick
import os.path
from config import *
import shutil

sourcedir = 'F:\\SolarResourceData\\Final_SRR\\'
destdir = "R:\\SA_Tiles_By_County\\"

county_to_demid = """
SELECT countyname AS county, d.id AS demid FROM county c, dem_fishnets d WHERE ST_INTERSECTS(c.the_geom,d.the_geom) ORDER BY position('Hennepin' IN countyname) DESC 
"""

countyres = dbconn_quick.run_query(county_to_demid)

cur_county = ""
cur_dem = -1
for county in countyres:

    if cur_county != county['county']:
        print "Working on county: " + county['county']
        cur_county = county['county']

    if cur_dem != county['demid']:
        print "\tWorking on DEM tile " + str(county['demid'])
        cur_dem = county['demid']

    try: 
        os.makedirs(destdir + county['county'])
completeQuery = """
    UPDATE """ + config.get('postgres', 'schema') + "." + config.get(
    'postgres', 'sa_fishnet_table') + """ AS sa
    SET 
    state = c.newstate::integer,
    time = c.runtime::float,
    hostname='""" + hostname + """'
    FROM (values
    ('UPDATEVALUES')) AS c(updateid,newstate,runtime)
    WHERE
    sa.id=c.updateid::integer
"""

# connect to database using dbconn connection script
print "Reserving first job"
res = dbconn_quick.run_query(reserveQuery)
print str(len(res)) + " jobs reserved"
count = 0
average = 0

while len(res) > 0:
    resultsToSubmit = []
    for row in res:
        count += 1

        print "Running Area Solar Radiation for row " + str(row['id'])
        start_time = time.clock()

        # add buffer/subtract distance to extent boundaries
        x_min = int(row['xmin']) - buff
        y_min = int(row['ymin']) - buff
Ejemplo n.º 5
0
gdal_merge = "python.exe D:\\Scripts\\bin\\gdal\\python\\scripts\\gdal_merge.py"

os.environ['GDAL_DRIVER_PATH'] = "D:\\Scripts\\bin\\gdal\\plugins"
os.environ['GDAL_DATA'] = "D:\\Scripts\\bin\\gdal-data"

reserveq = """SELECT id FROM dem_fishnets ORDER BY id"""

satileq = """
SELECT sa.id FROM sa_fishnets sa,dem_fishnets dem WHERE
dem.id=DEMID AND
st_contains(dem.the_geom,sa.the_geom)
"""

cmds = ""

res = dbconn_quick.run_query(reserveq)
rownum = 0
bat = open("merge_sa_tiles.bat", "w")

for row in res:
    rownum += 1
    demid = str(row['id'])

    print "On row " + str(rownum) + " (" + demid + ")"

    outputfile = samergedbase + demid + '.img'

    if not os.path.isfile(outputfile):

        satilesres = dbconn_quick.run_query(satileq.replace('DEMID', demid))
        tilepaths = []
Ejemplo n.º 6
0
gdal_merge = "python.exe D:\\Scripts\\bin\\gdal\\python\\scripts\\gdal_merge.py"

os.environ['GDAL_DRIVER_PATH'] = "D:\\Scripts\\bin\\gdal\\plugins"
os.environ['GDAL_DATA'] = "D:\\Scripts\\bin\\gdal-data"

reserveq = """SELECT id FROM dem_fishnets ORDER BY id"""

satileq = """
SELECT sa.id FROM sa_fishnets sa,dem_fishnets dem WHERE
dem.id=DEMID AND
st_contains(dem.the_geom,sa.the_geom)
"""

cmds = ""

res = dbconn_quick.run_query(reserveq)
rownum = 0
bat = open("merge_sa_tiles.bat","w")

for row in res:
    rownum += 1
    demid = str(row['id'])

    print "On row " + str(rownum) + " (" + demid + ")"

    outputfile = samergedbase + demid + '.img'

    if not os.path.isfile(outputfile):

        satilesres = dbconn_quick.run_query(satileq.replace('DEMID',demid))
        tilepaths = []