def json(self, query=""): 
        """ Generate a topojson and geojson file for the location_id
        """
        if self.data_layer == 'bbox':
            result = utils.atlas2json("SELECT hasc, name, ST_Box2D(geom) FROM adm0_area;").replace("BOX(","").replace(")","").replace("st_box2d","bbox")
            return result
#            for bbox in result['bbox']:
#                return bbox
        else:
            return self.query2json(self.query_table, self.query_where, self.file_name)
 def near(self):
     "Return the list of nearby areas"
     query1 = """
     SELECT hasc, name, ST_Y(ST_Transform(centroid(geom),4326)), ST_X(ST_Transform(centroid(geom),4326)) FROM {} WHERE hasc LIKE '{}'; 
     """.format(self.adm_area_table,self.code)
     query2 = """
     SELECT hasc, name, ST_Y(ST_Transform(centroid(geom),4326)), ST_X(ST_Transform(centroid(geom),4326)) FROM {} WHERE hasc LIKE '{}'; 
     """.format(self.adm_area_table,self.code)
     
     return utils.atlas2json(query1 + query2)
 def subunits(self):
     "Return the list of subunits within the area"
     return utils.atlas2json("SELECT hasc, name FROM {} WHERE hasc LIKE '{}.%';".format("adm1_area",self.code) )
 def center(self):
     "Return the centroid of the area"
     return utils.atlas2json("SELECT hasc, name, ST_Y(ST_Transform(centroid(geom),4326)), ST_X(ST_Transform(centroid(geom),4326)) FROM {} WHERE hasc LIKE '{}';".format(self.adm_area_table,self.code) )
 def bbox(self):
     "Return the bounding box of the area"
     return utils.atlas2json("SELECT hasc, name,ST_Box2D(geom) FROM {} WHERE hasc LIKE '{}';".format(self.adm_area_table,self.code) )
def list_countries():
    return utils.atlas2json("SELECT hasc, name, ST_Box2D(geom) FROM adm0_area;").replace("BOX(","").replace(")","").replace("st_box2d","bbox")