Browse Source

data extraction

kunickyd 3 years ago
parent
commit
62f547a4c8
1 changed files with 12 additions and 4 deletions
  1. 12 4
      app.ts

+ 12 - 4
app.ts

@@ -72,14 +72,22 @@ app.post("/buy", async (req, res, next) => {
 
         //TODO validate this properly
         let txDetail = await getTransactionDetail(req.body.txHash, req.body.user);
+
+        let extent: Array<Array<number>> = JSON.parse(txDetail.description).extent as Array<Array<number>>;
+        let dataFileId: string = Date.now().toString();
         
-        const { stdout, stderr } = await asyncExec(CHAIN4ALL_RASTER_CLIP_SCRIPT_PATH);
+        let dataCommand = CHAIN4ALL_RASTER_CLIP_SCRIPT_PATH + ' ' + extent[3][1] + ' ' + extent[3][0] + ' ' + extent[1][1] + ' ' + extent[1][0] + ' ' + dataFileId;
+        console.debug(dataCommand);
+
+        const { stdout, stderr } = await asyncExec(dataCommand);
         
+        console.debug(stdout);
+
         if(stderr){
-            throw(stderr);
+            console.warn(stderr);
         }
 
-        res.send(stdout);
+        res.send({dataUrl: "https://gis.lesprojekt.cz/chain4all/raster_" + dataFileId + ".tif"});
     }
     catch (err) {
         next(err);
@@ -131,7 +139,7 @@ function getPrice(extent: Array<Array<number>>): number {
 function errorMiddleware(err: any, req: any, res: any, next: any): void { //TODO: add custom Exception class
     console.log(err);
     res.status(500);
-    res.send(err.message);
+    res.send(err);
 }
 
 app.use(errorMiddleware);