[GIS] How to visuilze PostGIS data in GeoJSON format with PHP

geojsonPHPpostgis-2.0

I need to visualize PostGIS Geometry column as an overlay of a Leaflet tiled Map. I started a question here ,but didn't get any simple and satisfied answer. So I am starting this question. I got an option on Github to convert the PostGIS column to GeoJSON which can be visible through leaflet map.

I used the url as follows

http://localhost:8080/pgsql/PostGIS_GeoJSON.php?geotable=bgd_adm3&geomfield=geom

but it returns the following errors

Notice: Undefined index: parameters in C:\wamp\www\pgsql\PostGIS_GeoJSON.php on line 52

Notice: Undefined index: orderby in C:\wamp\www\pgsql\PostGIS_GeoJSON.php on line 54

Notice: Undefined index: limit in C:\wamp\www\pgsql\PostGIS_GeoJSON.php on line 61

Notice: Undefined index: offset in C:\wamp\www\pgsql\PostGIS_GeoJSON.php on line 63

Warning: pg_query() [function.pg-query]: Query failed: ERROR: function transform(geometry, integer) does not exist LINE 1: SELECT *, st_asgeojson(transform(geom,4326)) AS geojson FROM... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. in C:\wamp\www\pgsql\PostGIS_GeoJSON.php on line 89
An SQL error occured.

What I have to do?

Best Answer

The code you are using uses the older function naming style without the "ST_" prefix, used many many years ago. So transform(geometry, integer) is now ST_Transform(geometry, integer).

There are a few things you can do to fix this. Do one of these:

  • Fix the PHP code, by changing transform to ST_Transform
  • Apply the legacy.sql enabler script from the PostGIS contrib directory (documented here)