示例#1
0
 function __construct($driverName, $exportExt, $json, $map, $bExportAtt = false, $optDataSourceCreation = NULL, $bSearchSpatialRef = false)
 {
     $bOk = false;
     $msVersion = null;
     // MapServer version
     $groups = null;
     // Layers list that will be exported
     parent::__construct($json);
     OGRRegisterAll();
     // looking for destination driver
     for ($iDriver = 0; $iDriver < OGRGetDriverCount() && !$bOk; $iDriver++) {
         if (!strcasecmp(OGR_DR_GetName(OGRGetDriver($iDriver)), $driverName)) {
             $this->driverOGRDest = OGRGetDriver($iDriver);
             $bOk = true;
             break;
         }
     }
     if ($bOk) {
         // is it possible to create new data source with current driver
         if (!OGR_Dr_TestCapability($this->driverOGRDest, ODrCCreateDataSource)) {
             $this->driverOGRDest = null;
             $bOk = false;
             return;
         }
     }
     if ($bOk) {
         $msVersion = $_SESSION['MS_VERSION'];
         $groups = (array) $this->jsonList[0];
         // Create the destination directory
         @mkdir($this->tempFilePath, 0700);
         // for each layers that will be exported
         foreach ($groups as $grp) {
             $baseDest = null;
             $layerList = array();
             $attNameList = $grp->header;
             $ObjList = $grp->values;
             if (!$ObjList[0][0]->shplink) {
                 continue;
             }
             // if we need to export attributs
             if ($bExportAtt) {
                 include_once '../common/pluginsMapUtils.inc.php';
                 for ($iAtt = 0; $iAtt < count($attNameList); $iAtt++) {
                     if ($attNameList[$iAtt] == '@') {
                         array_splice($attNameList, $iAtt, 1);
                         $iAtt--;
                         continue;
                     }
                     // remove accents and spaces:
                     $newAttName = PluginsMapUtils::decodeMapFileVal($map, $attNameList[$iAtt], 'UTF-8');
                     $newAttName = str_replace($this->bad, $this->good, $attNameList[$iAtt]);
                     if (is_numeric($newAttName[0])) {
                         $newAttName = 'z' . $newAttName;
                     }
                     $attNameList[$iAtt] = $newAttName;
                 }
             }
             // for each objects that we want to export
             foreach ($ObjList as $Obj) {
                 $layerSrc = null;
                 // Source layer
                 $layerDest = null;
                 // Destination layer
                 $baseDest = null;
                 // Destination DataBase
                 $geoType = 0;
                 $shpLink = $Obj[0]->shplink;
                 $layerName = $shpLink[0];
                 $IdObj = $shpLink[1];
                 // if it's the first time we found current layer
                 if (!isset($layerList[$layerName])) {
                     // getting mapserver layer
                     $layerSrc = $map->getLayerByName($layerName);
                     // use layers with complex queries that are too long to select results
                     $newdata = $layerSrc->getMetaData('PM_RESULT_DATASUBSTITION');
                     if ($newdata != '') {
                         $layerSrc->set('data', $newdata);
                     }
                     // create destination data base
                     $output = $this->tempFilePath . "\\{$layerName}.{$exportExt}";
                     $output = str_replace('/', '\\', $output);
                     $baseDest = OGR_Dr_CreateDataSource($this->driverOGRDest, $output, $optDataSourceCreation);
                     if (!$baseDest) {
                         continue;
                     }
                     // is it possible to create new layers in current data source ?
                     if (!OGR_DS_TestCapability($baseDest, ODsCCreateLayer)) {
                         if ($baseDest) {
                             OGR_DS_Destroy($baseDest);
                         }
                         continue;
                     }
                     // create new layer in the destination data base
                     $geoType = $this->typeList[$layerSrc->type];
                     $layerDest = $this->createNewLayer($map, $baseDest, $layerName, $geoType, $bSearchSpatialRef);
                     // add new attribut in destination layer
                     if ($bExportAtt) {
                         $idAtt = 0;
                         foreach ($attNameList as $attName) {
                             $att = OGR_Fld_Create($attName, OFTString);
                             OGR_L_CreateField($layerDest, $att, $idAtt);
                             $idAtt++;
                         }
                     }
                     // saving all in layerList
                     $layerList[$layerName] = array();
                     $layerList[$layerName][] = $layerSrc;
                     $layerList[$layerName][] = $baseDest;
                     $layerList[$layerName][] = $layerDest;
                     $layerList[$layerName][] = $geoType;
                     // add file to files list will be exorted
                     $this->addFileToFileList($output);
                 } else {
                     $layerSrc = $layerList[$layerName][0];
                     $baseDest = $layerList[$layerName][1];
                     $layerDest = $layerList[$layerName][2];
                     $geoType = $layerList[$layerName][3];
                 }
                 // gettint shape object
                 $srcShp = PMCommon::resultGetShape($msVersion, $layerSrc, null, $IdObj, -1);
                 // export geometry of the object in WKT
                 $geoWKT = $srcShp->toWkt();
                 // create new geometry OGR object from WKT geometry
                 $geoOGR = $this->createNewOGRGeometry($geoWKT);
                 // create new data line on destination layer
                 $layerDestDefn = OGR_L_GetLayerDefn($layerDest);
                 $Data = OGR_F_Create($layerDestDefn);
                 // add geometry in data line
                 OGR_F_SetGeometry($Data, $geoOGR);
                 // if we need to export attributs
                 if ($bExportAtt) {
                     // add attributs values in data line
                     for ($iAtt = 1; $iAtt < count($Obj); $iAtt++) {
                         $newAttVal = PluginsMapUtils::decodeLayerVal($map, $layerName, $Obj[$iAtt], 'UTF-8');
                         OGR_F_SetFieldString($Data, $iAtt - 1 + $this->nbFieldBase, $newAttVal);
                     }
                 }
                 $this->insertSpecialFields($geoType, $layerDestDefn, $Data);
                 // add data line in destination layer
                 OGR_L_CreateFeature($layerDest, $Data);
                 OGR_F_Destroy($Data);
                 OGR_G_DestroyGeometry($geoOGR);
             }
             foreach ($layerList as $l) {
                 if (isset($l[1]) && $l[1]) {
                     OGR_DS_Destroy($l[1]);
                 }
             }
         }
         // files compression
         $this->zipFiles();
         // remove directory
         rmdir($this->tempFilePath);
     }
 }
