I'm using this PHP PostGIS to geoJSON script: https://gist.github.com/bmcbride/1913855
But I keep getting this error: 'missing required parameter: geotable'
This is my code:
# Retrive URL variables if (empty($_GET['WTGs_All'])) { echo "missing required parameter: geotable"; exit; } else $geotable = $_GET['WTGs_All']; if (empty($_GET['the_geom'])) { echo "missing required parameter: geomfield"; exit; } else $geomfield = $_GET['the_geom']; if (empty($_GET['srid'])) { $srid = '4326'; } else $srid = $_GET['srid']; if (empty($_GET['fields'])) { $fields = '*'; } else $fields = $_GET['fields']; $parameters = $_GET['parameters']; $orderby = $_GET['orderby']; if (empty($_GET['sort'])) { $sort = 'ASC'; } else $sort = $_GET['sort']; $limit = $_GET['limit']; $offset = $_GET['offset']; # Connect to PostgreSQL database $conn = pg_connect("dbname='postgres' user='postgres' password='****' port='5432' host='localhost'"); if (!$conn) { echo "Not connected : " . pg_error(); exit; } # Build SQL SELECT statement and return the geometry as a GeoJSON element in EPSG: 4326 $sql = "SELECT " . pg_escape_string($fields) . ", st_asgeojson(transform(" . pg_escape_string($geomfield) . ",$srid)) AS geojson FROM " . pg_escape_string($geotable); if (strlen(trim($parameters)) > 0) { $sql .= " WHERE " . pg_escape_string($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); } //echo $sql; # Try query or error $rs = pg_query($conn, $sql); if (!$rs) { echo "An SQL error occured.\n"; exit; } # Build GeoJSON $output = ''; $rowOutput = ''; while ($row = pg_fetch_assoc($rs)) { $rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "geometry": ' . $row['geojson'] . ', "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 . ' ]}'; echo $output; ?> My table is called WTGs_All, I don't know what am I doing wrong. Thanks.
أكثر...
But I keep getting this error: 'missing required parameter: geotable'
This is my code:
# Retrive URL variables if (empty($_GET['WTGs_All'])) { echo "missing required parameter: geotable"; exit; } else $geotable = $_GET['WTGs_All']; if (empty($_GET['the_geom'])) { echo "missing required parameter: geomfield"; exit; } else $geomfield = $_GET['the_geom']; if (empty($_GET['srid'])) { $srid = '4326'; } else $srid = $_GET['srid']; if (empty($_GET['fields'])) { $fields = '*'; } else $fields = $_GET['fields']; $parameters = $_GET['parameters']; $orderby = $_GET['orderby']; if (empty($_GET['sort'])) { $sort = 'ASC'; } else $sort = $_GET['sort']; $limit = $_GET['limit']; $offset = $_GET['offset']; # Connect to PostgreSQL database $conn = pg_connect("dbname='postgres' user='postgres' password='****' port='5432' host='localhost'"); if (!$conn) { echo "Not connected : " . pg_error(); exit; } # Build SQL SELECT statement and return the geometry as a GeoJSON element in EPSG: 4326 $sql = "SELECT " . pg_escape_string($fields) . ", st_asgeojson(transform(" . pg_escape_string($geomfield) . ",$srid)) AS geojson FROM " . pg_escape_string($geotable); if (strlen(trim($parameters)) > 0) { $sql .= " WHERE " . pg_escape_string($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); } //echo $sql; # Try query or error $rs = pg_query($conn, $sql); if (!$rs) { echo "An SQL error occured.\n"; exit; } # Build GeoJSON $output = ''; $rowOutput = ''; while ($row = pg_fetch_assoc($rs)) { $rowOutput = (strlen($rowOutput) > 0 ? ',' : '') . '{"type": "Feature", "geometry": ' . $row['geojson'] . ', "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 . ' ]}'; echo $output; ?> My table is called WTGs_All, I don't know what am I doing wrong. Thanks.
أكثر...