Пример #1
0
    def query2json(self, table, file_name, where, json_type = 'topojson'):
        "Generates a json result from the requested database query"
        output_file = self.output_path( file_name )
        
        options = "-w \"{}\"".format(where)
        
        # If target file does not exist
        if not os.path.exists(output_file + '.' + json_type):
            
            # Create a new directory if it does not exist
            if not os.path.exists(self.data_dir):
                os.makedirs(self.data_dir)
                
            # Generate an index file for the region with list of subunits and bounding boxes
            self.generate_atlas_index()
        
            # Now generate the files and regenerate the index
            utils.postgis2geojson(table, output_file, options )

        # Read generated file
        with open(output_file + '.' + json_type, 'r') as f:
            try:
                return json.dumps(json.load(f))
            finally:
                f.close()
    def query2json(self, table, where, file_name, update = 'false'):
        "Generates a json result from the requested database query"
        
        output_file_name = self.construct_output_path( file_name )
        options = "-w \"{}\"".format(where)
        
        # If target file does not exist
        if not os.path.exists(output_file_name + '.' + self.json_format):
            
            # Create a new directory if it does not exist
            if not os.path.exists(self.output_dir):
                os.makedirs(self.output_dir)
                
            # Generate an index file for the region with list of subunits and bounding boxes
#            self.update_data_index()
        
            # Now generate the files and regenerate the index
            utils.postgis2geojson(table, output_file_name, options )
#
        return self.fetch_json_data(output_file_name)