Esempio n. 1
0
     echo "{\"attributes\":" . json_encode($result) . "}";
     // Request = ask for field type
 } else {
     if ($operation == 'getattributetype') {
         $attributeType = '';
         $attributeName = $_REQUEST['attributename'];
         if ($attributeName && $layerName) {
             $msLayer = $map->getLayerByName($layerName);
             if ($msLayer && ($msLayer->connectiontype == MS_POSTGIS || $msLayer->connectiontype == MS_ORACLESPATIAL)) {
                 // get dns string containing : type of database, user name, password, host and database :
                 $dsn = PluginsMapUtils::getDSNConnection($msLayer);
                 if ($dsn) {
                     // data substitution :
                     $data = PluginsMapUtils::getQueryParamsFromDataString($msLayer, false, true);
                     // DB :
                     $edb = new Easy_MDB2();
                     $edb->setDSN($dsn);
                     $edb->start();
                     // Query :
                     $db_table = $data['db_table'];
                     $mdb2FieldType = $edb->getFieldType($db_table, $attributeName);
                     switch ($mdb2FieldType) {
                         case 'integer':
                         case 'decimal':
                         case 'float':
                         case 'boolean':
                             $attributeType = 'N';
                             break;
                         case 'text':
                         case 'date':
                         case 'time':
Esempio n. 2
0
 public static function calculateExtent($map, $groups, $applyMapExtentIfNull = false, $addBuffer = false)
 {
     $mapExtent = ms_newrectObj();
     $layers = getLayersByGroupOrLayerName($map, $groups);
     foreach ($layers as $layer) {
         $layerExtent = false;
         if ($layer) {
             if ($layer->connectiontype == MS_POSTGIS || $layer->connectiontype == MS_ORACLESPATIAL) {
                 //get dns string containing : type of database, user name, password, host and database.
                 $dsn = PluginsMapUtils::getDSNConnection($layer);
                 if ($dsn) {
                     // code from mapserver mailing list (by Armin Burger):
                     // get table and filter :
                     $data = PluginsMapUtils::getQueryParamsFromDataString($layer, false, false);
                     $mapLayerFilter = $data['mapLayerFilter'];
                     $fromTable = $data['fromTable'];
                     $geomFld = $data['geomFld'];
                     $sql = 'SELECT ST_xmin(extent) AS minx, ST_ymin(extent) AS miny, ST_xmax(extent) AS maxx, ST_ymax(extent) AS maxy ';
                     $sql .= "FROM (SELECT St_Extent({$geomFld}) AS extent FROM {$fromTable} ";
                     $sql .= ($mapLayerFilter ? "WHERE {$mapLayerFilter}" : '') . ' ';
                     $sql .= ') AS bar';
                     $sql .= ' WHERE extent IS NOT NULL';
                     pm_logDebug(4, "calculateExtent - sql:{$sql}");
                     // DB:
                     require_once dirname(__FILE__) . '/easyMDB2.inc.php';
                     $edb = new Easy_MDB2();
                     $edb->setDSN($dsn);
                     $edb->start();
                     $qresultE = $edb->selectByQuery($sql, '');
                     $resValues = $qresultE['values'][0];
                     if ($resValues) {
                         $resIsValid = true;
                         foreach ($resValues as $val) {
                             if (!isset($val) || $val == 0 || $val == -1) {
                                 $resIsValid = false;
                                 break;
                             }
                         }
                         if ($resIsValid) {
                             $layerExtent = ms_newRectObj();
                             $layerExtent->setExtent($resValues['minx'], $resValues['miny'], $resValues['maxx'], $resValues['maxy']);
                         }
                     }
                 }
             } else {
                 if ($layer->type != MS_LAYER_RASTER && ($layer->connectiontype == MS_SHAPEFILE || $layer->connectiontype == MS_TILED_SHAPEFILE || $layer->connectiontype == MS_OGR)) {
                     // SHP layer, OGR layer
                     $layerExtent = @$layer->getExtent();
                 }
             }
             if ($layerExtent) {
                 // change projection
                 $mapProjStr = $map->getProjection();
                 $layerProjStr = $layer->getProjection();
                 if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) {
                     if ($_SESSION['MS_VERSION'] < 6) {
                         $mapProjObj = ms_newprojectionobj($mapProjStr);
                         $layerProjObj = ms_newprojectionobj($layerProjStr);
                     } else {
                         $mapProjObj = new projectionObj($mapProjStr);
                         $layerProjObj = new projectionObj($layerProjStr);
                     }
                     $layerExtent->project($layerProjObj, $mapProjObj);
                 }
                 // add buffer around freshly calculated extent
                 if ($addBuffer) {
                     $minx = $layerExtent->minx;
                     $miny = $layerExtent->miny;
                     $maxx = $layerExtent->maxx;
                     $maxy = $layerExtent->maxy;
                     $pointBuffer = isset($_SESSION['pointBuffer']) ? $_SESSION['pointBuffer'] : 50;
                     $shapeQueryBuffer = isset($_SESSION['shapeQueryBuffer']) ? $_SESSION['shapeQueryBuffer'] : 0.01;
                     $buf = 0;
                     if ($layer->type == MS_LAYER_POINT || $layer->type == MS_LAYER_ANNOTATION) {
                         $buf = $pointBuffer;
                         // set buffer depending on dimensions of your coordinate system
                     } else {
                         if (isset($shapeQueryBuffer) && $shapeQueryBuffer > 0) {
                             $buf = $shapeQueryBuffer * (($maxx - $minx + ($maxy - $miny)) / 2);
                         }
                     }
                     if ($buf > 0) {
                         $minx -= $buf;
                         $miny -= $buf;
                         $maxx += $buf;
                         $maxy += $buf;
                         $layerExtent->setExtent($minx, $miny, $maxx, $maxy);
                     }
                 }
                 if ($mapExtent->minx == -1 && $mapExtent->miny == -1 && $mapExtent->maxx == -1 && $mapExtent->maxy == -1) {
                     $minx = $layerExtent->minx;
                     $miny = $layerExtent->miny;
                     $maxx = $layerExtent->maxx;
                     $maxy = $layerExtent->maxy;
                 } else {
                     $minx = $layerExtent->minx < $mapExtent->minx ? $layerExtent->minx : $mapExtent->minx;
                     $miny = $layerExtent->miny < $mapExtent->miny ? $layerExtent->miny : $mapExtent->miny;
                     $maxx = $layerExtent->maxx > $mapExtent->maxx ? $layerExtent->maxx : $mapExtent->maxx;
                     $maxy = $layerExtent->maxy > $mapExtent->maxy ? $layerExtent->maxy : $mapExtent->maxy;
                 }
                 $mapExtent->setExtent($minx, $miny, $maxx, $maxy);
             }
         }
     }
     if ($mapExtent->minx == -1 || $mapExtent->miny == -1 || $mapExtent->maxx == -1 || $mapExtent->maxy == -1) {
         $mapExtent = $map->extent;
         if (!$applyMapExtentIfNull) {
             $mapExtent->setExtent(0, 0, 1, 1);
         }
     }
     return $mapExtent;
 }