/** * * * @param unknown $table * @param unknown $sql * @param unknown $sql2 * @param unknown $from */ function doSelect($table, $sql, $sql2, $from) { global $db; global $depth; global $postgisObject; global $srs; global $gmlNameSpaceUri; global $lf; global $gmlNameSpace; global $gmlNameSpaceGeom; global $gmlFeature; global $gmlGeomFieldName; global $gmlUseAltFunctions; global $defaultBoundedBox; global $cacheDir; global $startTime; global $useWktToGmlInPHP; global $thePath; global $HTTP_FORM_VARS; global $tableObj; global $postgisschema; global $fieldConfArr; if (!$gmlFeature[$table]) { $gmlFeature[$table] = $table; } if ($sql2) { $postgisObject->execQuery("BEGIN"); $result = $postgisObject->execQuery($sql2 . $from); //logfile::write($sql2.$from."\n"); if ($postgisObject->numRows($result) == 1) { while ($myrow = $postgisObject->fetchRow($result)) { if (!empty($myrow["txmin"])) { //added NR genBBox($myrow["txmin"], $myrow["tymin"], $myrow["txmax"], $myrow["tymax"]); } else { //return; } } } else { print $defaultBoundedBox; } } else { print $defaultBoundedBox; } $result = $postgisObject->execQuery($sql . $from . " LIMIT 1000000"); if ($postgisObject->numRows($result) < 1) { $sql = str_replace(",public.ST_AsText(public.ST_Transform(the_geom,25832)) as the_geom", "", $sql); $from = str_replace("view", "join", $from); $result = $postgisObject->execQuery($sql . $from); } logfile::write("SQL fired\n\n"); logfile::write($sql . $from . "\n"); $totalTime = microtime_float() - $startTime; logfile::write("\nQuery time {$totalTime}\n"); //foreach($postgisObject -> execQuery($sql.$from." LIMIT 10000") as $myrow) { //Iteration directly over result. Only PDO if ($postgisObject->PDOerror) { makeExceptionReport($postgisObject->PDOerror); } while ($myrow = $postgisObject->fetchRow($result)) { writeTag("open", "gml", "featureMember", null, True, True); $depth++; writeTag("open", $gmlNameSpace, $gmlFeature[$table], array("fid" => "{$table}.{$myrow["fid"]}"), True, True); $depth++; $checkIfGeomHasPassed = false; // Check that geom field is written out only once. $numFields = sizeof($myrow); $keys = array_keys($myrow); for ($i = 0; $i < $numFields; $i++) { $FieldName = $keys[$i]; $FieldValue = $myrow[$FieldName]; if ($tableObj->metaData[$FieldName]['type'] != "geometry" && $FieldName != "txmin" && $FieldName != "tymin" && $FieldName != "txmax" && $FieldName != "tymax" && $FieldName != "tymax" && $FieldName != "oid") { if ($gmlUseAltFunctions['altFieldValue']) { $FieldValue = altFieldValue($FieldName, $FieldValue); } if ($gmlUseAltFunctions['altFieldNameToUpper']) { $FieldName = altFieldNameToUpper($FieldName); } if ($gmlUseAltFunctions['changeFieldName']) { $FieldName = changeFieldName($FieldName); } $fieldProperties = (array) json_decode($fieldConfArr[$FieldName]->properties); if ($fieldProperties['cartomobilePictureUrl']) { //if ($myrow[$fieldProperties['cartomobilePictureUrl']]) { $FieldValue = getCartoMobilePictureUrl($table, $FieldName, $fieldProperties['cartomobilePictureUrl'], $myrow["fid"]); //} } //$FieldValue = htmlentities($FieldValue); $FieldValue = altUseCdataOnStrings($FieldValue); if ($FieldValue && ($FieldName != "fid" && $FieldName != "FID")) { writeTag("open", $gmlNameSpace, $FieldName, null, True, False); //$FieldType = pg_field_type($result, $i); echo $FieldValue; writeTag("close", $gmlNameSpace, $FieldName, null, False, True); } } elseif ($tableObj->metaData[$FieldName]['type'] == "geometry") { // Check if the geometry field use another name space and element name if (!$gmlGeomFieldName[$table]) { $gmlGeomFieldName[$table] = $FieldName; } if ($gmlNameSpaceGeom) { $tmpNameSpace = $gmlNameSpaceGeom; } else { $tmpNameSpace = $gmlNameSpace; } writeTag("open", $tmpNameSpace, $gmlGeomFieldName[$table], null, True, True); $depth++; if ($useWktToGmlInPHP) { $__geoObj = geometryfactory::createGeometry($myrow[$FieldName], "EPSG:" . $srs); echo $__geoObj->getGML(); unset($__geoObj); } else { echo $myrow[$FieldName]; } $depth--; writeTag("close", $tmpNameSpace, $gmlGeomFieldName[$table], null, True, True); } } $depth--; writeTag("close", $gmlNameSpace, $gmlFeature[$table], null, True, True); $depth--; writeTag("close", "gml", "featureMember", null, True, True); } $totalTime = microtime_float() - $startTime; print "\n<!-- {$totalTime} -->"; $postgisObject->execQuery("ROLLBACK"); }
function geometryCollection($wktArray) { foreach ($wktArray as $__key => $__value) { $this->geometryArray[$__key] = parent::createGeometry($__value); } }
function loadInDB(&$postgisObject, $tableName) { if ($this->arr) { //First we try to drop table $dropSql = "DROP TABLE " . $tableName . " CASCADE"; //When we try to delete row from geometry_columns $deleteFromGeometryColumns = "DELETE FROM geometry_columns WHERE f_table_name='" . $tableName . "'"; //When we insert new row in geometry_columns $sqlInsert = "INSERT INTO geometry_columns VALUES ('', '" . $postgisObject->postgisdb . "', '" . $tableName . "', 'the_geom', 2, 25832, '" . $this->geomType . "', NULL, NULL, NULL)"; //Last we create the new table $createSql = "\n\t\t\tCREATE TABLE " . $tableName . " (\n\t\t\tgid serial NOT NULL,\n\t\t\t" . $this->strForSql . " character varying,\n\t\t\tthe_geom geometry,\n\t\t\tCONSTRAINT \"\$1\" CHECK ((srid(the_geom) = 25832)),\n\t\t\tCONSTRAINT \"\$2\" CHECK (((geometrytype(the_geom) = '" . $this->geomType . "'::text) OR (the_geom IS NULL)))\n\t\t\t);"; // Check if table is already created $checkSql = "select * FROM " . $tableName; $check = $postgisObject->execQuery($checkSql); // Start of transactions block $postgisObject->execQuery(BEGIN); if ($check) { $result = $postgisObject->execQuery($dropSql); $postgisObject->free($result); //echo $tableName." dropped\n"; } $result = $postgisObject->execQuery($deleteFromGeometryColumns); $postgisObject->free($result); $result = $postgisObject->execQuery($sqlInsert); $postgisObject->free($result); $result = $postgisObject->execQuery($createSql); $postgisObject->free($result); //echo "\n"; $countRows = 0; for ($i = 0; $i < sizeof($this->arr['fields']); $i++) { $geoObj = geometryfactory::createGeometry($this->arr['geom'][$i], "25832"); if ($geoObj) { if ($geoObj->getGeomType() == "POLYGON" || $geoObj->getGeomType() == "LINESTRING" || $geoObj->getGeomType() == "POINT") { $this->arr['geom'][$i] = $geoObj->getAsMulti(); } } $sqlInsert = "insert into " . $tableName . " (" . $this->arr['fields'][$i] . ",the_geom) values(" . $this->arr['values'][$i] . ",'SRID=25832;" . $this->arr['geom'][$i] . "')"; // Check if feature has geometry if ($this->arr['geom'][$i] != "()") { $result = $postgisObject->execQuery($sqlInsert); if ($result and pg_affected_rows($result) == 1) { $countRows++; $postgisObject->free($result); } else { logfile::write("Error in #" . $i . "\n"); logfile::write("ROLLBACK\n"); logfile::write($sqlInsert . "\n"); $postgisObject->execQuery(ROLLBACK); logfile::write("Script terminated\n"); die; } } else { logfile::write("#. " . $i . " missing geometry.\n"); logfile::write("ROLLBACK\n"); $postgisObject->execQuery(ROLLBACK); logfile::write("Script terminated\n"); die; } //echo "."; } $postgisObject->execQuery(COMMIT); // End of transactions block } else { $sql = "DELETE FROM " . $tableName; $result = $postgisObject->execQuery($sql); $postgisObject->free($result); $countRows = "0"; } logfile::write(date('l jS \\of F Y h:i:s A') . " " . $countRows . " features loaded in table '" . $tableName . "'\n"); }
function loadInDB($tableName) { $st = $this->explodeTableName($tableName); //print_r($this -> arr); if ($this->arr) { //print_r($this->arr); //First we try to drop table $dropSql = "DROP TABLE " . $tableName . " CASCADE"; //When we try to delete row from geometry_columns $deleteFromGeometryColumns = "DELETE FROM geometry_columns WHERE f_table_schema='" . $st['schema'] . "' AND f_table_name='" . $st['table'] . "'"; //When we insert new row in geometry_columns $sqlInsert = "INSERT INTO geometry_columns VALUES ('', '" . $st['schema'] . "', '" . $st['table'] . "', 'the_geom', 2, {$this->arr['srid'][0]}, '" . $this->geomType . "')"; //Last we create the new table.Must use schema prefix cos search path include public $createSql = "\n\t\t\tCREATE TABLE " . $tableName . " (\n\t\t\tgid serial NOT NULL PRIMARY KEY,\n\t\t\t" . $this->strForSql . " character varying,\n\t\t\tthe_geom geometry,\n\t\t\tCONSTRAINT \"\$1\" CHECK ((srid(the_geom) = {$this->arr['srid'][0]})),\n\t\t\tCONSTRAINT \"\$2\" CHECK (((geometrytype(the_geom) = '" . $this->geomType . "'::text) OR (the_geom IS NULL)))\n\t\t\t);\n\t\t\t"; //echo $createSql."\n"; // Check if table is already created $checkSql = "select * FROM " . $tableName; $check = $this->execQuery($checkSql); $this->PDOerror = NULL; // Start of transactions block $this->execQuery(BEGIN); if ($check) { $result = $this->execQuery($dropSql); $this->free($result); //echo $tableName." dropped\n"; } $result = $this->execQuery($deleteFromGeometryColumns); $this->free($result); $result = $this->execQuery($sqlInsert); $this->free($result); $result = $this->execQuery($createSql); $this->free($result); //echo "\n"; $countRows = 0; for ($i = 0; $i < sizeof($this->arr['fields']); $i++) { $geoObj = geometryfactory::createGeometry($this->arr['geom'][$i], $this->arr['srid'][$i]); if ($geoObj) { if ($geoObj->getGeomType() == "POLYGON" || $geoObj->getGeomType() == "LINESTRING" || $geoObj->getGeomType() == "POINT") { $this->arr['geom'][$i] = $geoObj->getAsMulti(); } } $sqlInsert = "insert into " . $tableName . " (" . $this->arr['fields'][$i] . ",the_geom) values(" . $this->arr['values'][$i] . ",geomFromText('" . $this->arr['geom'][$i] . "'," . $this->arr['srid'][$i] . "))"; //echo $sqlInsert; // Check if feature has geometry if ($this->arr['geom'][$i] != "()") { $result = $this->execQuery($sqlInsert); if (!$this->PDOerror) { $countRows++; $this->free($result); } else { print_r($this->PDOerror); print "Error in #" . $i . "\n"; print "ROLLBACK\n"; print $sqlInsert . "\n"; $this->execQuery(ROLLBACK); print "Script terminated\n"; die; } } else { print "#. " . $i . " missing geometry.\n"; print "ROLLBACK\n"; $this->execQuery(ROLLBACK); print "Script terminated\n"; die; } //echo "."; } $this->execQuery(COMMIT); // End of transactions block } else { $sql = "DELETE FROM " . $tableName; $result = $this->execQuery($sql); $this->free($result); $countRows = "0"; } print date('l jS \\of F Y h:i:s A') . " " . $countRows . " features loaded in table '" . $tableName . "'\n"; }