示例#2
0
 /**
  * Init function
  */
 function __construct($json, $map)
 {
     parent::__construct($json);
     $msVersion = $_SESSION['MS_VERSION'];
     $grouplist = $_SESSION['grouplist'];
     //pm_logDebug(3, $grouplist, 'grouplist in exportSHP');
     $groups = (array) $this->jsonList[0];
     $fileList = array();
     $valueList = array();
     $dbfFieldList = array();
     $cpyPrjFile = '';
     @mkdir($this->tempFilePath, 0700);
     foreach ($groups as $grp) {
         $layerNameList = array();
         $layerList = array();
         $values = $grp->values;
         if (!$values[0][0]->shplink) {
             continue;
         }
         // headers with invalid characters
         include_once '../common/pluginsMapUtils.inc.php';
         $headerListTmp = $grp->header;
         $headerList = array();
         foreach ($headerListTmp as $n => $h) {
             if ($h != '@') {
                 $newHeader = PluginsMapUtils::decodeMapFileVal($map, $h, 'ISO-8859-1');
                 // remove accents and spaces:
                 // adpated from http://www.lecoindunet.com/zone_php/scripts_utiles/remplacer-les-caracteres-accentues-dune-chaine-en-php-72
                 $bad = array(' ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
                 $good = array('_', 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
                 $newHeader = str_replace($bad, $good, $newHeader);
                 // upper case
                 $newHeader = strtoupper($newHeader);
                 // if header already exists :'FIELD_' + index
                 if (in_array($newHeader, $headerList)) {
                     $newHeader = "FIELD_{$n}";
                 }
                 $headerList[] = $newHeader;
                 // if '@' not at the beginning
             } else {
                 if ($n != 0) {
                     $headerList = array();
                     break;
                 }
             }
         }
         foreach ($values as $vList) {
             $dbfRow = array();
             foreach ($vList as $n => $v) {
                 if ($shplink = $v->shplink) {
                     //pm_logDebug(3, $shplink, "shplink");
                     $layerName = $shplink[0];
                     $shpIdxTmp = $shplink[1];
                     $shpIdx = preg_replace('/^.*@/', '', $shpIdxTmp);
                     $tileShpIdx = -1;
                     if (!in_array($layerName, $layerNameList)) {
                         $typeList = array(MS_SHP_POINT, MS_SHP_ARC, MS_SHP_POLYGON);
                         $srcLayer = $map->getLayerByName($layerName);
                         // use layers with complex queries that are too long to select results
                         $newdata = $srcLayer->getMetaData('PM_RESULT_DATASUBSTITION');
                         if ($newdata != '') {
                             $srcLayer->set('data', $newdata);
                         }
                         $srcLayerType = $srcLayer->type;
                         //error_log("type: $srcLayerType");
                         $layerNameList[] = $layerName;
                         $layerList[] = $srcLayer;
                         $valueList[$layerName] = array();
                         $srcLayer->open();
                         //pm_logDebug(3, $layerItems);
                         $outShpFname = "{$this->tempFilePath}/{$layerName}";
                         $shpFile = ms_newShapeFileObj($outShpFname, $typeList[$srcLayerType]);
                         $dbfFileName = "{$outShpFname}.dbf";
                         $cpyPrjFile = '';
                         unset($proj);
                         $proj = $srcLayer->getProjection();
                         if (empty($proj)) {
                             $proj = $map->getProjection();
                         }
                         if (!empty($proj)) {
                             $prjFile = dirname(__FILE__) . "\\shp\\";
                             $pos = strpos($proj, 'epsg:');
                             if ($pos !== false) {
                                 $proj = substr($proj, $pos + 5);
                                 $prjFile .= "{$proj}.prj";
                             }
                             if (file_exists($prjFile) && !is_dir($prjFile)) {
                                 $cpyPrjFile = "{$outShpFname}.prj";
                                 copy($prjFile, $cpyPrjFile);
                             }
                         }
                         $fileList[$layerName] = array();
                         $fileList[$layerName][] = "{$outShpFname}.shp";
                         $fileList[$layerName][] = "{$outShpFname}.shx";
                         $fileList[$layerName][] = $dbfFileName;
                         if (file_exists($cpyPrjFile)) {
                             $fileList[$layerName][] = $cpyPrjFile;
                         }
                     }
                     $srcShp = PMCommon::resultGetShape($msVersion, $srcLayer, null, $shpIdx, -1);
                     // changed for compatibility with PG layers and MS >= 5.6
                     $shpFile->addShape($srcShp);
                 } else {
                     if ($headerList) {
                         $hyperlink = $v->hyperlink;
                         if ($hyperlink) {
                             $val = $hyperlink[2];
                         } else {
                             $val = $v;
                         }
                         $fldName = $headerList[$n - 1];
                         $dbfRow[] = utf8_decode($val);
                         if (!isset($dbfFieldList[$layerName])) {
                             $dbfFieldList[$layerName] = array();
                         }
                         if (!isset($dbfFieldList[$layerName][$fldName])) {
                             $dbfFieldList[$layerName][$fldName] = array();
                         }
                         $dbfFieldList[$layerName][$fldName] = $this->getFieldType(trim($val), $dbfFieldList[$layerName][$fldName]);
                     }
                 }
             }
             $valueList[$layerName][] = $dbfRow;
         }
         // some clean up
         //            PMCommon::freeMsObj($shpFile);
         // shapefileObj: changes are committed only when the object is destroyed
         $shpFile->free();
         unset($shpFile);
         foreach ($layerList as $l) {
             $l->close();
         }
     }
     // write dBase files
     foreach ($fileList as $layerName => $files) {
         $dbfFileName = $fileList[$layerName][2];
         // Modified by Thomas RAFFIN (SIRAP)
         // bug export for groups (with many layers)
         $dbfFieldListTmp = $dbfFieldList[$layerName];
         $valueListTmp = $valueList[$layerName];
         $this->writeDbf($dbfFileName, $dbfFieldListTmp, $valueListTmp);
     }
     // Write all files to zip and remove tmp dir
     $this->tempFileLocation .= '.zip';
     $zipFilePath = "{$this->tempFilePath}.zip";
     $filesToZip = array();
     foreach ($fileList as $files) {
         foreach ($files as $file) {
             $filesToZip[] = $file;
         }
     }
     PMCommon::packFilesZip($zipFilePath, $filesToZip, true, true);
     rmdir($this->tempFilePath);
 }
示例#3
0
 /**
  * EXECUTE QUERY
  */
 public function q_execMapQuery()
 {
     //--------------------------------
     // Initialize tolerance to 0
     //--------------------------------
     $msLayers = array();
     // query in specified groups only:
     if (isset($_REQUEST['groups']) && $_REQUEST['groups']) {
         $msLayers = getLayersByGroupOrLayerName($this->map, $_REQUEST['groups']);
         // all groups:
     } else {
         for ($i = 0; $i < $this->map->numlayers; $i++) {
             $msLayers[] = $this->map->getLayer($i);
         }
     }
     foreach ($msLayers as $msLayer) {
         // change tolerance only for buffer zone search.
         if ($this->queryType == 'object') {
             $msLayer->set('tolerance', 0);
         }
     }
     // Modified by Thomas RAFFIN (SIRAP)
     // to test (substitution)
     // query by point
     // Modified by Thomas RAFFIN (SIRAP)
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     $oldDatas = array();
     for ($i = 0; $i < $this->map->numlayers; $i++) {
         $qLayer = $this->map->getLayer($i);
         $layerName = $qLayer->name;
         if ($qLayer->getMetaData('PM_RESULT_DATASUBSTITION') != '') {
             $oldDatas[$layerName] = $qLayer->data;
             $qLayer->set('data', $qLayer->getMetaData('PM_RESULT_DATASUBSTITION'));
         }
     }
     // few lines from incphp/query/query.php
     // Patch from Alessandro Pasotti for fixing problems with result returned
     $this->map->setSize($this->mapwidth, $this->mapheight);
     // Set $this->map->extent to values of current map extent
     // otherwise values of TOLERANCE in map file are not interpreted correctly
     $this->map->setExtent($this->GEOEXT['minx'], $this->GEOEXT['miny'], $this->GEOEXT['maxx'], $this->GEOEXT['maxy']);
     $this->map->preparequery();
     if ($this->queryType == 'object') {
         if (isset($_SESSION['pluginsConfig']['graphicalqueries']) && isset($_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'])) {
             $bufferOnlyWithScale = $_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'] == 1;
         } else {
             $bufferOnlyWithScale = true;
         }
         if (!$bufferOnlyWithScale) {
             //				PMCommon::setGroups($this->map, $this->querygroups, $this->scale, 0, 1);
             PMCommon::setGroups($this->map, $this->querygroups, 0, 0, 1);
         }
         // Search selected object
         $jsonPMResult = $_SESSION['JSON_Results'];
         // "[...]" ou "{...}"
         $PMResult = json_decode($jsonPMResult);
         // array ou class
         if ($PMResult) {
             $objUnion = false;
             // List layer of selected object
             $layersWithResult = $PMResult[0];
             // be carreful : 0.000000001 is too small !!
             $smallBuffer = 1.0E-8;
             $mapProjStr = $this->map->getProjection();
             if ($_SESSION['MS_VERSION'] < 6) {
                 $mapProjObj = ms_newprojectionobj($mapProjStr);
             } else {
                 $mapProjObj = new projectionObj($mapProjStr);
             }
             // Loop on layers
             $layerName = '';
             foreach ($layersWithResult as $layerWithResult) {
                 $objUnionLayer = false;
                 // init layer to close the last open one
                 $layer = false;
                 $layerProjObj = false;
                 // Loop on layer objects
                 foreach ($layerWithResult->values as $selectedObject) {
                     // layer name
                     $currentLayerName = $selectedObject[0]->shplink[0];
                     if ($currentLayerName != $layerName) {
                         if ($layer) {
                             $layer->close();
                         }
                         $layerName = $currentLayerName;
                         $layer = $this->map->getLayerByName($layerName);
                         $layerProjObj = false;
                         $layerProjStr = $layer->getProjection();
                         if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) {
                             if ($_SESSION['MS_VERSION'] < 6) {
                                 $layerProjObj = ms_newprojectionobj($layerProjStr);
                             } else {
                                 $layerProjObj = new projectionObj($layerProjStr);
                             }
                         }
                         $layer->open();
                     }
                     $shpIndex = $selectedObject[0]->shplink[1];
                     // Retrieve shape by its index.
                     $objShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $layer, null, $shpIndex, -1);
                     // changed for compatibility with PG layers and MS >= 5.6
                     // reproject
                     if ($layerProjObj) {
                         $objShape->project($layerProjObj, $mapProjObj);
                     }
                     // Union of the shapes
                     if ($objUnionLayer) {
                         $objUnionLayer = $objShape->union($objUnionLayer);
                     } else {
                         $objUnionLayer = $objShape;
                     }
                 }
                 // End foreach : Loop of the layer
                 // close layer if exists
                 if ($layer) {
                     $layer->close();
                 }
                 if ($objUnionLayer) {
                     // Line : Buffer to convert Line or Point to Polygon
                     if ($objUnionLayer->type == MS_SHAPE_LINE && isset($_REQUEST['select_buffer']) && $_REQUEST['select_buffer'] > 0 || $objUnionLayer->type == MS_SHAPE_POINT) {
                         $objUnionLayer = $objUnionLayer->buffer($smallBuffer);
                         // if polygon -> the outline is removed to not select contiguous objects
                     } else {
                         if ($objUnionLayer->type == MS_SHAPE_POLYGON && !isset($_REQUEST['select_buffer'])) {
                             $objBoundary = $objUnionLayer->boundary();
                             $objBoundary = $objBoundary->buffer($smallBuffer);
                             $objUnionLayer = $objUnionLayer->difference($objBoundary);
                         }
                     }
                 }
                 if ($objUnionLayer) {
                     if ($objUnion) {
                         $objUnion = $objUnion->union($objUnionLayer);
                     } else {
                         $objUnion = $objUnionLayer;
                     }
                 }
                 // End if($objUnionLayer)
             }
             // End foreach : loop of layers
             // Buffer -> Buffer zone
             if (isset($_REQUEST['select_buffer'])) {
                 if ($objUnion) {
                     $objUnion = $objUnion->buffer($_REQUEST['select_buffer']);
                     unset($_REQUEST['select_buffer']);
                 }
             }
             if ($objUnion) {
                 // Query
                 @$this->map->queryByShape($objUnion);
             }
         }
         // Query by point
     } else {
         if ($this->queryType == 'point') {
             $tmpPoint = ms_newPointObj();
             $tmpPoint->setXYZ($_REQUEST['select_pointX'], $_REQUEST['select_pointY'], 0);
             if (isset($_REQUEST['select_buffer'])) {
                 @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $_REQUEST['select_buffer']);
             } else {
                 @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, -1);
             }
             PMCommon::freeMsObj($tmpPoint);
             // query by Shape
         } else {
             if ($this->queryType == 'polygon') {
                 //'shape')
                 $poly = $_REQUEST['select_poly'];
                 $tmpLine = ms_newLineObj();
                 $tmpPoly = explode(',', $poly);
                 foreach ($tmpPoly as $point) {
                     $tmpTab = explode(' ', $point);
                     $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                 }
                 $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON);
                 $objPoly->add($tmpLine);
                 // Buffer -> Buffer zone
                 if (isset($_REQUEST['select_buffer'])) {
                     $objPoly = $objPoly->buffer($_REQUEST['select_buffer']);
                     unset($_REQUEST['select_buffer']);
                 }
                 @$this->map->queryByShape($objPoly);
                 PMCommon::freeMsObj($tmpLine);
                 PMCommon::freeMsObj($objPoly);
                 // query by PolyLine
             } else {
                 if ($this->queryType == 'line') {
                     $poly = $_REQUEST['select_line'];
                     $tmpLine = ms_newLineObj();
                     $tmpPoly = explode(',', $poly);
                     foreach ($tmpPoly as $point) {
                         $tmpTab = explode(' ', $point);
                         $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                     }
                     // Reduce the polygon to a polyline
                     for ($i = count($tmpPoly) - 1; $i >= 0; $i--) {
                         $tmpTab = explode(' ', $tmpPoly[$i]);
                         $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                     }
                     $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON);
                     $objPoly->add($tmpLine);
                     // Buffer -> Buffer zone
                     if (isset($_REQUEST['select_buffer'])) {
                         $bufferLocal = $_REQUEST['select_buffer'];
                         if ($bufferLocal < 0) {
                             $bufferLocal = 0;
                         }
                         $objPoly = $objPoly->buffer($bufferLocal);
                         unset($_REQUEST['select_buffer']);
                     }
                     @$this->map->queryByShape($objPoly);
                     PMCommon::freeMsObj($tmpLine);
                     PMCommon::freeMsObj($objPoly);
                     // query by circle
                 } else {
                     if ($this->queryType == 'circle') {
                         $point = $_REQUEST['select_point'];
                         $radius = $_REQUEST['select_radius'];
                         $tmpPoint = ms_newPointObj();
                         $tmpTab = explode(' ', $point);
                         $tmpPoint->setXYZ($tmpTab[0], $tmpTab[1], 0);
                         if (isset($_REQUEST['select_buffer'])) {
                             @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius + $_REQUEST['select_buffer']);
                         } else {
                             @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius);
                         }
                         PMCommon::freeMsObj($tmpPoint);
                     }
                 }
             }
         }
     }
     // Modified by Thomas RAFFIN (SIRAP)
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     // reset data tag
     foreach ($oldDatas as $qLayer => $oldData) {
         $qLayer = $this->map->getLayerByName($qLayer);
         $qLayer->set('data', $oldData);
     }
 }
