Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Bugs & Fixes 2 years ago
Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I'm catching features from my PostGIS database with PHP, which generates dynamic sql requests. Since I can't manage to wrap my response into an ol.layer.Image I thought about using ST_UNIONor ST_COLLECT to improve map rendering performance. My current generated SQL is looking like this:
ol.layer.Image
ST_UNION
ST_COLLECT
SELECT krs,class, st_asgeojson(st_transform(ST_SimplifyPreserveTopology(the_geom,0),4326),6) AS geojson FROM tbl_detailansicht_f WHERE krs = 'Rotenburg (Wümme)' AND class = 5 AND the_geom && st_transform(st_makeenvelope(7.981262207031247,52.23004870271677,11.112365722656248,53.695628373000176,4326),4326)
I would like to get a sql statement like this:
SELECT krs,class, st_asgeojson(st_transform(ST_SimplifyPreserveTopology(st_collect(the_geom),0),4326),6) AS geojson FROM tbl_detailansicht_f WHERE krs = 'Rotenburg (Wümme)' AND class = 5 AND the_geom && st_transform(st_makeenvelope(7.981262207031247,52.23004870271677,11.112365722656248,53.695628373000176,4326),4326) GROUP BY krs, class
So my PHP (by https://github.com/bmcbride/PHP-Database-GeoJSON) needs to be adjusted in order to consider this change, which I fail at.
php /** * GET GeoJSON from PostGIS * Query a PostGIS table or view and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc. * Author: Bryan R. McBride, GISP, adapted by G.Moes * Contact: bryanmcbride.com * GitHub: https://github.com/bmcbride/PHP-Database-GeoJSON * * @param string $geotable The PostGIS layer name *REQUIRED* * @param string $geomfield The PostGIS geometry field *REQUIRED* * @param string $srid The SRID of the returned GeoJSON *OPTIONAL (If omitted, EPSG: 2169 will be used)* * @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)* * NOTE- Uppercase field names should be wrapped in double quotes * @param string $parameters SQL WHERE clause parameters *OPTIONAL* * @param string $orderby SQL ORDER BY constraint *OPTIONAL* * @param string $sort SQL ORDER BY sort order (ASC or DESC) *OPTIONAL* * @param string $limit Limit number of results returned *OPTIONAL* * @param integer $precision digits of returned geojson 6 = 0.111 m submeter as DEFAULT *OPTIONAL* * @param real $simplify simplify geometry to >5.0m as DEFAULT *OPTIONAL* * @param string $offset Offset used in conjunction with limit *OPTIONAL* * @return string resulting geojson string */ # Connect to PostgreSQL database You need to pass here the credentials to connect to Your database require("./connect.php"); function escapeJsonString($value) { # list from www.json.org: (\b backspace, \f formfeed) $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"); $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"); $result = str_replace($escapers, $replacements, $value); return $result; } # Retrive URL variables if (empty($_GET['geotable'])) { echo "missing required parameter: geotable"; exit; } else $geotable = $_GET['geotable']; if (empty($_GET['geomfield'])) { $geomfield='the_geom'; } else $geomfield = $_GET['geomfield']; if (empty($_GET
got it!
$sql = "SELECT " . pg_escape_string($fields) . ", st_asgeojson(st_transform(ST_SimplifyPreserveTopology(ST_Collect(" . pg_escape_string($geomfield) . "),".$simplify."),4326),".$precision.") AS geojson FROM " . pg_escape_string($geotable); if (strlen(trim($parameters)) > 0) { $sql .= " WHERE " . str_replace("''", "'", pg_escape_string($parameters)); } if (strlen(trim($parameters)) > 0 AND strlen(trim($bbox)) > 0){ $sql .= " AND the_geom && st_transform(st_makeenvelope(".pg_escape_string ($bbox).",4326),".$srid.")"; } if (strlen(trim($parameters)) <= 0 AND strlen(trim($bbox)) > 0) { $sql .= " WHERE the_geom && st_transform(st_makeenvelope(".pg_escape_string ($bbox).",4326),".$srid.")"; } if (strlen(trim($orderby)) > 0) { $sql .= " ORDER BY " . pg_escape_string($orderby) . " " . $sort; } if (strlen(trim($limit)) > 0) { $sql .= " LIMIT " . pg_escape_string($limit); } if (strlen(trim($offset)) > 0) { $sql .= " OFFSET " . pg_escape_string($offset); } $sql .= " GROUP BY " . pg_escape_string($fields);
sadly that doesn't improve map rendering performance at all.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.