function makeTileCacheFile($user, $extentLayer = NULL) { //return; global $basePath; global $postgisdb; global $postgishost; global $postgispw; global $hostName; global $postgisschema; $postgisdb = $user; $table = $extentLayer; $postgisObject = new postgis(); $srs = "900913"; $geomField = $postgisObject->getGeometryColumns($table, "f_geometry_column"); if ($extentLayer) { $sql = "SELECT xmin(EXTENT(transform(" . $geomField . ",{$srs}))) AS TXMin,xmax(EXTENT(transform(" . $geomField . ",{$srs}))) AS TXMax, ymin(EXTENT(transform(" . $geomField . ",{$srs}))) AS TYMin,ymax(EXTENT(transform(" . $geomField . ",{$srs}))) AS TYMax FROM " . $table; $result = $postgisObject->execQuery($sql); //print_r($postgisObject->PDOerror); $row = $postgisObject->fetchRow($result); } ob_start(); echo "[cache]\n"; echo "type=Disk\n"; echo "base={$basePath}/tmp/{$user}\n\n"; //echo "type=AWSS3\n"; //echo "access_key=AKIAIZUYE3I462NPVANQ\n"; //echo "secret_access_key=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\n"; $sql = "SELECT * FROM settings.geometry_columns_view"; //echo $sql; $result = $postgisObject->execQuery($sql); if ($postgisObject->PDOerror) { makeExceptionReport($postgisObject->PDOerror); } while ($row = $postgisObject->fetchRow($result)) { echo "[{$row['f_table_schema']}.{$row['f_table_name']}]\n"; echo "type=WMS\n"; echo "url=http://127.0.0.1/cgi-bin/mapserv?map={$basePath}/wms/mapfiles/{$user}_{$row['f_table_schema']}.map\n"; echo "extension=png\n"; echo "bbox=-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892\n"; echo "maxResolution=156543.0339\n"; echo "metaTile=yes\n"; echo "metaSize=5,5\n"; echo "srs=EPSG:900913\n\n"; } $data = ob_get_clean(); @unlink("{$basePath}wms/cfgfiles/{$user}.tilecache.cfg"); $newFile = "{$basePath}wms/cfgfiles/{$user}.tilecache.cfg"; $fh = fopen($newFile, 'w'); fwrite($fh, $data); fclose($fh); }
} } else { $HTTP_FORM_VARS = array(""); } } //HTTP_FORM_VARS is set in script if POST is used $HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER); // Make keys case $HTTP_FORM_VARS["TYPENAME"] = dropNameSpace($HTTP_FORM_VARS["TYPENAME"]); $tables = explode(",", $HTTP_FORM_VARS["TYPENAME"]); $properties = explode(",", dropNameSpace($HTTP_FORM_VARS["PROPERTYNAME"])); $featureids = explode(",", $HTTP_FORM_VARS["FEATUREID"]); $bbox = explode(",", $HTTP_FORM_VARS["BBOX"]); // Start HTTP basic authentication //if(!$_SESSION["oauth_token"]) { $auth = $postgisObject->getGeometryColumns($postgisschema . "." . $HTTP_FORM_VARS["TYPENAME"], "authentication"); if ($auth == "Read/write") { include '../inc/http_basic_authen.php'; } //} // End HTTP basic authentication print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; ob_start(); if (!empty($properties[0])) { foreach ($properties as $property) { $__u = explode(".", $property); // Is it "/" for get method? // We first check if typeName is namespace if ($__u[1]) { foreach ($tables as $table) { if ($table == $__u[0]) {
function wfs_server() { // Manually tested this piece of code in order to check the requests. // Code based on a similar idea but build in Java header('Content-Type:text/xml; charset=UTF-8', TRUE); header('Connection:close', TRUE); //$userFromUri = "mhoegh"; // for testing logfile::write($userFromUri . "\n\n"); // We connect to the users db $postgisdb = $userFromUri; $srs = $srsFromUri; $postgisschema = $schemaFromUri; $postgisObject = new postgis(); //$user = new users($userFromUri); //$version = new version($user); $geometryColumnsObj = new GeometryColumns(); function microtime_float() { list($utime, $time) = explode(" ", microtime()); return (double) $utime + (double) $time; } $startTime = microtime_float(); //ini_set("display_errors", "On"); $thePath = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REDIRECT_URL']; //$thePath= "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; $server = "http://" . $_SERVER['SERVER_NAME']; $BBox = null; //end added $currentTable = null; $currentTag = null; $gen = array(); $gen[0] = ""; $level = 0; $depth = 0; $tables = array(); $fields = array(); $wheres = array(); $limits = array(); logfile::write("\nRequest\n\n"); logfile::write($HTTP_RAW_POST_DATA . "\n\n"); $unserializer_options = array('parseAttributes' => TRUE, 'typeHints' => FALSE); $unserializer = new XML_Unserializer($unserializer_options); /*$HTTP_RAW_POST_DATA = '<?xml version="1.0" encoding="utf-8"?><wfs:Transaction service="WFS" version="1.0.0" xmlns="http://www.opengis.net/wfs" xmlns:mrhg="http://twitter/mrhg" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wfs:Insert idgen="GenerateNew"><mrhg:hej><the_geom><gml:MultiPolygon srsName="urn:x-ogc:def:crs:EPSG:6.9:4326"><gml:polygonMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:coordinates>5.0657329559,-41.1107215881 8.4824724197,-39.3435783386 4.3241734505,-34.6001853943 5.0657329559,-41.1107215881 </gml:coordinates></gml:LinearRing></gml:exterior></gml:Polygon></gml:polygonMember></gml:MultiPolygon></the_geom></mrhg:hej></wfs:Insert></wfs:Transaction>';*/ /*$HTTP_RAW_POST_DATA = '<?xml version="1.0"?><DescribeFeatureType version="1.1.0" service="WFS" xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"> <TypeName>california_coastline</TypeName></DescribeFeatureType>'; */ // Post method is used if ($HTTP_RAW_POST_DATA) { //$forUseInSpatialFilter = $HTTP_RAW_POST_DATA; // We store a unaltered version of the raw request $HTTP_RAW_POST_DATA = dropNameSpace($HTTP_RAW_POST_DATA); logfile::write($HTTP_RAW_POST_DATA . "\n\n"); $status = $unserializer->unserialize($HTTP_RAW_POST_DATA); $arr = $unserializer->getUnserializedData(); $request = $unserializer->getRootName(); //print_r($arr); switch ($request) { case "GetFeature": if (!is_array($arr['Query'][0])) { $arr['Query'] = array(0 => $arr['Query']); } for ($i = 0; $i < sizeof($arr['Query']); $i++) { if (!is_array($arr['Query'][$i]['PropertyName'])) { $arr['Query'][$i]['PropertyName'] = array(0 => $arr['Query'][$i]['PropertyName']); } } $HTTP_FORM_VARS["REQUEST"] = "GetFeature"; foreach ($arr['Query'] as $queries) { $HTTP_FORM_VARS["TYPENAME"] .= $queries['typeName'] . ","; if ($queries['PropertyName'][0]) { foreach ($queries['PropertyName'] as $PropertyNames) { // We check if typeName is prefix and add it if its not if (strpos($PropertyNames, ".")) { $HTTP_FORM_VARS["PROPERTYNAME"] .= $PropertyNames . ","; } else { $HTTP_FORM_VARS["PROPERTYNAME"] .= $queries['typeName'] . "." . $PropertyNames . ","; } } } if (is_array($queries['Filter']) && $arr['version'] == "1.0.0") { @($checkXml = simplexml_load_string($queries['Filter'])); if ($checkXml === FALSE) { makeExceptionReport("Filter is not valid"); } $wheres[$queries['typeName']] = parseFilter($queries['Filter'], $queries['typeName']); } } $HTTP_FORM_VARS["TYPENAME"] = dropLastChrs($HTTP_FORM_VARS["TYPENAME"], 1); $HTTP_FORM_VARS["PROPERTYNAME"] = dropLastChrs($HTTP_FORM_VARS["PROPERTYNAME"], 1); break; case "DescribeFeatureType": $HTTP_FORM_VARS["REQUEST"] = "DescribeFeatureType"; $HTTP_FORM_VARS["TYPENAME"] = $arr['TypeName']; //if (!$HTTP_FORM_VARS["TYPENAME"]) $HTTP_FORM_VARS["TYPENAME"] = $arr['typeName']; break; case "GetCapabilities": $HTTP_FORM_VARS["REQUEST"] = "GetCapabilities"; break; case "Transaction": $HTTP_FORM_VARS["REQUEST"] = "Transaction"; if (isset($arr["Insert"])) { $transactionType = "Insert"; } if ($arr["Update"]) { $transactionType = "update"; } if ($arr["Delete"]) { $transactionType = "Delete"; } break; } } else { if (sizeof($_GET) > 0) { logfile::write($_SERVER['QUERY_STRING'] . "\n\n"); $HTTP_FORM_VARS = $_GET; $HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER); // Make keys case insensative $HTTP_FORM_VARS["TYPENAME"] = dropNameSpace($HTTP_FORM_VARS["TYPENAME"]); // We remove name space, so $where will get key without it. if ($HTTP_FORM_VARS['FILTER']) { @($checkXml = simplexml_load_string($HTTP_FORM_VARS['FILTER'])); if ($checkXml === FALSE) { makeExceptionReport("Filter is not valid"); } //$forUseInSpatialFilter = $HTTP_FORM_VARS['FILTER']; $status = $unserializer->unserialize(dropNameSpace($HTTP_FORM_VARS['FILTER'])); $arr = $unserializer->getUnserializedData(); $wheres[$HTTP_FORM_VARS['TYPENAME']] = parseFilter($arr, $HTTP_FORM_VARS['TYPENAME']); } } else { $HTTP_FORM_VARS = array(""); } } //HTTP_FORM_VARS is set in script if POST is used $HTTP_FORM_VARS = array_change_key_case($HTTP_FORM_VARS, CASE_UPPER); // Make keys case $HTTP_FORM_VARS["TYPENAME"] = dropNameSpace($HTTP_FORM_VARS["TYPENAME"]); $tables = explode(",", $HTTP_FORM_VARS["TYPENAME"]); $properties = explode(",", dropNameSpace($HTTP_FORM_VARS["PROPERTYNAME"])); $featureids = explode(",", $HTTP_FORM_VARS["FEATUREID"]); $bbox = explode(",", $HTTP_FORM_VARS["BBOX"]); // Start HTTP basic authentication //if(!$_SESSION["oauth_token"]) { $auth = $postgisObject->getGeometryColumns($postgisschema . "." . $HTTP_FORM_VARS["TYPENAME"], "authentication"); //} // End HTTP basic authentication print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; ob_start(); if (!empty($properties[0])) { foreach ($properties as $property) { $__u = explode(".", $property); // Is it "/" for get method? // We first check if typeName is namespace if ($__u[1]) { foreach ($tables as $table) { if ($table == $__u[0]) { $fields[$table] .= $__u[1] . ","; } } } else { foreach ($tables as $table) { $fields[$table] .= $property . ","; } } } } if (!empty($featureids[0])) { foreach ($featureids as $featureid) { $__u = explode(".", $featureid); foreach ($tables as $table) { $primeryKey = $postgisObject->getPrimeryKey($postgisschema . "." . $table); if ($table == $__u[0]) { $wheresArr[$table][] = "{$primeryKey['attname']}={$__u[1]}"; } $wheres[$table] = implode(" OR ", $wheresArr[$table]); } } } //get the request switch (strtoupper($HTTP_FORM_VARS["REQUEST"])) { case "GETCAPABILITIES": getCapabilities($postgisObject); break; case "GETFEATURE": if (!$gmlFeatureCollection) { $gmlFeatureCollection = "wfs:FeatureCollection"; } print "<" . $gmlFeatureCollection . "\n"; print "xmlns=\"http://www.opengis.net/wfs\"\n"; print "xmlns:wfs=\"http://www.opengis.net/wfs\"\n"; print "xmlns:gml=\"http://www.opengis.net/gml\"\n"; print "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"; print "xmlns:{$gmlNameSpace}=\"{$gmlNameSpaceUri}\"\n"; if ($gmlSchemaLocation) { print "xsi:schemaLocation=\"{$gmlSchemaLocation}\""; } else { //print "xsi:schemaLocation=\"{$gmlNameSpaceUri} {$thePath}?REQUEST=DescribeFeatureType&TYPENAME=".$HTTP_FORM_VARS["TYPENAME"]." http://www.opengis.net/wfs ".str_replace("server.php","",$thePath)."schemas/wfs/1.0.0/WFS-basic.xsd\""; print "xsi:schemaLocation=\"{$gmlNameSpaceUri} {$thePath}?REQUEST=DescribeFeatureType&TYPENAME=" . $HTTP_FORM_VARS["TYPENAME"] . " http://www.opengis.net/wfs http://wfs.plansystem.dk:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd\""; } print ">\n"; doQuery("Select"); print "</" . $gmlFeatureCollection . ">"; break; case "DESCRIBEFEATURETYPE": getXSD($postgisObject); break; case "TRANSACTION": doParse($arr); break; default: makeExceptionReport("Don't know that request"); break; } }
function makeTileCacheFile($user, $extentLayer = NULL) { //return; global $basePath; global $postgisdb; global $postgishost; global $postgispw; global $hostName; global $postgisschema; $postgisdb = $user; $table = $extentLayer; $postgisObject = new postgis(); $srs = "900913"; $geomField = $postgisObject->getGeometryColumns($table, "f_geometry_column"); if ($extentLayer) { $sql = "SELECT xmin(EXTENT(transform(" . $geomField . ",{$srs}))) AS TXMin,xmax(EXTENT(transform(" . $geomField . ",{$srs}))) AS TXMax, ymin(EXTENT(transform(" . $geomField . ",{$srs}))) AS TYMin,ymax(EXTENT(transform(" . $geomField . ",{$srs}))) AS TYMax FROM " . $table; $result = $postgisObject->execQuery($sql); //print_r($postgisObject->PDOerror); $row = $postgisObject->fetchRow($result); } ob_start(); echo "[cache]\n"; echo "type=Disk\n"; echo "base={$basePath}/tmp/{$user}\n\n"; //echo "type=AWSS3\n"; //echo "access_key=AKIAIZUYE3I462NPVANQ\n"; //echo "secret_access_key=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\n"; //echo "db={$user}\n"; $sql = "SELECT * FROM settings.geometry_columns_view"; $result = $postgisObject->execQuery($sql); if ($postgisObject->PDOerror) { makeExceptionReport($postgisObject->PDOerror); } while ($row = $postgisObject->fetchRow($result)) { $layerArr[] = $row['f_table_schema'] . "." . $row['f_table_name']; $def = json_decode($row['def']); $def->meta_tiles == true ? $meta_tiles = "yes" : ($meta_tiles = "no"); $def->ttl < 120 ? $expire = 120 : ($expire = $def->ttl); echo "[{$row['f_table_schema']}.{$row['f_table_name']}]\n"; echo "type=WMS\n"; echo "url={$hostName}/wms/{$user}/{$row['f_table_schema']}/?"; echo "extension=png\n"; echo "bbox=-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892\n"; echo "maxResolution=156543.0339\n"; echo "metaBuffer=20\n"; echo "metaTile={$meta_tiles}\n"; echo "metaSize=3,3\n"; echo "srs=EPSG:900913\n"; echo "expire={$expire}\n\n"; } echo "[{$postgisschema}]\n"; echo "layers=" . implode(",", $layerArr) . "\n"; echo "type=WMS\n"; echo "url={$hostName}/wms/{$user}/{$postgisschema}/?TRANSPARENT=FALSE&"; echo "extension=png\n"; echo "bbox=-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892\n"; echo "maxResolution=156543.0339\n"; echo "metaBuffer=20\n"; echo "metaTile={$meta_tiles}\n"; echo "metaSize=3,3\n"; echo "srs=EPSG:900913\n"; echo "expire={$expire}\n\n"; $data = ob_get_clean(); @unlink("{$basePath}wms/cfgfiles/{$user}.tilecache.cfg"); $newFile = "{$basePath}wms/cfgfiles/{$user}.tilecache.cfg"; $fh = fopen($newFile, 'w'); fwrite($fh, $data); fclose($fh); }