示例#4
0
文件: initmap.php 项目: sukma279/GIS
 /**
  * FUNCTION TO RETURN URL FOR MAPFRAME
  * used for starting application with pre-defined extent
  * extent read from shape features
  */
 function getMapInitURL($map, $zoomLayer, $zoomQuery)
 {
     $qLayer = $this->map->getLayerByName($zoomLayer);
     // Query parameters
     $queryList = preg_split('/@/', $zoomQuery);
     $queryField = $queryList[0];
     $queryFieldType = $queryList[1];
     //$queryValue = "/^" . $queryList[2] ."$/";
     $queryValue = $queryList[2];
     $highlFeature = $queryList[3];
     $setMaxExtent = $queryList[4];
     // Modify filter for PostGIS & Oracle layers
     if ($qLayer->connectiontype == 6 || $qLayer->connectiontype == 8) {
         $q = $queryFieldType == 1 ? "'" : "";
         $queryValue = "{$queryField} = {$q}{$queryValue}{$q}";
         //error_log($queryValue);
     }
     // Query layer
     @$qLayer->queryByAttributes($queryField, $queryValue, MS_MULTIPLE);
     $numResults = $qLayer->getNumResults();
     $qLayer->open();
     // Return query results (SINGLE FEATURE): shape index and feature extent
     /*
     $qRes = $qLayer->getResult(0);
     $qShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $qLayer, $qRes);
     $qShpIdx = $qShape->index;
     $qShpBounds = $qShape->bounds;
     */
     // Check if layer has different projection than map
     // if yes, re-project extent from layer to map projection
     $mapProjStr = $this->map->getProjection();
     $qLayerProjStr = $qLayer->getProjection();
     if ($mapProjStr && $qLayerProjStr && $mapProjStr != $qLayerProjStr) {
         if ($_SESSION['MS_VERSION'] < 6) {
             $mapProjObj = ms_newprojectionobj($mapProjStr);
             $qLayerProjObj = ms_newprojectionobj($qLayerProjStr);
         } else {
             $mapProjObj = new projectionObj($mapProjStr);
             $qLayerProjObj = new projectionObj($qLayerProjStr);
         }
         //$qShpBounds->project($this->qLayerProjObj, $this->mapProjObj);
         $reprojectShape = 1;
     }
     // initial max/min values
     $mExtMinx = 999999999;
     $mExtMiny = 999999999;
     $mExtMaxx = -999999999;
     $mExtMaxy = -999999999;
     // ABP: Store all shape indexes
     $qShpIdxArray = array();
     // Return query results: shape index and feature extent
     for ($iRes = 0; $iRes < $numResults; $iRes++) {
         $qRes = $qLayer->getResult($iRes);
         $qShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $qLayer, $qRes);
         $qShpIdx = $qShape->index;
         $qShpIdxArray[] = $qShpIdx;
         $qShpBounds = $qShape->bounds;
         if ($reprojectShape) {
             $qShpBounds->project($qLayerProjObj, $mapProjObj);
         }
         $shpMinx = $qShpBounds->minx;
         $shpMiny = $qShpBounds->miny;
         $shpMaxx = $qShpBounds->maxx;
         $shpMaxy = $qShpBounds->maxy;
         // Get max/min values of ALL features
         $mExtMinx = min($mExtMinx, $shpMinx);
         $mExtMiny = min($mExtMiny, $shpMiny);
         $mExtMaxx = max($mExtMaxx, $shpMaxx);
         $mExtMaxy = max($mExtMaxy, $shpMaxy);
     }
     // Apply buffer (in units of features)
     if ($qLayer->type == 0) {
         $buffer = $_SESSION["pointBuffer"];
     } else {
         $buffer = $_SESSION["shapeQueryBuffer"] * (($mExtMaxx - $mExtMinx + ($mExtMaxy - $mExtMiny)) / 2);
     }
     $mExtMinx -= $buffer;
     $mExtMiny -= $buffer;
     $mExtMaxx += $buffer;
     $mExtMaxy += $buffer;
     $roundFact = $map->units != 5 ? 0 : 6;
     $shpMinx = round($mExtMinx, $roundFact);
     $shpMiny = round($mExtMiny, $roundFact);
     $shpMaxx = round($mExtMaxx, $roundFact);
     $shpMaxy = round($mExtMaxy, $roundFact);
     // no object found --> extent = mapExtent
     if (!$qShpIdxArray) {
         $mapExtent = $this->map->extent;
         $shpMinx = $mapExtent->minx;
         $shpMiny = $mapExtent->miny;
         $shpMaxx = $mapExtent->maxx;
         $shpMaxy = $mapExtent->maxy;
         $highlFeature = false;
         $setMaxExtent = false;
     }
     $ext = array($shpMinx, $shpMiny, $shpMaxx, $shpMaxy);
     $_SESSION['zoom_extparams'] = $ext;
     // Set Max Extent for map
     if ($setMaxExtent) {
         $mapMaxExt['minx'] = $shpMinx;
         $mapMaxExt['miny'] = $shpMiny;
         $mapMaxExt['maxx'] = $shpMaxx;
         $mapMaxExt['maxy'] = $shpMaxy;
         $_SESSION['mapMaxExt'] = $mapMaxExt;
     }
     // Add highlight feature if defined in URL parameters
     if ($highlFeature) {
         $resultlayers[$zoomLayer] = $qShpIdxArray;
         $_SESSION["resultlayers"] = $resultlayers;
     }
     // Return URL
     $searchString = "&mode=map&zoom_type=zoomextent&extent=" . $shpMinx . "+" . $shpMiny . "+" . $shpMaxx . "+" . $shpMaxy . ($highlFeature ? "&resultlayer={$zoomLayer}+{$qShpIdx}" : "");
     $mapInitURL = "map.phtml?{$searchString}";
     return $mapInitURL;
 }
