public function generateGeoJson($sql, $gp_name) { global $database; if (strlen(trim($parameters)) > 0) { if ($gp_name == "intersects" || $gp_name == "split" || $gp_name == "bbox") { $sql .= " AND " . $parameters; } else { $sql .= " WHERE " . $parameters; } } 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); } $rs = DBAccess::find_by_sql($sql); $output = ''; $rowOutput = ''; while ($row = $database->fetch_array($rs)) { $rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "geometry": ' . $row['gp_geom'] . ', "properties": {'; $props = ''; $id = ''; foreach ($row as $key => $val) { if ($key != "geojson") { $props .= (strlen($props) > 0 ? ',' : '') . '"' . $key . '":"' . escapeJsonString($val) . '"'; } if ($key == "id") { $id .= ',"id":"' . escapeJsonString($val) . '"'; } } $rowOutput .= $props . '}'; $rowOutput .= $id; $rowOutput .= '}'; $output .= $rowOutput; } $output = '{ "type": "FeatureCollection", "features": [ ' . $output . ' ]}'; return $output; }