You are here

how to create a custom WMS from my own PHP code

6 posts / 0 new
Last post
how to create a custom WMS from my own PHP code

Some different questions regarding suas mapserver 4 (interesting software!!):

- Is postgresql a requirement or not? It is listed in the mandatory prerequisites but together with mysql (1 and 2). Perhaps this means I can use EITHER 1 or 2?
I tried my installation (ubuntu) with both of them enabled (just to be safe), but our production server has not postgresql so I wonder if it is mandatory or not

- May I change the server url somehow? I have a different hostname if accessing from inside or outside the university. As I configured suas from inside, I used the "local" name when creating the googlemaps API, but then it doesnt work when accessing from home
EDIT (I answer myself): this setting is in config.php file, $baseserverhost

- I am so interested in creating a PHP script which might somehow define a custom WMS service, not depending on any server files. 2 different approaches:
1. Let's say I want let the user pass a POST query with data, so mapserver processes them to generate WMS responses. Could you please give me clues on how to accomplish this?
2. My php script would get data from my own defined mysql tables, and I want to create a WMS from that.

So both are similar cases: the key is how to pass data (and which format) to the appropiate existing saus php scripts which generate the WMS responses

Thank you very much in advance for your help


To illustrate a bit more what I meant with my first example, lets call my PHP script customWMS.php

I would let user call this script passing it an array of geographical features (those the user is interested to map). All of them should be defined using the same SRS, and all parameters that SUAS should require would be passed in this array (layer definition/style/metadata, features definition ... whatever).
As this could be large data, that's the reason I said that they could be passed to customWMS.php using POST request. But there could be another way: let the user store these data in another internet site, and just pass this GET parameter to our script, like this:
(I don't know if the above url syntax is appropriate but you get the idea)

This script should work like the http://mysite/suas/files/atlas/1/wms.php
script, the only difference is that all mapped data should come from userdata parameter (not from layers defined in SAUS server files).

Does anyone know of any public WMS server letting users map their data like this? (just to generate a transparent layer of polygons, squares or even points ... no other layers behind)

The idea is provide our university users (students/researchers) an easy way to map/share their own data with potential GIS users, not having to install their own WMS server.
I suppose SUAS was not designed for this usage, but I think it is the simplest available option (compared to other like or, which look much more complex; we also prefer it due the PHP-MySQL approach, since this university has already a running server). But before trying to dive into this perhaps you could give me some clues:

- If you know other projects we could reuse for trying this kind of PHP-WMS service, your comments are so appreciated. In the mean time, which are the relevant SUAS files to deal with?

- Which input data format would you recommend? I have to say I'm a beginner to both GIS and WMS technologies, so they will be many obvious things I could be missing.
I imagine that a combination of fields from the mysql tables suasatlas, suasstyle, suasfeatureclass and suasfeaturegeometry would do it?

I could find answers just diving into SUAS php files, but perhaps somebody else think this is an interesting feature (even SUAS developers), so I prefer to share my thoughts before diving. Maybe this "remote data option" could be available by default in future SUAS releases?.

My 2nd example (data coming from my own defined mysql tables) was just a workaround for the same objective. But as this would be a mapping service even for anonymous users, I think the foreign url file for user data is a better option.

A non related question: what minimum hardware is recommended for SUAS? I have not seen this in documentation (only software requirements).

Thank you all for your comments & advices
Abu Bel


firstly answer your questions:
1. postgresql is not mandatory, actually the current version only support mysql
2. you can change the server url in config.php as you like.

then about the last question:
There is example script in SUAS, once you create your atlas, you can view the demo, the demo page has one basic WMS request form, you can learn how to send via POST, and you should know some basic thing about WMS specification, such as request parameter: bbox, format....


hi, after reading your requirement, i think your purpose can be done with Openlayers and SUAS
1. use SUAS ans standard WMS service.
2. Use Openlayers as front GUI to let students add, edit geometries or shapes.
look at "Geometry intersection example" and
"OpenLayers Select Feature Example"
3. write one php script to receive and store the custom geometries from users into mysql database, store format can be WKT(mysql native support).
4. render the geometries from db as layers , example:
look at "Feature Styles Example" and many other custom layer example.

by the way, the recommended hardware for SUAS, ummmmm, not so strict, as my experience, SUAS can be run on Pentium IV, or AMD 2600+, and CoreDuo. It depends on the database size, if you use huge database, you need one powerful server.


leelight, thanks a lot for your reply:

I understand the use of openlayers for data input and WKT-MySQL for data storage ... but why do you link openlayers again for "render geometries from db as layers"? Isn't that SUAS mission?
I think openlayers is merely a client developing tool, but my problem is just at WMS server side (how to render and serve a transparent layer of polygons/points with distribution of whatever kind of WKT data). I just want my server to be compatible with WMS clients, no matters if they use openlayers or any other GIS desktop or web applications to show our server maps.

The point is: once my server receives WKT data (either from MySQL or a remote file), how do I reuse SUAS scripts to generate a WMS service URL for that user?
I am looking for CSV data processing code in SUAS PHP scripts. Perhaps I might bypass MySQL usage (go directly from CSV file load to layer drawing). I understand the "geom" data (SUAS "CSV file standart format") has to be in WKT format. Right?
Could you clarify the CSV input format with some examples? I would like to get a definition for all CSV headers (specially xlink, attributes, and the different IDs), and also know if you plan to change/add something else (headers differ in SUAS 3 and 4).

Many thanks in advance for your answers!

BTW, no idea about similar projects already running over any other WMS servers? (I mean, a public WMS server that lets you pass GET/POST data to render your custom layer). Something similar to the googlemaps service for mapping stuff, but in this case just producing a transparent WMS compliant layer (that whoever could load using a GIS).
I googled a lot for this, it surprises me a lot not finding anything similar ...


Hi abu,
yes, you are right, "render geometries from db as layers", this task can be done in SUAS or in Openlayers. But if you want to modify the geometry, you need use Openlayers, because SUAS render the static image map.

If you just want use SUAS to render static map, it is ok.

1. I understand the "geom" data (SUAS "CSV file standart format") has to be in WKT format. Right?
yes, right. the example CSV file you can download from google codes, "demo data". Forget SUAS3, i have stopped to support it.

2. about similar projects already running over any other WMS servers?
I have not ever seen such server.
My suggestion, try understand the CSV parser in SUAS(or other parser), write you own parser to receive the data from user, and save it into SUAS database. There is one good example in SUAS, go to My Atlas->select one atlas->configuration->Geo Edit, this is one Geo GUI tool to let use add geometries into database, not yet finished, but at least you can save what you have added on the map into SUAS database as one layer.

Log in to post comments