示例#5
0
文件: map.php 项目: sukma279/GIS
 /**
  * FOR ZOOM TO SELECTED.
  * Adds a new layer to the map for highlighting feature
  */
 private function pmap_addResultLayer($reslayer, $shpindexes)
 {
     if (isset($_SESSION["resulttilelayers"])) {
         $resulttilelayers = $_SESSION["resulttilelayers"];
         $resulttilelayer = $resulttilelayers[$reslayer];
     } else {
         $resulttilelayers = null;
         $resulttilelayer = null;
     }
     $qLayer = $this->map->getLayerByName($reslayer);
     $qlayType = $qLayer->type;
     $layNum = count($this->map->getAllLayerNames());
     // Test if layer has the same projection as map
     $mapProjStr = $this->map->getProjection();
     $qLayerProjStr = $qLayer->getProjection();
     $changeLayProj = false;
     if ($mapProjStr && $qLayerProjStr && $mapProjStr != $qLayerProjStr) {
         $changeLayProj = true;
         if ($_SESSION['MS_VERSION'] < 6) {
             $mapProjObj = ms_newprojectionobj($mapProjStr);
             $qLayerProjObj = ms_newprojectionobj($qLayerProjStr);
         } else {
             $mapProjObj = new projectionObj($mapProjStr);
             $qLayerProjObj = new projectionObj($qLayerProjStr);
         }
     }
     // New result layer
     if ($_SESSION['PM_TPL_MAP_FILE']) {
         // load from template map file
         $hlDynLayer = 0;
         $hlMap = ms_newMapObj($_SESSION['PM_TPL_MAP_FILE']);
         $hlMapLayer = $hlMap->getLayerByName("highlight_{$qlayType}");
         $hlMapLayer->set("name", "pmapper_reslayer");
         $newResLayer = ms_newLayerObj($this->map, $hlMapLayer);
     } else {
         // create dynamically
         $hlDynLayer = 1;
         $newResLayer = ms_newLayerObj($this->map);
         $newResLayer->set("name", "pmapper_reslayer");
         if ($qlayType == 0) {
             $newResLayer->set("type", 0);
             // Point for point layer
         } elseif ($qlayType == 1 || $qlayType == 2) {
             $newResLayer->set("type", 1);
             // Line for line && polygon layers
         }
         //##$newResLayer->set("type", $qlayType);  // Take always same layer type as layer itself
     }
     // Add selected shape to new layer
     //# when layer is an event theme
     if ($qLayer->getMetaData("XYLAYER_PROPERTIES") != "") {
         foreach ($shpindexes as $cStr) {
             $cList = preg_split('/@/', $cStr);
             $xcoord = $cList[0];
             $ycoord = $cList[1];
             $resLine = ms_newLineObj();
             // needed to use a line because only a line can be added to a shapeObj
             $resLine->addXY($xcoord, $ycoord);
             $resShape = ms_newShapeObj(1);
             $resShape->add($resLine);
             $newResLayer->addFeature($resShape);
         }
         //# specific for PG layers  <==== required for MS >= 5.6 !!!
     } elseif ($qLayer->connectiontype == 6) {
         $newResLayer->set("connection", $qLayer->connection);
         if (method_exists($newResLayer, "setConnectionType")) {
             $newResLayer->setConnectionType($qLayer->connectiontype);
         } else {
             $newResLayer->set("connectiontype", $qLayer->connectiontype);
         }
         $data = $qLayer->data;
         // use layers with complex queries that are too long to select results
         // cause maxscaledenom is not used...
         if ($qLayer->getMetaData("PM_RESULT_DATASUBSTITION") != "") {
             $data = $qLayer->getMetaData("PM_RESULT_DATASUBSTITION");
         }
         $newResLayer->set("data", $data);
         if ($qLayerProjStr) {
             $newResLayer->setProjection($qLayerProjStr);
         }
         $glList = PMCommon::returnGroupGlayer($reslayer);
         $glayer = $glList[1];
         $layerDbProperties = $glayer->getLayerDbProperties();
         $uniqueField = $layerDbProperties['unique_field'];
         $indexesStr = implode(",", $shpindexes);
         $idFilter = "({$uniqueField} IN ({$indexesStr}))";
         $newResLayer->setFilter($idFilter);
         //# 'normal' layers
     } else {
         // Add selected shape to new layer
         // Modified by Thomas RAFFIN (SIRAP)
         // use layers with complex queries that are too long to select results
         // cause maxscaledenom is not used...
         $olddata = false;
         if ($qLayer->getMetaData("PM_RESULT_DATASUBSTITION") != "") {
             $olddata = $qLayer->data;
             $qLayer->set("data", $qLayer->getMetaData("PM_RESULT_DATASUBSTITION"));
         }
         $qLayer->open();
         foreach ($shpindexes as $resShpIdx) {
             if (preg_match("/@/", $resShpIdx)) {
                 $idxList = explode("@", $resShpIdx);
                 $resTileShpIdx = $idxList[0];
                 $resShpIdx = $idxList[1];
             } else {
                 $resTileShpIdx = $resulttilelayer[$resShpIdx];
             }
             $resShape = PMCommon::resultGetShape($this->msVersion, $qLayer, null, $resShpIdx, $resTileShpIdx);
             // changed for compatibility with PG layers and MS >= 5.6
             // Change projection to map projection if necessary
             if ($changeLayProj) {
                 // If error appears here for Postgis layers, then DATA is not defined properly as:
                 // "the_geom from (select the_geom, oid, xyz from layer) AS new USING UNIQUE oid USING SRID=4258"
                 if ($resShape) {
                     $resShape->project($qLayerProjObj, $mapProjObj);
                 }
             }
             if ($resShape) {
                 $newResLayer->addFeature($resShape);
             }
         }
         $qLayer->close();
         // Modified by Thomas RAFFIN (SIRAP)
         // use layers with complex queries that are too long to select results
         // cause maxscaledenom is not used...
         // reset data tag
         if ($olddata) {
             $qLayer->set("data", $olddata);
         }
     }
     $newResLayer->set("status", MS_ON);
     $newResLayerIdx = $newResLayer->index;
     if ($hlDynLayer) {
         // SELECTION COLOR
         $iniClrStr = trim($_SESSION["highlightColor"]);
         $iniClrList = preg_split('/[\\s,]+/', $iniClrStr);
         $iniClr0 = $iniClrList[0];
         $iniClr1 = $iniClrList[1];
         $iniClr2 = $iniClrList[2];
         // CREATE NEW CLASS
         $resClass = ms_newClassObj($newResLayer);
         $clStyle = ms_newStyleObj($resClass);
         $clStyle->color->setRGB($iniClr0, $iniClr1, $iniClr2);
         $clStyle->set("symbolname", "circle");
         $symSize = $qlayType < 1 ? 10 : 5;
         $clStyle->set("size", $symSize);
     }
     // Move layer to top (is it working???)
     while ($newResLayerIdx < $layNum - 1) {
         $this->map->moveLayerUp($newResLayerIdx);
     }
 }
