OpenLayers Wrapper Features to other formats


We’re developing a web GIS application based on Vaadin and OpenLayers wrapper. Our goal is to be able to create, edit and delete features on a map and eventually store the features in PostGIS database and now we’re trying to figure out how to get there with these tools.

First we thought about WFS-T with GeoServer but the wrapper lacks support for it. Then we thought that we could convert features into GeoJSON or WKT and then store them but those aren’t either supported by the wrapper and we’re stuck trying to implement these features ourselves, because we aren’t gurus. :slight_smile:

Could someone suggest a solution to our problem? What would be the simplest way to convert OpenLayers features into a format that we can store in PostGIS? (via GeoServer or not).

Thanks in advance.


WFS-T is something that I have never used by myself, but several developers have asked if OpenLayers Wrapper would support it. So far I think none of the add-ons developers have worked on it, but maybe some day.

Without knowing your architecture or requirements better it is hard to say what would be the best approach for you. If you can access the database directly from your java server it is quite easy to query data directly and display stuff with VectorLayer. This way you don’t need to setup a separate map server at all. If you wish to make it cleaner, you should look into creating JPA entities for you data types.

Too bad I personally have quite limited resources to invest on this project currently. Lots of official Vaadin work to do and too little spare time - especially during the hunting season. I really like working on GIS stuff and I see a great potential in Vaadin based GIS apps. So many ideas - too little time (or slow brains) for them.

WKT support
should be there.


Thank you Matti for very quick response! And thanks for the nice addon also. :slight_smile:

We have direct access to the PostGIS database and we are able to get the features out from there in various formats and handle them in our business logic. Our problem is how to convert OpenLayers vectors back to some format we could store in the database. Do you have any suggestions how to do that without modifying the wrapper?


Are editing some geo data in your DB or creating something new? I’m not sure if I missed something, but if you make your Vectors in VectorLayer editable you can just read their new points when user clicks save. There is also VectorModifiedListener and VectorAddedListener available in the VectorLayer. If you are using Form to edit your entities you should definitely look into CustomField addon and create a field that contains OpenLayersMap to edit coordinates related to your business objects.

I really should build better demo applications for the add-on.
is one small app that has sources online, but it is more like a quick and dirty prototype than a proper example app.


The easiest way to get the Vectors back into the PostGIS db is to convert the Vector into a WKT string and then use the PostGIS function st_geomfromtext to set the value of the geometry field.
Here’s example code that creates either a POINT or POLYGON WKT from a Vector v:

		isPoint = v.getPoints().length == 1;

		StringBuilder coords = new StringBuilder();
		for (Point p : v.getPoints()) {
			coords.append(p.getLon() + " " +  p.getLat() + ",");
		String wkt;
		if (isPoint) {
			wkt = "POINT(" + coords.substring(0, coords.length() - 1) + ")";
		} else {
			// Close the polygon 
.getLon() + " " + v.getPoints()[0]
			wkt = "POLYGON((" + coords.toString() + "))";


If this is commonly used would it be handy if there was getWKT() function in VOL’s Vector objects?


Hi Matti and John,

WKT and GeoJSON presentations would be nice to get straight out from Vectors. OpenLayers API has functions for those. I already made my own not-probably-so-sophisticated Vector → GeoJSON and back converters with Google GSON library and simple wrappers for it. Now I’m able to save the geometries (points, polylines and polygons) in PostGIS format.

Thanks for your replies!