2

I used FeatureServer before and I liked it. The only thing I didn't like, though, is that it needs some other dependencies to work. That's why I want to try PHP instead.

I know that there are already ways to get e.g. geojson after query pgsql db with php and pg (like here and here). I think they are good starting points, but I am searching some other good materials with good examples (not only the PHP tutorial like here) to start with.

Any pointers are welcomed, thanks in advance,

PS. PHP to be used with postgis+pgsql+mapserver+geoext+ext+ol

  • 1
    Could you elaborate on what you're actually after? REST, different data formats import/export or something else? – Michal Zimmermann Sep 17 '14 at 15:07
  • @zimmi basically the common db get/post/delete/update using geojson, but also common ways to do queries like in featureserver – Gery Sep 17 '14 at 21:41
2
+75

If you're looking for geojson support, I would go for builtin PostgreSQL capabilities instead of parsing it with PHP. It's available since version 9.3 and it works like charm with Leaflet library.

You'd also probably need to do some routing if you want to build a RESTful app and you might find any of these PHP framework handy.

  • thanks zimmi, but I need to make interactive queries, I know this is done in the client (for me OL), but afaik a need an script that makes those calls in the server side, that's why I was using featureserver+geoalchemy, and I think PHP could replace these ones. – Gery Sep 19 '14 at 14:49
  • Well you just make an AJAX call from JS to PHP, which queries the database and returns the result. Than you just update the map with the new data. – Michal Zimmermann Sep 19 '14 at 18:17
  • @Gery, I agree zimmi, here an example where the webservice/ajax is a pure SQL, PHP need only to request the correct SQL function. – Peter Krauss Sep 24 '14 at 11:53
1

If you plan to use Mapserver and PostGIS, you may edit the spatial database using WFS-T provided by TinyOWS add-on: link to the docs

There is also a project called dirt-simple-postgis-http-api (former PostGIS RESTful Web Service Framework), but it's read-only. For full CRUD capabilities, you will have to create a backend service from scratch. OpenLayers.Strategy.Save and OpenLayers.Protocol.HTTP work well with RESTful APIs. Pick some PHP microframework to handle the URL routing, and you will probably find a tutorial how to create such API with it. The only special thing about GeoJSON is treating geometry and attributes as separate entities, while in a database they are columns in a single row. You will have to split them (when reading) or merge (when creating or updating) and use PostGIS functions - ST_AsGeoJSON for reading / ST_GeomFromGeoJSON for writing. Also, remember that OpenLayers uses FeatureCollection objects for reading features (GET request) or creating new features (POST request), and single Feature objects for updating (PUT request).

  • @Michael Mackiewicz thanks for the reply, but I want to use PHP scripting instead, I think it shouldn't be that harder but still want to take a look at some really nice examples, just that. I know about TiniOWS as well as microframeworks, but I am not after those ones. – Gery Sep 19 '14 at 17:18
  • 1
    Speaking of the ST_GeomFromGeoJson function, be aware you need JSON-c support enabled for your postgis installation, otherwise it won't work (I spent almost a day this week getting it right, it was hell). If you don't compile from source, it should probably work out of the box. – Michal Zimmermann Sep 19 '14 at 19:32
  • If ST_GeomFromGeoJson function doesn't work, then geoPHP library can convert GeoJSON to WKT or EWKB (PostGIS raw binary) geometry format ready for inserting into PostGIS. – Michal Mackiewicz Sep 20 '14 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.