示例#6
0
文件: search.php 项目: sukma279/GIS
 /**
  * Get the option values from a MapServer layer
  */
 protected function getOptionsFromMS($mslayer, $encoding, $keyfield, $showfield, $sort)
 {
     $qLayer = $this->map->getLayerByName($mslayer);
     $query = $qLayer->queryByAttributes($keyfield, "/()/", MS_MULTIPLE);
     if ($query == MS_SUCCESS) {
         $qLayer->open();
         $numResults = $qLayer->getNumResults();
         //error_log($numResults);
         for ($iRes = 0; $iRes < $numResults; $iRes++) {
             $qRes = $qLayer->getResult($iRes);
             $qShape = PMCommon::resultGetShape($this->msVersion, $qLayer, $qRes);
             // changed for compatibility with PG layers and MS >= 5.6
             $k = $encoding != "UTF-8" ? iconv($encoding, "UTF-8", $qShape->values[$keyfield]) : $qShape->values[$keyfield];
             $v = $encoding != "UTF-8" ? iconv($encoding, "UTF-8", $qShape->values[$showfield]) : $qShape->values[$showfield];
             $ol[$k] = trim($v);
             // avoid <, >, ...
             $ol[$k] = htmlentities($ol[$k], ENT_COMPAT, 'UTF-8');
             PMCommon::freeMsObj($qShape);
         }
         $json = $this->options_array2json($ol, $sort);
         return $json;
     }
 }
