Esempio n. 1
0
 function __construct()
 {
     if (\app\inc\Input::getPath()->part(3) == "tilecache") {
         $postgisschema = \app\inc\Input::getPath()->part(4);
     } else {
         $postgisschema = \app\inc\Input::getPath()->part(3);
     }
     $db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $db);
     if (sizeof($dbSplit) == 2) {
         $db = $dbSplit[1];
     }
     $path = App::$param['path'] . "/app/wms/mapfiles/";
     $name = $db . "_" . $postgisschema . ".map";
     $oMap = new \mapObj($path . $name);
     $request = new \OWSRequestObj();
     if ($_SERVER['REQUEST_METHOD'] === 'GET') {
         foreach ($_GET as $k => $v) {
             if (strtolower($k) == "layers" || strtolower($k) == "layer" || strtolower($k) == "typename" || strtolower($k) == "typenames") {
                 $layers = $v;
             }
             $request->setParameter($k, $v);
         }
     } else {
         $request->loadParams();
     }
     if ($_SESSION['http_auth'] != $db) {
         \app\models\Database::setDb($db);
         $postgisObject = new \app\inc\Model();
         foreach (explode(",", $layers) as $layer) {
             $auth = $postgisObject->getGeometryColumns($layer, "authentication");
             $layerSplit = explode(".", $layer);
             $HTTP_FORM_VARS["TYPENAME"] = $layerSplit[1];
             if ($auth == "Read/write") {
                 include 'inc/http_basic_authen.php';
             } else {
                 include 'inc/http_basic_authen_subuser.php';
             }
         }
     }
     ms_ioinstallstdouttobuffer();
     $oMap->owsdispatch($request);
     $contenttype = ms_iostripstdoutbuffercontenttype();
     if ($contenttype == 'image/png') {
         header('Content-type: image/png');
     } else {
         header('Content-type: text/xml');
     }
     ms_iogetStdoutBufferBytes();
     print "<!--\n";
     include "README";
     print "\n-->\n";
     ms_ioresethandlers();
 }
