def add_image(): name = request.args.get('name') path = request.args.get('path') fp = request.args.get('footprint') i = Images(name=name, path=path, footprint=fp) session.add(i) session.commit() return i.__repr__()
def __init__(self, *args, parent=None, **kwargs): # If this is the first time that the image is seen, add it to the DB if parent is None: self.parent = Parent(config) else: self.parent = parent # Create a session to work in session = Session() # For now, just use the PATH to determine if the node/image is in the DB res = session.query(Images).filter( Images.path == kwargs['image_path']).first() exists = False if res: exists = True kwargs['node_id'] = res.id session.close() super(NetworkNode, self).__init__(*args, **kwargs) if exists is False: # Create the camera entry try: self._camera = create_camera(self.geodata) serialized_camera = self._camera.getModelState() cam = Cameras(camera=serialized_camera) except: cam = None kpspath = io_keypoints.create_output_path(self.geodata.file_name) # Create the keypoints entry kps = Keypoints(path=kpspath, nkeypoints=0) # Create the image i = Images(name=kwargs['image_name'], path=kwargs['image_path'], footprint_latlon=self.footprint, cameras=cam, keypoints=kps) session = Session() session.add(i) session.commit() session.close() self.job_status = defaultdict(dict)
def post_image(): if request.method == 'POST': d = request.form footprint_ll = d['footprint_latlon'] if footprint_ll: gj = json.loads(footprint_ll) fp_shapely = shape(gj) footprint_ll = WKTElement(fp_shapely.wkt, srid=949900) footprint_bf = d['footprint_bodyfixed'] if footprint_bf: footprint_bf = WKTElement(footprint_bf) i = Images(name=d['name'], path=d['path'], footprint_latlon=footprint_ll) session.add(i) session.commit() return json.dumps({"id":i.id}) elif request.method == 'GET': # TODO: Write the post requirements print('Signature')
outdir = kwargs.pop('outdir') outpath = create_output_path(ds, outdir) to_hdf(keypoints, descriptors, outpath) # Default response data = {'success':False,'path':input_file} # Connect to the DB and write maxretries = 3 # Create the DB objs camera = pickle.dumps(camera, 2) c = Cameras(camera=camera) k = Keypoints(path=outpath, nkeypoints=len(keypoints)) img = Images(name=ds.file_name, path=input_file, footprint_latlon=footprint_latlon, cameras=c,keypoints=k) # Attempt to grab an available db connection session = None while maxretries: try: engine = create_engine(db_uri, poolclass=NullPool) connection = engine.connect() session = sessionmaker(bind=engine, autoflush=True)() break except: time.sleep(30) maxretries -= 1 if session: session.add(img)