示例#7
0
文件: squery.php 项目: sukma279/GIS
 /**
  * DUMP QUERY RESULTS INTO QUERY STRING $qStr
  *******************************************************/
 function dumpQueryResults()
 {
     if ($this->zoomFull) {
         // Maximum extents
         $this->mExtMinx = 999999999;
         $this->mExtMiny = 999999999;
         $this->mExtMaxx = -999999999;
         $this->mExtMaxy = -999999999;
     }
     $this->returnTableJoinProperties();
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     $oldData = false;
     // only for MS >= 6, else bad Data is used in shapeObj (in MS 6 man use resultObj instead of shapeObj)
     $layerCloned = false;
     if ($this->msVersion >= 6) {
         if ($this->qLayer->getMetaData('PM_RESULT_DATASUBSTITION') != '') {
             $oldData = $this->qLayer->data;
             $layerCloned = ms_newLayerObj($this->map, $this->qLayer);
             $this->qLayer->set('data', $this->qLayer->getMetaData('PM_RESULT_DATASUBSTITION'));
         }
     }
     $this->qLayer->open();
     if ($layerCloned) {
         $layerCloned->open();
     }
     // Set numresults; Apply limit for query results if numresult > limit
     $this->numResults = $this->qLayer->getNumResults();
     if ($this->numResults > $this->limitResult) {
         $this->numResults = $this->limitResult;
     }
     //error_log("numresults: " .$this->numResults);
     for ($iRes = 0; $iRes < $this->numResults; $iRes++) {
         $qRes = $this->qLayer->getResult($iRes);
         $qShape = PMCommon::resultGetShape($this->msVersion, $this->qLayer, $qRes);
         // required for MS >= 5.6 !!!
         if ($this->qLayer->connectiontype == 6 || $this->qLayer->connectiontype == 8) {
             $layerDbProperties = $this->glayer->getLayerDbProperties();
             $uniqueField = $layerDbProperties['unique_field'];
             $shapeIndex = $qShape->values[$uniqueField];
             if ($layerCloned) {
                 //					$qShape = $layerCloned->getShape(new resultObj($shapeIndex));
                 $qShape = PMCommon::resultGetShape($this->msVersion, $layerCloned, null, $qShape->index);
             }
         } else {
             $shapeIndex = $qRes->shapeindex;
         }
         $this->qStr .= $this->printResultRow($qShape);
         $this->qStr .= $iRes < $this->numResults - 1 ? ", " : "";
         $this->resultindexes[] = $shapeIndex;
         $this->resulttileindexes[$shapeIndex] = $qRes->tileindex;
     }
     //error_log($this->qStr);
     $this->qLayer->close();
     if ($layerCloned) {
         $layerCloned->close();
     }
     // Modified by Thomas RAFFIN (SIRAP)
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     // reset data tag
     if ($oldData) {
         $this->qLayer->set('data', $oldData);
     }
 }