Esempio n. 2
0
 function __construct()
 {
     if (\app\inc\Input::getPath()->part(3) == "tilecache") {
         $postgisschema = \app\inc\Input::getPath()->part(4);
     } else {
         $postgisschema = \app\inc\Input::getPath()->part(3);
     }
     $db = \app\inc\Input::getPath()->part(2);
     $dbSplit = explode("@", $db);
     if (sizeof($dbSplit) == 2) {
         $db = $dbSplit[1];
     }
     $path = App::$param['path'] . "/app/wms/mapfiles/";
     $name = $db . "_" . $postgisschema . ".map";
     $oMap = new \mapObj($path . $name);
     $request = new \OWSRequestObj();
     if ($_SERVER['REQUEST_METHOD'] === 'GET') {
         foreach ($_GET as $k => $v) {
             if (strtolower($k) == "layers" || strtolower($k) == "layer" || strtolower($k) == "typename" || strtolower($k) == "typenames") {
                 $layers = $v;
             }
             $request->setParameter($k, $v);
         }
     } else {
         $request->loadParams();
     }
     if ($_SESSION['http_auth'] != $db) {
         \app\models\Database::setDb($db);
         $postgisObject = new \app\inc\Model();
         foreach (explode(",", $layers) as $layer) {
             $auth = $postgisObject->getGeometryColumns($layer, "authentication");
             $layerSplit = explode(".", $layer);
             $HTTP_FORM_VARS["TYPENAME"] = $layerSplit[1];
             if ($auth == "Read/write") {
                 include 'inc/http_basic_authen.php';
             } else {
                 include 'inc/http_basic_authen_subuser.php';
             }
         }
     }
     if ($_GET['sql_layer']) {
         include '../libs/functions.php';
         include '../conf/main.php';
         $postgisdb = "mydb";
         $request->setParameter("SLD_BODY", "<StyledLayerDescriptor version='1.1.0'><NamedLayer><Name>sql</Name><UserStyle><Title>xxx</Title><FeatureTypeStyle><Rule><LineSymbolizer><Stroke><CssParameter name='stroke'>#FFFF00</CssParameter><CssParameter name='stroke-width'>15</CssParameter></Stroke></LineSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>\n                ");
         $postgisObj = new postgis();
         $postgisObj2 = new postgis();
         $view = "public.hello";
         $sqlView = "CREATE VIEW {$view} as " . urldecode($_GET['sql_layer']);
         $postgisObj->connect();
         $postgisObj->execQuery($sqlView);
         $postgisObj->execQuery("CREATE SEQUENCE _serial START 1");
         $arrayWithFields = $postgisObj2->getMetaData($view);
         foreach ($arrayWithFields as $key => $arr) {
             if ($arr['type'] == "geometry") {
                 $fieldsArr[] = "transform(" . $key . ",900913) as the_geom";
             } else {
                 $fieldsArr[] = $key;
             }
         }
         $fieldsArr[] = "nextval('_serial') as _serial";
         $sql = implode(",", $fieldsArr);
         $sql = "SELECT {$sql} FROM {$view}";
         $request->setParameter("LAYERS", $_GET['LAYERS'] . ",sql");
         $layer = ms_newLayerObj($oMap);
         $layer->updateFromString("\n\tLAYER\n\t\tNAME 'sql'\n\t\tSTATUS off\n\t\tPROCESSING 'CLOSE_CONNECTION=DEFER'\n\t\tDATA \"the_geom from ({$sql}) as foo using unique _serial using srid=900913\"\n\t\tTYPE POLYGON\n\t\tCONNECTIONTYPE POSTGIS\n\t\tCONNECTION 'user=postgres dbname=mydb host=127.0.0.1'\n\t\tMETADATA\n\t\t  'wms_title'    'sql'\n\t\t  'wms_srs'    'EPSG:4326'\n\t\t  'wms_name'    'sql'\n\t\tEND\n\t\tPROJECTION\n\t\t  'init=epsg:900913'\n\t\tEND\n\t\tCLASS\n\t\t  NAME 'New style'\n\t\t  STYLE\n\t\t\tOUTLINECOLOR 255 0 0\n\t\t  END\n  \t\tEND\n  \tEND\n\t");
     }
     ms_ioinstallstdouttobuffer();
     $oMap->owsdispatch($request);
     if ($_GET['sql_layer']) {
         $sql = "DROP VIEW {$view}";
         $result = $postgisObj->execQuery($sql);
     }
     $contenttype = ms_iostripstdoutbuffercontenttype();
     if ($contenttype == 'image/png') {
         header('Content-type: image/png');
     } else {
         header('Content-type: text/xml');
     }
     ms_iogetStdoutBufferBytes();
     ms_ioresethandlers();
 }
