示例#1
0
def start_available_job():
    # Updates the earliest job from status 0 to status 1, and returns the gis of the updated row. Returns nothing
    # if no pending jobs are available.
    sql = """update job set status = 1
        where gid in (select min(gid) from job where status = 0)
        returning gid"""
    result = None
    current_job = db.exec_sql(sql, [], True)
    if type(current_job) is tuple:
        result = current_job[0]
    return result
示例#2
0
def complete_job(job_id, town_id, map_url):
    sql = "update job set status = 2 where job_id = %s"
    db.exec_sql(sql, [job_id])
示例#3
0
def add_map_layer(job_id, layer_name, map_url):
    sql = "insert into map_layer (job_id, town_id, name, url) values (%s, (select max(town_id) from job where gid=%s), %s, %s)"
    db.exec_sql(sql, [job_id, job_id, layer_name, map_url])
示例#4
0
def update_job_status(job_id, status):
    # Returns the status of the tilees in the job, count grouped by status
    sql = "update job set status=%s where gid=%s"
    db.exec_sql(sql, [status, job_id])
示例#5
0
    def run_next_job(self):
        # Updates the earliest job from status 0 to status 1, and returns the gid of the updated row. Returns nothing
        # if no pending jobs are available.
        sql = """update job set status = 'in progress'
            where gid in (select min(gid) from job where status = 'ready')
            returning gid"""
        current_job = db.exec_sql(sql, [], True)
        self.update_status("processing tiles")
        if type(current_job) is tuple:
            self.job_id = current_job[0]
            self.thread_list = []
            self.log_message("started job")
            self.work_path = conf.work_path + str(self.job_id) + "/"
            if not os.path.exists(self.work_path):
                os.makedirs(self.work_path)
            tile_list = self.get_tiles_to_process()
            minx, miny, maxx, maxy = self.get_bounds()
            if conf.num_threads > 1:
                if len(tile_list) < conf.num_threads:
                    self.num_threads = len(tile_list)
                else:
                    self.num_threads = conf.num_threads
                tile_count_step = len(tile_list) // self.num_threads # Integer division to get floow
                args = [[] for x in range(conf.num_threads)]
                for i in range(len(tile_list)):
                    args[i % self.num_threads].append(tile_list[i])
                pool = Pool(self.num_threads)
                pool.map(process_tiles, args)
                pool.close()
                pool.join()
            else:
                process_tiles(tile_list)

            self.update_status("saving clip file")
            sql = "select geom_txt from job where gid = {0}".format(self.job_id)
            wkt = db.exec_sql(sql, [], True)[0]
            clip_poly = self.work_path + "clip_poly.shp"
            utils.save_clip_poly(wkt, clip_poly)

            # self.update_status("mosaicking tiles")
            # utils.mosaic_tiles(self.work_path + "*_dsm.tif", self.work_path + "mosaic_dsm.tif", minx, miny, maxx, maxy,
            #                    clip_poly, self.job_id)
            # utils.mosaic_tiles(self.work_path + "*_height.tif", self.work_path + "mosaic_height.tif", minx, miny, maxx,
            #                    maxy, clip_poly, self.job_id)
            # # utils.mosaic_tiles(self.work_path + "*_intensity.tif", self.work_path + "mosaic_intensity.tif", minx, miny, maxx, maxy, clip_poly)
            # utils.mosaic_tiles(self.work_path + "*_dem.tif", self.work_path + "mosaic_dem.tif", minx, miny, maxx, maxy,
            #                    clip_poly, self.job_id)

            self.update_status("finalizing output")
            tree_file = self.work_path + "mosaic_trees.shp"
            utils.merge_tiles(self.work_path + "*_trees.shp", tree_file, clip_poly)
            utils.finalize(tree_file, clip_poly, self.job_id)

            # bldgs_file = self.work_path + "mosaic_bldgs.shp"
            # utils.merge_tiles(self.work_path + "*_bldgs.shp", bldgs_file, clip_poly, 10)
            # utils.finalize(bldgs_file, clip_poly, self.job_id)

            # impervious_file = self.work_path + "mosaic_impervious.shp"
            # utils.merge_tiles(self.work_path + "*_impervious.shp", impervious_file, clip_poly, 10)
            # utils.finalize(impervious_file, clip_poly, self.job_id)

            # contours_file = self.work_path + "mosaic_contours.shp"
            # utils.contours(self.work_path + "mosaic_dem.tif", contours_file, clip_poly)
            # utils.finalize(contours_file, clip_poly, self.job_id)

            for f_name in gl.glob(self.work_path + "*.txt"):
                out_file = conf.output_path + str(job_id) + "_" + os.path.basename(f_name)
                cmd = "copy {0} {1}".format(f_name.replace("/", "\\"), out_file.replace("/", "\\"))
                utils.exec_command_line(cmd, shell_flag=True)

            self.update_status("job complete!")
            # utils.mosaic_tiles(self.work_path + "*_trees.tif", self.work_path + "mosaic_trees.tif", minx, miny, maxx, maxy)
            # self.update_status("generating map tiles")
            # utils.create_output_tiles(self.work_path + "mosaic_dsm.tif", self.work_path + "dsm/")
            # utils.create_output_tiles(self.work_path + "mosaic_height.tif", self.work_path + "height/")
            # # utils.create_output_tiles(self.work_path + "mosaic_intensity.tif", self.work_path + "intensity/")
            # utils.create_output_tiles(self.work_path + "mosaic_dem.tif", self.work_path + "dem/")
            # # utils.create_output_tiles(self.work_path + "mosaic_trees.tif", self.work_path + "trees/")

        else:
            self.job_id = None
            self.log_message("No jobs found")
示例#6
0
 def log_message(self, message):
     # Logs message about this job to the job_log table
     print (message)
     if self.job_id:
         sql = "insert into job_log(job_id, message) values ({0}, '{1}')".format(self.job_id, message)
         db.exec_sql(sql)
示例#7
0
 def update_tile_status(self, tile_id, status):
     # Returns the status of the tilees in the job, count grouped by status
     sql = "update job_tile set status=%s where tile_id=%s"
     db.exec_sql(sql, [status, tile_id])