示例#8
0
文件: suggest.php 项目: sukma279/GIS
 /**
  * Get Suggest records from a MS layer using generic MapScript attribute query 
  *
  * @return string
  */
 private function msSuggestMatch($searchParams)
 {
     $msVersion = $_SESSION['msVersion'];
     if (!extension_loaded('MapScript')) {
         dl("php_mapscript{$msVersion}." . PHP_SHLIB_SUFFIX);
     }
     $map = $this->map;
     pm_logDebug(3, $searchParams, "suggest.php->msSuggestMatch()");
     $mslayer = $searchParams['mslayer'];
     $searchfield = $searchParams['searchfield'];
     $sort = $searchParams['sort'];
     $encoding = $searchParams['encoding'];
     $regexleft = $searchParams['regexleft'];
     $startleft = $searchParams['startleft'];
     // many dependfields
     $dependFields = isset($searchParams['dependFields']) && $searchParams['dependFields'] ? $searchParams['dependFields'] : array();
     $left = $startleft ? "^" : "";
     $qLayer = $map->getLayerByName($mslayer);
     $qs = "";
     // Create search string
     // many dependfields
     $qsDependFieldsParts = array();
     if ($dependFields) {
         foreach ($dependFields as $fieldName => $fieldValue) {
             $depFldName = "dependfldval_{$fieldName}";
             $depFldValue = $searchParams[$depFldName];
             $depFldValue = trim($depFldValue);
             if ($depFldValue != '') {
                 $qsDependFieldsParts[] = "( \"[{$fieldName}]\" =~ /{$depFldValue}/ )";
             }
         }
     }
     if ($qsDependFieldsParts) {
         $qs .= ' (' . implode(' AND ', $qsDependFieldsParts) . ') AND ';
     }
     if (trim($searchParams['fieldtype']) == "s") {
         if ($encoding != $this->defCharset) {
             $this->search = iconv($this->defCharset, $encoding, $this->search);
         }
         $searchVal = get_magic_quotes_gpc() ? stripslashes($this->search) : $this->search;
         if ($this->msVersion >= 6) {
             $qs .= "( \"[{$searchfield}]\" ~* \"{$regexleft}{$left}{$searchVal}\" )";
         } else {
             $val = preg_replace("/\\w/ie", "'('. strtoupper('\$0') . '|' . strtolower('\$0') .')'", $searchVal);
             $qs .= "( \"[{$searchfield}]\" =~ /{$regexleft}{$left}{$val}/ )";
         }
     } else {
         $qs .= "([{$searchfield}] = {$this->search})";
     }
     if ($layFilter = $qLayer->getFilterString()) {
         $querystring = "( ({$layFilter}) AND ({$qs}) )";
     } else {
         $querystring = "( {$qs} )";
     }
     pm_logDebug(3, $querystring, "MS suggest query string, suggest.php/msSuggestMatch()");
     // Query layer
     $query = @$qLayer->queryByAttributes($searchfield, $querystring, MS_MULTIPLE);
     if ($query == MS_SUCCESS) {
         $qLayer->open();
         $numResults = $qLayer->getNumResults();
         // Return query results
         for ($iRes = 0; $iRes < $numResults; $iRes++) {
             $qRes = $qLayer->getResult($iRes);
             $qShape = PMCommon::resultGetShape($this->msVersion, $qLayer, $qRes);
             // changed for compatibility with PG layers and MS >= 5.6
             $fldValue = $qShape->values[$searchfield];
             if ($encoding != $this->defCharset) {
                 $fldValue = iconv($encoding, $this->defCharset, $fldValue);
             }
             $resArray[] = trim($fldValue);
             PMCommon::freeMsObj($qShape);
         }
         $ret = $this->suggest_array2json($resArray, $sort);
         return $ret;
     } else {
         return 0;
     }
 }