Esempio n. 3
0
        $req->setParameter("SRS", "EPSG:3857");
        $_GET["SRS"] = "EPSG:3857";
    }
}
ms_ioinstallstdouttobuffer();
//o LAYER pode ter um nome randomico em funcao de ser um plugin
$l = $oMap->getlayer(0);
if ($req->getValueByName("LAYERS") != $l->name) {
    $req->setParameter("LAYERS", $l->name);
}
//verifica parametro outputformat
if (strtolower($req->getValueByName("REQUEST")) == "getmap" && $req->getValueByName("format") == "") {
    $req->setParameter("format", "image/png");
}
$oMap->owsdispatch($req);
$contenttype = ms_iostripstdoutbuffercontenttype();
if (!isset($OUTPUTFORMAT)) {
    header("Content-type: {$contenttype}");
}
$buffer = ms_iogetStdoutBufferBytes();
ms_ioresethandlers();
function texto2iso($texto)
{
    if (function_exists("mb_convert_encoding")) {
        if (mb_detect_encoding($texto, "UTF-8", true)) {
            $texto = mb_convert_encoding($texto, "ISO-8859-1", "UTF-8");
        }
    }
    return $texto;
}
function nomeRand($n = 10)
Esempio n. 4
0
 public function getMapImage(Request $request)
 {
     //tutti i parametri in minuscolo
     $getRequestParams = $request->query->all();
     $requestParams = array();
     foreach ($getRequestParams as $key => $val) {
         $requestParams[strtolower($key)] = $val;
     }
     //prendo il parametro layers, dove ci sono le linee da visualizzare in formato li_nr:str_li_var
     $layers = explode(',', $requestParams['layers']);
     if (count($layers) > 1 || $layers[0] != 'all') {
         $lines = array();
         $whereClauses = array();
         foreach ($layers as $layer) {
             if (!strpos($layer, ':')) {
                 throw new Exception('Invalid layers parameter');
             }
             list($line, $var) = explode(':', $layer);
             array_push($lines, (int) $line);
             if (!preg_match('/[0-9a-z]+/i', $var)) {
                 throw new Exception('Invalid var paramter');
             }
             array_push($whereClauses, "(rec_lid.li_nr = " . (int) $line . " and rec_lid.str_li_var = '{$var}')");
         }
     }
     $sql = "select li_nr, li_r, li_g, li_b from vdv.line_attributes";
     if (isset($lines)) {
         $sql .= " where li_nr in (" . implode(',', $lines) . ")";
     }
     $res = $this->connection->query($sql);
     $classes = $res->fetchAll(\PDO::FETCH_ASSOC);
     /*         $classes = array(
                 array('li_nr'=>201, 'li_r'=>255, 'li_g'=>0, 'li_b'=>0),
                 array('li_nr'=>211, 'li_r'=>0, 'li_g'=>255, 'li_b'=>0),
             ); */
     $layerData = "the_geom FROM (SELECT rec_lid.li_nr, rec_lid.str_li_var, rec_lid.li_nr || ':' || rec_lid.str_li_var as gc_objid, ST_Collect(ort_edges.the_geom) AS the_geom FROM vdv.rec_lid INNER JOIN vdv.lid_verlauf ON rec_lid.li_nr=lid_verlauf.li_nr AND rec_lid.str_li_var=lid_verlauf.str_li_var INNER JOIN vdv.lid_verlauf next_verlauf ON rec_lid.li_nr=next_verlauf.li_nr AND rec_lid.str_li_var=next_verlauf.str_li_var AND lid_verlauf.li_lfd_nr+1=next_verlauf.li_lfd_nr LEFT JOIN vdv.ort_edges ON lid_verlauf.ort_nr=ort_edges.start_ort_nr AND lid_verlauf.onr_typ_nr=ort_edges.start_onr_typ_nr AND next_verlauf.ort_nr=ort_edges.end_ort_nr AND next_verlauf.onr_typ_nr=ort_edges.end_onr_typ_nr ";
     // $layerData = "the_geom from (select the_geom, li_nr, li_nr || ':' || str_li_var as gc_objid from vdv.rec_lid ";
     if (isset($whereClauses)) {
         $layerData .= "where " . implode(' OR ', $whereClauses);
     }
     $layerData .= "GROUP BY rec_lid.li_nr, rec_lid.str_li_var) AS foo USING UNIQUE gc_objid USING SRID=25832";
     //  echo $layerData; die();
     //TODO: pescarlo da resources!
     $mapfilePath = __DIR__ . '/../../Resources/config/lines_mapfile.map';
     $map = ms_newMapobj($mapfilePath);
     $layer = $map->getLayerByName('g_lines.line');
     $layer->set('data', $layerData);
     foreach ($classes as $n => $classConfig) {
         $class = ms_newClassObj($layer);
         $class->set('name', 'dynamic_class_' . $n);
         $class->setExpression("('[li_nr]' eq '" . $classConfig['li_nr'] . "')");
         $style = ms_newStyleObj($class);
         $style->color->setRGB($classConfig['li_r'], $classConfig['li_g'], $classConfig['li_b']);
         $style->outlinecolor->setRGB($classConfig['li_r'], $classConfig['li_g'], $classConfig['li_b']);
         $style->set('size', 3);
         $style->set('width', 3);
         //$style->width = 2;
         //$style->symbol = 'CIRCLE';
     }
     $objRequest = ms_newOwsrequestObj();
     $presetParams = array('layers' => 'g_lines.line', 'map' => null);
     foreach ($requestParams as $key => $value) {
         if (!is_string($key)) {
             continue;
         }
         if (!empty($presetParams[$key])) {
             $objRequest->setParameter($key, $presetParams[$key]);
         } else {
             $objRequest->setParameter($key, stripslashes($value));
         }
     }
     ms_ioinstallstdouttobuffer();
     $map->save('/tmp/debug.map');
     $map->owsdispatch($objRequest);
     $contentType = ms_iostripstdoutbuffercontenttype();
     //accrocchio, ma ms_iogetstdoutbufferstring() non funziona, mi da sempre una immagine vuota!
     ob_start();
     ms_iogetStdoutBufferBytes();
     $image = ob_get_contents();
     ob_end_clean();
     //die($image);
     ms_ioresethandlers();
     return array($contentType, $image);
 }