|
|
@@ -29,31 +29,65 @@ class Route_UrlAction_WmsGenerate extends RouteBase {
|
|
|
return $folderConf['mount_point'];
|
|
|
}
|
|
|
|
|
|
- public function defaultAction() {
|
|
|
- SE_Layout::gora();
|
|
|
- SE_Layout::menu();
|
|
|
- $ID_WMS_LAYERS=V::get('ID_WMS_LAYERS',0,$_GET,'int');
|
|
|
- if ($ID_WMS_LAYERS<=0) die ('ID ERROR');
|
|
|
-
|
|
|
+ private function defaultAction_WMS_LAYERS($ID_WMS_LAYERS) {
|
|
|
try {
|
|
|
+ $LAYER_TYPE=DB::getPDO()->fetchall("select LAYER_TYPE from WMS_LAYERS where ID='".$ID_WMS_LAYERS."'");
|
|
|
+ if (!$LAYER_TYPE) throw new Exception('Błąd - nie ma takiej warstwy!');
|
|
|
+
|
|
|
$destFolderPath = $this->getDirectory($ID_WMS_LAYERS);
|
|
|
$files=array();
|
|
|
- foreach (glob($destFolderPath."/*.tif",GLOB_BRACE) as $node) {
|
|
|
- if (is_file($node)) $files[]=basename($node);
|
|
|
- }
|
|
|
- if (count($files)==0) throw new Exception('Nie znaleziono żadnego pliku tif!');
|
|
|
- if (count($files)>1) throw new Exception('Znaleziono zbyt dużo plików tif!');
|
|
|
+
|
|
|
+ if ($LAYER_TYPE[0]['LAYER_TYPE']=='GeoTIFF') {
|
|
|
+
|
|
|
+ foreach (glob($destFolderPath."/*.tif",GLOB_BRACE) as $node) {
|
|
|
+ if (is_file($node)) $files[]=basename($node);
|
|
|
+ }
|
|
|
+ if (count($files)==0) throw new Exception('Nie znaleziono żadnego pliku tif!');
|
|
|
+ if (count($files)>1) throw new Exception('Znaleziono zbyt dużo plików tif!');
|
|
|
+
|
|
|
+ $validateGeoTifJson=shell_exec("/opt/local/bin/gdalinfo -json ".$destFolderPath."/*".$files[0]." 2>/dev/null");
|
|
|
+ $validateGeoTif=json_decode($validateGeoTifJson);
|
|
|
+ if (!$validateGeoTif) throw new Exception('Znaleziony plik '.$files[0].' nie jest poprawnym plikiem tif!');
|
|
|
+ if (!$validateGeoTif->coordinateSystem->wkt) throw new Exception('Znaleziony plik '.$files[0].' nie jest poprawnym plikiem GeoTif!');
|
|
|
+
|
|
|
+ } elseif ($LAYER_TYPE[0]['LAYER_TYPE']=='QGIS') {
|
|
|
+
|
|
|
+ foreach (glob($destFolderPath."/*.qgs",GLOB_BRACE) as $node) {
|
|
|
+ if (is_file($node)) $files[]=basename($node);
|
|
|
+ }
|
|
|
+ if (count($files)==0) throw new Exception('Nie znaleziono żadnego pliku qgs!');
|
|
|
+ if (count($files)>1) throw new Exception('Znaleziono zbyt dużo plików qgs!');
|
|
|
+ $validateXml=simplexml_load_file($destFolderPath."/".$files[0]);
|
|
|
+ if (!$validateXml) throw new Exception('Znaleziony plik '.$destFolderPath.'/'.$files[0].' nie jest poprawnym plikiem qgs!');
|
|
|
+ if (!$validateXml->mapcanvas->destinationsrs->spatialrefsys->srid) throw new Exception('Znaleziony plik '.$files[0].' nie jest poprawnym plikiem projektu QGIS!');
|
|
|
+
|
|
|
+ $DataSources=$validateXml->xpath('/qgis/projectlayers/maplayer/datasource');
|
|
|
+ if (!$DataSources) throw new Exception('Plik projektu QGIS nie zawiera żadnej warstwy!');
|
|
|
+
|
|
|
+ $suffixes=array('.shp','.dbf','.shx');
|
|
|
+ $filesToCopy=array($files[0]);
|
|
|
+ $missingFiles=array();
|
|
|
+ foreach ($DataSources as $DataSource) {
|
|
|
+ $file=basename($DataSource,".shp");
|
|
|
+ foreach ($suffixes as $suffix) {
|
|
|
+ if(is_file($destFolderPath."/".$file.$suffix)) $filesToCopy[]=$file.$suffix;
|
|
|
+ else $missingFiles[]=$file.$suffix;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($missingFiles) throw new Exception('Nie znaleziono poniższych plików wymaganych przez plik projetku QGIS:<br/>'.implode('<br/>',$missingFiles));
|
|
|
|
|
|
- $validateGeoTifJson=shell_exec("/opt/local/bin/gdalinfo -json ".$destFolderPath."/*".$files[0]." 2>/dev/null");
|
|
|
- $validateGeoTif=json_decode($validateGeoTifJson);
|
|
|
- if (!$validateGeoTif) throw new Exception('Znaleziony plik '.$files[0].' nie jest poprawnym plikiem tif!');
|
|
|
- if (!$validateGeoTif->coordinateSystem->wkt) throw new Exception('Znaleziony plik '.$files[0].' nie jest poprawnym plikiem GeoTif!');
|
|
|
+ if (is_dir($destFolderPath.'/.wms')) shell_exec('rm -rf '.$destFolderPath.'/.wms');
|
|
|
+ mkdir($destFolderPath.'/.wms');
|
|
|
+ foreach ($filesToCopy as $file) copy($destFolderPath."/".$file,$destFolderPath."/.wms/".$file);
|
|
|
+
|
|
|
+ } else throw new Exception('Nieznany typ warstwy!');
|
|
|
|
|
|
$sqlObj = new stdClass();
|
|
|
$sqlObj->ID = $ID_WMS_LAYERS;
|
|
|
$sqlObj->FILE_STATUS='TO_GENERATE';
|
|
|
$sqlObj->FILE_STATUS_INFO='Plik oczekuje na przetworzenie';
|
|
|
$sqlObj->FILE_NAME=$files[0];
|
|
|
+ $sqlObj->OLD_LAYER_TYPE=$LAYER_TYPE[0]['LAYER_TYPE'];
|
|
|
$affected = DB::getDB()->UPDATE_OBJ('WMS_LAYERS', $sqlObj);
|
|
|
if ($affected) SE_Layout::alert('success','Oznaczono plik '.$files[0].' do przetworzenia.');
|
|
|
else SE_Layout::alert('warning','Plik '.$files[0].' został już wcześniej oznaczony do przetworzenia.');
|
|
|
@@ -61,10 +95,30 @@ class Route_UrlAction_WmsGenerate extends RouteBase {
|
|
|
} catch (Exception $e) {
|
|
|
SE_Layout::alert('danger',$e->getMessage());
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private function defaultAction_WMS_MAPS($ID_WMS_MAPS) {
|
|
|
+ try {
|
|
|
+ $affected = DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$ID_WMS_MAPS,'MAP_STATUS'=>'TO_GENERATE','MAP_STATUS_INFO'=>'Mapa oczekuje na przetworzenie'));
|
|
|
+ if ($affected) SE_Layout::alert('success','Oznaczono mapę do ponownego wygenerowania.');
|
|
|
+ else SE_Layout::alert('warning','Mapa została już wcześniej oznaczona do ponownego wygenerowania.');
|
|
|
+ } catch (Exception $e) {
|
|
|
+ SE_Layout::alert('danger',$e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function defaultAction() {
|
|
|
+ SE_Layout::gora();
|
|
|
+// SE_Layout::menu();
|
|
|
+
|
|
|
+ if (V::get('ID_WMS_LAYERS',0,$_GET,'int')>0) $this->defaultAction_WMS_LAYERS(V::get('ID_WMS_LAYERS',0,$_GET,'int'));
|
|
|
+ elseif (V::get('ID_WMS_MAPS',0,$_GET,'int')>0) $this->defaultAction_WMS_MAPS(V::get('ID_WMS_MAPS',0,$_GET,'int'));
|
|
|
+ else SE_Layout::alert('danger','Błąd parametru');
|
|
|
|
|
|
?>
|
|
|
-<div class="container">
|
|
|
- <a href="<?php echo $_SERVER['HTTP_REFERER']?>" class="btn btn-primary">Powrót</a>
|
|
|
+<div class="container" style="text-align:center">
|
|
|
+<!-- <a href="<?php echo $_SERVER['HTTP_REFERER']?>" class="btn btn-primary">Powrót</a> -->
|
|
|
+ <button class="btn btn-primary" onClick="javascript:window.close()">Zamknij</button>
|
|
|
</div>
|
|
|
<?php
|
|
|
SE_Layout::dol();
|
|
|
@@ -73,15 +127,79 @@ class Route_UrlAction_WmsGenerate extends RouteBase {
|
|
|
public function doGenerate() {
|
|
|
|
|
|
try {
|
|
|
+ ### Ustawiamy zmienną sesji nazwy użytkownika, aby w rekordach historycznych było widać, że autorem systemu jest moduł WmsGenerate
|
|
|
+ $_SESSION['ADM_ACCOUNT']="WmsGenerate";
|
|
|
+
|
|
|
+
|
|
|
### Sprawdzenie czy modul WMS jest aktywny na danej instalacji Procesy5
|
|
|
$moduleActive=DB::getPDO()->fetchall("select count(*) as cnt from CRM_CONFIG where CONF_KEY='module_WMS' and CONF_VAL='on'");
|
|
|
if (!$moduleActive[0]['cnt']) throw new Exception("Module WMS disabled/not installed.");
|
|
|
|
|
|
- ### Znalezienie nowo przetworzonych warstw i utworzenie pojedynczych map do mapserver
|
|
|
+
|
|
|
+ ### Utworzenie niezbędnych katalogów i plików
|
|
|
$wmsDirLocation=$this->getMainDirectory();
|
|
|
if (!file_exists($wmsDirLocation.'/.maps/.single')) mkdir($wmsDirLocation.'/.maps/.single',0755,true);
|
|
|
if (!file_exists($wmsDirLocation.'/.maps/.single')) throw new Exception('Error during creating maps directory.');
|
|
|
+ if (!file_exists($wmsDirLocation.'/.maps/.template.html')) file_put_contents($wmsDirLocation.'/.maps/.template.html','');
|
|
|
+
|
|
|
+
|
|
|
+ ### Tablica rozszerzeń plików warstw
|
|
|
+ $mapFileSuffix=array('GeoTIFF'=>'.map','QGIS'=>'.qgs');
|
|
|
+
|
|
|
+
|
|
|
+ ### Definicja tablicy przechowującej numery map do wygenerowania
|
|
|
+ $mapsToGenerate=Array();
|
|
|
+
|
|
|
+
|
|
|
+ ### Weryfikacja zmiany typu warstwy
|
|
|
+ $layers=DB::getPDO()->fetchall("select ID,OLD_LAYER_TYPE from WMS_LAYERS where LAYER_TYPE!=OLD_LAYER_TYPE AND (MAP_STATUS='ACTIVE' or FILE_STATUS in ('TO_GENERATE','IN_PROGRESS'))");
|
|
|
+ foreach ($layers as $layer) DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'LAYER_TYPE'=>$layer['OLD_LAYER_TYPE']));
|
|
|
+
|
|
|
+
|
|
|
+ ### Przetworzenie projektów QGIS
|
|
|
+ $layers=DB::getPDO()->fetchall("select ID,FILE_NAME,LAYER_NAME,A_STATUS,ID_WMS_MAPS from WMS_LAYERS where LAYER_TYPE='QGIS' and FILE_STATUS='TO_GENERATE'");
|
|
|
+ foreach ($layers as $layer) {
|
|
|
+ $destFolderPath = $this->getDirectory($layer['ID']);
|
|
|
+ if(!is_file($destFolderPath.'/'.$layer['FILE_NAME'])) {
|
|
|
+ DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'ERROR','FILE_STATUS_INFO'=>'Wystąpił błąd pliku qgs'));
|
|
|
+ throw new Exception("Błąd pliku: ".$layer['FILE_NAME']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $xml=simplexml_load_file($destFolderPath.'/.wms/'.$layer['FILE_NAME']);
|
|
|
+ if (!$xml) {
|
|
|
+ DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'ERROR','FILE_STATUS_INFO'=>'Wystąpił błąd pliku qgs'));
|
|
|
+ throw new Exception("Błąd pliku: ".$layer['FILE_NAME']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $dataSources=$xml->xpath('/qgis/projectlayers/maplayer/datasource');
|
|
|
+ foreach ($dataSources as $id => $file) $dataSources[$id][0]=$destFolderPath.'/.wms/'.basename($file);
|
|
|
+
|
|
|
+ if ($layer['LAYER_NAME']) $LAYER_NAME=V::convert($layer['LAYER_NAME'],'url');
|
|
|
+ else $LAYER_NAME="QGIS_".$layer['ID'];
|
|
|
+ $xml->properties->WMSRootName=$LAYER_NAME;
|
|
|
+ $xml->properties->WMSRootName->addAttribute('type','QString');
|
|
|
+ $xml->properties->WMSServiceTitle=$LAYER_NAME;
|
|
|
+ $xml->properties->WMSServiceTitle->addAttribute('type','QString');
|
|
|
+ $xml->properties->WMSServiceCapabilities="true";
|
|
|
+ $xml->properties->WMSServiceCapabilities->addAttribute('type','bool');
|
|
|
+ $xml->properties->WMSAddWktGeometry="true";
|
|
|
+ $xml->properties->WMSAddWktGeometry->addAttribute('type','bool');
|
|
|
+ $xml->properties->Paths->Absolute="true";
|
|
|
+ $xml->properties->WMSUrl="http://127.0.0.1:34580/wms/qgis/".$layer['ID'];
|
|
|
+ $xml->properties->WMSUrl->addAttribute('type','QString');
|
|
|
+ $epsg=$xml->mapcanvas->destinationsrs->spatialrefsys->srid;
|
|
|
+ $extent=implode(" ",(array) $xml->mapcanvas->extent);
|
|
|
+
|
|
|
+ $xml->asXml($destFolderPath.'/.wms/wms.qgs');
|
|
|
+ unlink($destFolderPath.'/.wms/'.$layer['FILE_NAME']);
|
|
|
+ //TODO calculate wgs84
|
|
|
+ //DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'GENERATED','FILE_STATUS_INFO'=>'Plik przetworzony poprawnie','the_geom'=>"GeomFromText('{$geom}')",'EPSG'=>"{$epsg}",'EXTENT'=>"{$extent}"));
|
|
|
+ DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'GENERATED','FILE_STATUS_INFO'=>'Plik przetworzony poprawnie','EPSG'=>"{$epsg}",'EXTENT'=>"{$extent}"));
|
|
|
+ if ($layer['A_STATUS']=='NORMAL') $mapsToGenerate[$layer['ID_WMS_MAPS']]=1;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ ### Znalezienie nowo przetworzonych warstw GeoTIFF i utworzenie pojedynczych map do mapserver
|
|
|
$mapSchema='MAP
|
|
|
|
|
|
NAME "__NAME__"
|
|
|
@@ -96,7 +214,8 @@ class Route_UrlAction_WmsGenerate extends RouteBase {
|
|
|
METADATA
|
|
|
WMS_TITLE "__NAME__"
|
|
|
WMS_ENABLE_REQUEST "*"
|
|
|
- WMS_ONLINERESOURCE "https://__SERVER_NAME__/wms/.single/__ID__"
|
|
|
+# WMS_ONLINERESOURCE "https://__SERVER_NAME__/wms/.single/__ID__"
|
|
|
+ MS_ONLINERESOURCE "http://127.0.0.1:34580/wms/.single/__ID__"
|
|
|
WMS_SRS "EPSG:__EPSG__"
|
|
|
END
|
|
|
END
|
|
|
@@ -127,8 +246,7 @@ END
|
|
|
';
|
|
|
$search=array('__NAME__','__EXTENT__','__SERVER_NAME__','__ID__','__EPSG__','__FILE__');
|
|
|
|
|
|
- $layers=DB::getPDO()->fetchall("select ID,LAYER_NAME,EPSG,ID_WMS_MAPS,A_STATUS,FILE_NAME from WMS_LAYERS where FILE_STATUS='IN_PROGRESS'");
|
|
|
- $mapsToGenerate=Array();
|
|
|
+ $layers=DB::getPDO()->fetchall("select ID,LAYER_NAME,EPSG,ID_WMS_MAPS,A_STATUS,FILE_NAME from WMS_LAYERS where LAYER_TYPE='GeoTIFF' and FILE_STATUS='IN_PROGRESS'");
|
|
|
foreach ($layers as $layer) {
|
|
|
if (!file_exists('/tmp/generate_wms-'.$layer['ID'].'.lock')) {
|
|
|
unlink('/tmp/generate_wms-'.$layer['ID'].'.sh');
|
|
|
@@ -143,10 +261,12 @@ END
|
|
|
unlink($destFolderPath.'/.wms/.data');
|
|
|
$geom=$data_arr[0];
|
|
|
$extent=$data_arr[1];
|
|
|
- $replace=array($layer['LAYER_NAME'],$extent,$_SERVER['SERVER_NAME'],$layer['ID'],$layer['EPSG'],$destFolderPath.'/.wms/'.$layer['FILE_NAME']);
|
|
|
+ if ($layer['LAYER_NAME']) $LAYER_NAME=V::convert($layer['LAYER_NAME'],'url');
|
|
|
+ else $LAYER_NAME="GeoTIFF_".$layer['ID'];
|
|
|
+ $replace=array($LAYER_NAME,$extent,$_SERVER['SERVER_NAME'],$layer['ID'],$layer['EPSG'],$destFolderPath.'/.wms/'.$layer['FILE_NAME']);
|
|
|
$map = str_replace($search,$replace,$mapSchema);
|
|
|
- file_put_contents($destFolderPath.'/.wms/mapserver.map',$map);
|
|
|
- DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'GENERATED','FILE_STATUS_INFO'=>'Plik przetworzony poprawnie','the_geom'=>"GeomFromText('{$geom}')"));
|
|
|
+ file_put_contents($destFolderPath.'/.wms/wms.map',$map);
|
|
|
+ DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'FILE_STATUS'=>'GENERATED','FILE_STATUS_INFO'=>'Plik przetworzony poprawnie','the_geom'=>"GeomFromText('{$geom}')",'EXTENT'=>"{$extent}"));
|
|
|
unlink($destFolderPath.'/.wms/.completed');
|
|
|
if ($layer['A_STATUS']=='NORMAL') $mapsToGenerate[$layer['ID_WMS_MAPS']]=1;
|
|
|
}
|
|
|
@@ -167,18 +287,21 @@ END
|
|
|
|
|
|
|
|
|
### Aktywacja nieaktywnych warstw, ktore nalezy zaktywowac
|
|
|
- $layers=DB::getPDO()->fetchall("select ID,ID_WMS_MAPS from WMS_LAYERS where A_STATUS='NORMAL' and FILE_STATUS='GENERATED' and MAP_STATUS='INACTIVE'");
|
|
|
+ $layers=DB::getPDO()->fetchall("select ID,ID_WMS_MAPS,LAYER_TYPE from WMS_LAYERS where A_STATUS='NORMAL' and FILE_STATUS='GENERATED' and MAP_STATUS='INACTIVE'");
|
|
|
foreach ($layers as $layer) {
|
|
|
- if (!file_exists($wmsDirLocation.'/.maps/.single/'.$layer['ID'].'.map')) symlink($destFolderPath.'/.wms/mapserver.map',$wmsDirLocation.'/.maps/.single/'.$layer['ID'].'.map');
|
|
|
+ if (!file_exists($wmsDirLocation.'/.maps/.single/'.$layer['ID'].$mapFileSuffix[$layer['LAYER_TYPE']])) {
|
|
|
+ $destFolderPath = $this->getDirectory($layer['ID']);
|
|
|
+ symlink($destFolderPath.'/.wms/wms'.$mapFileSuffix[$layer['LAYER_TYPE']],$wmsDirLocation.'/.maps/.single/'.$layer['ID'].$mapFileSuffix[$layer['LAYER_TYPE']]);
|
|
|
+ }
|
|
|
DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'MAP_STATUS'=>'ACTIVE'));
|
|
|
$mapsToGenerate[$layer['ID_WMS_MAPS']]=1;
|
|
|
}
|
|
|
|
|
|
|
|
|
### Dezaktywacja aktywnych warstw, ktore nalezy zdezaktywowac
|
|
|
- $layers=DB::getPDO()->fetchall("select ID,ID_WMS_MAPS from WMS_LAYERS where MAP_STATUS='ACTIVE' and (A_STATUS!='NORMAL' or FILE_STATUS!='GENERATED')");
|
|
|
+ $layers=DB::getPDO()->fetchall("select ID,ID_WMS_MAPS,LAYER_TYPE from WMS_LAYERS where MAP_STATUS='ACTIVE' and (A_STATUS!='NORMAL' or FILE_STATUS!='GENERATED')");
|
|
|
foreach ($layers as $layer) {
|
|
|
- if (file_exists($wmsDirLocation.'/.maps/.single/'.$layer['ID'].'.map')) unlink($wmsDirLocation.'/.maps/.single/'.$layer['ID'].'.map');
|
|
|
+ if (is_link($wmsDirLocation.'/.maps/.single/'.$layer['ID'].$mapFileSuffix[$layer['LAYER_TYPE']])) $res=unlink($wmsDirLocation.'/.maps/.single/'.$layer['ID'].$mapFileSuffix[$layer['LAYER_TYPE']]);
|
|
|
DB::getDB()->UPDATE_OBJ('WMS_LAYERS',(object) array('ID'=>$layer['ID'],'MAP_STATUS'=>'INACTIVE'));
|
|
|
$mapsToGenerate[$layer['ID_WMS_MAPS']]=1;
|
|
|
}
|
|
|
@@ -191,36 +314,136 @@ END
|
|
|
|
|
|
### Oznaczenie map do generowania
|
|
|
if ($mapsToGenerate) {
|
|
|
- foreach ($mapsToGenerate as $ID_WMS_MAPS => $x)
|
|
|
+ foreach ($mapsToGenerate as $ID_WMS_MAPS => $x) {
|
|
|
$mapsCount=DB::getPDO()->fetchall("select ID from WMS_MAPS where ID='".$ID_WMS_MAPS."' and A_STATUS='NORMAL'");
|
|
|
if ($mapsCount) DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$ID_WMS_MAPS,'MAP_STATUS'=>'TO_GENERATE','MAP_STATUS_INFO'=>'Mapa oczekuje na przetworzenie'));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
### Generowanie map
|
|
|
- $maps=DB::getPDO()->fetchall("select ID,MAP_NAME,MAP_EPSG,MAP_FILE from WMS_MAPS where MAP_STATUS='TO_GENERATE'");
|
|
|
+ $layerSchema['GeoTIFF']='
|
|
|
+ LAYER
|
|
|
+ NAME "__NAME__"
|
|
|
+ STATUS OFF
|
|
|
+ TYPE RASTER
|
|
|
+ CONNECTION "http://127.0.0.1:34580/wms/__TYPE__/__ID__"
|
|
|
+ CONNECTIONTYPE WMS
|
|
|
+ EXTENT __EXTENT__
|
|
|
+
|
|
|
+ PROJECTION
|
|
|
+ "init=epsg:__EPSG__"
|
|
|
+ END
|
|
|
+
|
|
|
+ METADATA
|
|
|
+ WMS_TITLE "__NAME__"
|
|
|
+ WMS_SRS "EPSG:__EPSG__"
|
|
|
+ WMS_EXTENT "__EXTENT__"
|
|
|
+ WMS_NAME "__NAME__"
|
|
|
+ WMS_FORMAT "image/png"
|
|
|
+ WMS_SERVER_VERSION "1.1.1"
|
|
|
+ END
|
|
|
+ END
|
|
|
+';
|
|
|
+
|
|
|
+ $layerSchema['QGIS']='
|
|
|
+ LAYER
|
|
|
+ NAME "__NAME__"
|
|
|
+ STATUS OFF
|
|
|
+ TYPE RASTER
|
|
|
+ CONNECTION "http://127.0.0.1:34580/wms/__TYPE__/__ID__"
|
|
|
+ CONNECTIONTYPE WMS
|
|
|
+ EXTENT __EXTENT__
|
|
|
+
|
|
|
+ PROJECTION
|
|
|
+ "init=epsg:__EPSG__"
|
|
|
+ END
|
|
|
+
|
|
|
+ CLASS
|
|
|
+ TEMPLATE "__TEMPLATE__"
|
|
|
+ END
|
|
|
+
|
|
|
+ METADATA
|
|
|
+ WMS_TITLE "__NAME__"
|
|
|
+ WMS_SRS "EPSG:__EPSG__"
|
|
|
+ WMS_EXTENT "__EXTENT__"
|
|
|
+ WMS_NAME "__NAME__"
|
|
|
+ WMS_FORMAT "image/png"
|
|
|
+ WMS_SERVER_VERSION "1.1.1"
|
|
|
+ END
|
|
|
+ END
|
|
|
+';
|
|
|
+
|
|
|
+ $layerSearch=array('__NAME__','__TYPE__','__ID__','__EXTENT__','__EPSG__','__TEMPLATE__');
|
|
|
+
|
|
|
+ $mapHeadSchema='MAP
|
|
|
+
|
|
|
+ NAME "__NAME__"
|
|
|
+ STATUS ON
|
|
|
+ SIZE 400 300
|
|
|
+ EXTENT -180 -90 180 90
|
|
|
+ UNITS METERS
|
|
|
+ IMAGECOLOR 255 255 0
|
|
|
+ IMAGETYPE PNG
|
|
|
+
|
|
|
+ WEB
|
|
|
+ METADATA
|
|
|
+ WMS_TITLE "__NAME__"
|
|
|
+ WMS_ENABLE_REQUEST "*"
|
|
|
+ WMS_ONLINERESOURCE "__MAP_URL__"
|
|
|
+ WMS_SRS "__EPSGS__"
|
|
|
+ END
|
|
|
+ END
|
|
|
+
|
|
|
+ PROJECTION
|
|
|
+ "init=epsg:4236"
|
|
|
+ END
|
|
|
+';
|
|
|
+ $mapHeadSearch=array('__NAME__','__MAP_URL__','__EPSGS__');
|
|
|
+
|
|
|
+ $mapTailSchema='
|
|
|
+END
|
|
|
+';
|
|
|
+
|
|
|
+ $maps=DB::getPDO()->fetchall("select ID,MAP_NAME,MAP_FILE,MAP_URL from WMS_MAPS where MAP_STATUS='TO_GENERATE'");
|
|
|
+ $urlLayerType=array('GeoTIFF'=>'.single','QGIS'=>'qgis');
|
|
|
foreach ($maps as $map) {
|
|
|
- if ($map['MAP_FILE']) unlink($wmsDirLocation.'/.maps/'.$map['MAP_FILE'].'.map');
|
|
|
- $MAP_FILE=strtolower(V::convert($map['MAP_NAME']));
|
|
|
- if ($MAP_FILE=="") {
|
|
|
- DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$ID_WMS_MAPS,'MAP_STATUS'=>'ERROR','MAP_STATUS_INFO'=>'Brak nazwy mapy'));
|
|
|
+ if ($map['MAP_FILE']) unlink($wmsDirLocation.'/.maps/'.$map['MAP_FILE']);
|
|
|
+ $MAP_FILE=strtolower(V::convert($map['MAP_NAME'],'url'));
|
|
|
+ if ($MAP_FILE=="") $MAP_FILE=$map['ID'];
|
|
|
+ $MAP_URL='https://'.$_SERVER['SERVER_NAME'].'/wms/'.$MAP_FILE;
|
|
|
+ $MAP_FILE.=".map";
|
|
|
+ $otherMaps=DB::getPDO()->fetchall("select ID from WMS_MAPS where ID!='".$map['ID']."' and MAP_FILE='".$MAP_FILE."'");
|
|
|
+ if ($otherMaps) {
|
|
|
+ DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$map['ID'],'MAP_STATUS'=>'ERROR','MAP_STATUS_INFO'=>'Nieunikalna nazwa mapy','MAP_URL'=>'','MAP_FILE'=>''));
|
|
|
} else {
|
|
|
- $otherMaps=DB::getPDO()->fetchall("select ID from WMS_MAPS where ID!='".$map['ID']."' and MAP_FILE='".$MAP_FILE."'");
|
|
|
- if ($otherMaps) {
|
|
|
- DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$ID_WMS_MAPS,'MAP_STATUS'=>'ERROR','MAP_STATUS_INFO'=>'Nieunikalna nazwa mapy'));
|
|
|
- } else {
|
|
|
- file_put_contents($wmsDirLocation.'/.maps/'.$MAP_FILE.'.map','test');
|
|
|
- DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$ID_WMS_MAPS,'MAP_STATUS'=>'GENERATED','MAP_STATUS_INFO'=>'Mapa wygenerowana poprawnie','MAP_URL'=>'https://'.$_SERVER['SERVER_NAME'].'/wms/'.$MAP_FILE,'MAP_FILE'=>$MAP_FILE));
|
|
|
+ $layers=DB::getPDO()->fetchall("select ID,LAYER_NAME,FILE_NAME,EPSG,EXTENT,LAYER_TYPE from WMS_LAYERS where MAP_STATUS='ACTIVE' and ID_WMS_MAPS='".$map['ID']."'");
|
|
|
+ $MAP_LAYERS="";
|
|
|
+ foreach ($layers as $layer) {
|
|
|
+ if ($layer['LAYER_NAME']) $LAYER_NAME=V::convert($layer['LAYER_NAME'],'url');
|
|
|
+ else $LAYER_NAME=$layer['LAYER_TYPE']."_".$layer['ID'];
|
|
|
+ //$destFolderPath = $this->getDirectory($layer['ID']);
|
|
|
+ //$file=$destFolderPath.'/.wms/'.$layer['FILE_NAME'];
|
|
|
+ //if(is_file($file)) $files[]='"'.$file.'"';
|
|
|
+ //else throw new Exception("ERROR - couldn't find file ".$file."\n");
|
|
|
+ $replace=array($LAYER_NAME,$urlLayerType[$layer['LAYER_TYPE']],$layer['ID'],$layer['EXTENT'],$layer['EPSG'],$wmsDirLocation.'/.maps/.template.html');
|
|
|
+ $MAP_LAYERS .= str_replace($layerSearch,$replace,$layerSchema[$layer['LAYER_TYPE']]);
|
|
|
+ $EPSGS['EPSG:'.$layer['EPSG']]=1;
|
|
|
}
|
|
|
+
|
|
|
+ $replace=array($map['MAP_NAME'],$MAP_URL,implode(" ",array_keys($EPSGS)));
|
|
|
+ $MAP_TXT=str_replace($mapHeadSearch,$replace,$mapHeadSchema).$MAP_LAYERS.$mapTailSchema;
|
|
|
+ file_put_contents($wmsDirLocation.'/.maps/'.$MAP_FILE,$MAP_TXT);
|
|
|
+ DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$map['ID'],'MAP_STATUS'=>'GENERATED','MAP_STATUS_INFO'=>'Mapa wygenerowana poprawnie','MAP_URL'=>$MAP_URL,'MAP_FILE'=>$MAP_FILE));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- ### Uzunięcie zbędnych map
|
|
|
+ ### Usunięcie zbędnych map
|
|
|
$maps=DB::getPDO()->fetchall("select ID,MAP_FILE from WMS_MAPS where MAP_STATUS='GENERATED' and A_STATUS!='NORMAL'");
|
|
|
foreach ($maps as $map) {
|
|
|
if (file_exists($wmsDirLocation.'/.maps/'.$map['MAP_FILE'])) unlink($wmsDirLocation.'/.maps/'.$map['MAP_FILE']);
|
|
|
- DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$ID_WMS_MAPS,'MAP_STATUS'=>'NONE','MAP_STATUS_INFO'=>'Mapa usunięta','MAP_URL'=>'','MAP_FILE'=>''));
|
|
|
+ DB::getDB()->UPDATE_OBJ('WMS_MAPS',(object) array('ID'=>$map['ID'],'MAP_STATUS'=>'NONE','MAP_STATUS_INFO'=>'Mapa usunięta','MAP_URL'=>'','MAP_FILE'=>''));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -247,11 +470,10 @@ else
|
|
|
cp tmp/generate_wms-__ID__.log __PATH__/.wms/.error
|
|
|
echo "Error creating tif file."
|
|
|
fi
|
|
|
-cp tmp/generate_wms-__ID__.log __PATH__/.wms/.test
|
|
|
';
|
|
|
$search=array('__ID__','__PATH__','__FILE__');
|
|
|
|
|
|
- $layers=DB::getPDO()->fetchall("select ID,FILE_NAME from WMS_LAYERS where FILE_STATUS='TO_GENERATE'");
|
|
|
+ $layers=DB::getPDO()->fetchall("select ID,FILE_NAME from WMS_LAYERS where LAYER_TYPE='GeoTIFF' and FILE_STATUS='TO_GENERATE'");
|
|
|
foreach ($layers as $layer) {
|
|
|
$destFolderPath = $this->getDirectory($layer['ID']);
|
|
|
if(!is_file($destFolderPath.'/'.$layer['FILE_NAME'])) {
|
|
|
@@ -289,7 +511,7 @@ cp tmp/generate_wms-__ID__.log __PATH__/.wms/.test
|
|
|
public function reinstall() {
|
|
|
$sqlList = array();
|
|
|
//$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_CONFIG`";
|
|
|
- $sqlList['InstallTable'] = <<<SQL
|
|
|
+/* $sqlList['InstallTable'] = <<<SQL
|
|
|
CREATE TABLE IF NOT EXISTS `WMS_LAYERS` (
|
|
|
`ID` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
`the_geom` polygon NOT NULL,
|
|
|
@@ -357,7 +579,7 @@ CREATE TABLE IF NOT EXISTS `WMS_LAYERS_HIST` (
|
|
|
PRIMARY KEY (`ID`)
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=latin2;
|
|
|
SQL;
|
|
|
-
|
|
|
+*/
|
|
|
$sqlList['ActivateWms'] = <<<SQL
|
|
|
REPLACE INTO `CRM_CONFIG` (`CONF_KEY`,`CONF_VAL`) VALUES ('module_WMS','on');
|
|
|
SQL;
|