-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcutGeoJson.php
More file actions
86 lines (69 loc) · 2.27 KB
/
cutGeoJson.php
File metadata and controls
86 lines (69 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors','1');
require_once('classes/experimento.class.php');
require_once('classes/conexao.class.php');
$conexao = new Conexao;
$conn = $conexao->Conectar();
$Experimento = new Experimento();
$Experimento->conn = $conn;
$expid = $_REQUEST['expid'];
$Experimento->getById($expid);
$Experimento->getPath($expid);
$isImageCut = $Experimento->isImageCut;
$isImageCut = $isImageCut === 't'? true: false;
if(dirname(__FILE__) != '/var/www/html/rafael/modelr'){
$baseUrl = '../';
} else {
$baseUrl = './';
}
if($isImageCut){
$pngCutPath = $Experimento->pngCutPath;
$rasterCutPath = "'" . $Experimento->rasterCutPath . "'";
} else {
$pngCutPath = $Experimento->rasterPngPath;
$rasterCutPath = "'" . $Experimento->tiffPath . "'";
}
$Experimento->alterarPathPngRaster($expid, "'".$baseUrl."temp/" . $expid ."/png_map-" . $expid . ".png'", "'".$baseUrl."temp/" . $expid ."/raster_crop-" . $expid . ".tif'");
$filePath = $baseUrl . '../../../../../../mnt/dados/modelr/json/polygon-' . $expid . '.json';
$file = fopen($filePath, 'w');
$arrayPolygon = json_decode($_REQUEST['array'], true);
foreach($arrayPolygon as $polygon){
$type = $polygon['type'];
if($type != 'circle'){
$vertices = explode(';',$polygon['vertices']);
$result = [];
foreach($vertices as $v){
$result[] = [explode(',',$v)[1], explode(',',$v)[0]];
}
$coordinates[] = [$result];
$myObj->type = "MultiPolygon";
$myObj->coordinates = $coordinates;
$myJSON = json_encode($myObj, JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK);
fwrite($file, $myJSON);
fclose($file);
} else {
$vertices = explode(';',$polygon['vertices']);
foreach($vertices as $v){
$vertices = explode(';',$polygon['vertices']);
$result = [];
foreach($vertices as $v){
$result[] = [explode(',',$v)[1], explode(',',$v)[0]];
}
$coordinates[] = [$result];
}
$myObj->type = "Circle";
$myObj->coordinates = $coordinates;
$myObj->radius = $polygon['radius'];
$myJSON = json_encode($myObj, JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK);
fwrite($file, $myJSON);
fclose($file);
}
}
if (!file_exists($baseUrl . "temp/" . $expid )) {
mkdir($baseUrl . "temp/" . $expid , 0777, true);
}
exec("Rscript R/script_pos.R $expid $filePath $rasterCutPath");
return 'success';
?>