-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.php
More file actions
116 lines (111 loc) · 4.48 KB
/
class.php
File metadata and controls
116 lines (111 loc) · 4.48 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// Flayac Quentin - quentin.flayac@epitech.eu
// 29/08/19 v2
// PHP Homemade Script to Transform GML SRS
class SRSReader {
public function logger() {
$args = func_get_args();
fwrite(STDOUT, implode(" ", $args) . "\n");
return;
}
public static function doThis($opts) {
if((isset($opts["d"]) || isset($opts["directory"])) && $opts["FoF"][0] === 'folder') {
self::logger("\nStarting folderRewrite...");
self::folderRewrite($opts);
self::logger("Done");
}
elseif((isset($opts["f"]) || isset($opts["file"])) && $opts["FoF"][0] === 'file') {
self::logger("\nStarting fileRewrite...");
self::fileRewrite($opts);
self::logger("Done");
}
elseif((isset($opts["c"]) || isset($opts["check"])) && $opts["FoF"][0] === 'file') {
self::logger("\nStarting SRS Checker...");
self::checkSRS($opts);
self::logger("Done");
}
else {
self::logger("Exit. Invalid Arguments. -h or --help");
}
}
public function SRSMan(){
echo"\nSRSRewriter(1) User Commands SRSRewriter(1)\n
\nMAINTAINER
Flayac Quentin - quentin.flayac@epitech.eu
\nNAME
SRSRewriter – PHP Tool to Edit / Check CityGML Files
\nSYNOPSIS
SRSRewriter [OPTIONS]... FILE/FOLDER
\nEXAMPLE
php main.php -h
php main.php -d -s=3946 /home/CityGMLFolder/
php main.php -f -s=3946 /home/CityGMLFolder/citygml.gml
php main.php -c /home/CityGMLFolder/citygml.gml
\nDESCRIPTION
This tool was made in order to add the property 'srsName' to cityGML
files node. Since the v2 he is able to check all node who contain
'srsDimension' and display them.
-f, --file
Look into the cityGML files passed as arguement.
-d, --directory
Look for cityGML files into the directory passed as arguement.
/!\ It doesn't watch in subdirectories /!\
-s, --srs = STRING with INTEGER srsName
Add the srsName on each node with srsDimension=\"3\"
-c, --check /!\ Only with single file /!\
Check all gml node who contain srsDimension=\"3\".
\nBONUS COMMANDS
-h, --help=HELP
Open the Manual.\n\n";
}
public function folderRewrite($opts) {
// basefolder -> filename (//countable)
$files = scandir($opts["FoF"][1]);
// 587
for($i = 0; $i < count($files); $i++) {
$extension = explode(".", $files[$i]);
$extPlacement = count($extension);
if($extension[$extPlacement - 1] === "gml") {
// basefile content in an array, exploded with \n
$array = explode("\n", file_get_contents($opts["FoF"][1]."/".$files[$i]));
// basefile name
$filename = explode("/", $files[$i]);
$srs = isset($opts['s']) ? $srs = $opts['s'] : $srs = $opts['srs'];
for($y = 0; $y < count($array); $y++) {
$srsReplace = "srsDimension=\"3\"";
$srsUpdate = "srsName=\"EPSG:".$content."\" srsDimension=\"3\"";
$array[$y] = str_replace($srsReplace, $srsUpdate, $array[$y]);
}
// create a new File with modification
self::logger("File saved at: " . __DIR__."/rewrited/rewrited_".$filename[count($filename) - 1]);
file_put_contents(__DIR__."/rewrited/rewrited_".$filename[count($filename) - 1], implode("\n", $array));
}
}
return;
}
public function fileRewrite($opts) {
// basefile content in an array, exploded with \n
$array = explode("\n", file_get_contents($opts["FoF"][1]));
// basefile name
$filename = explode("/", $opts["FoF"][1]);
$srs = isset($opts['s']) ? $srs = $opts['s'] : $srs = $opts['srs'];
for($i = 0; $i < count($array); $i++) {
$srsReplace = "srsDimension=\"3\"";
$srsUpdate = "srsName=\"EPSG:".$srs."\" srsDimension=\"3\"";
$array[$i] = str_replace($srsReplace, $srsUpdate, $array[$i]);
}
// create a new File with modification
self::logger("File saved at: " . __DIR__."/rewrited/rewrited_".$filename[count($filename) - 1]);
file_put_contents(__DIR__."/rewrited/rewrited_".$filename[count($filename) - 1], implode("\n", $array));
return;
}
function checkSRS($opts) {
$array = explode("\n", file_get_contents($opts["FoF"][1]));
$search = 'srsDimension';
for($i = 0; $i < count($array); $i++) {
if(strpos($array[$i], $search) !== false) {
echo "l." . $i . ": " . $array[$i] . "\n";
}
}
}
}