Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing an application where I take a route from google maps, save it in postgresql/postgis. I'd like to take this route (LineString geometry) and send it back to Google Maps.

I already can save the map in the database, now I want to show the routes on a map.

On the client side I'm using JQuery (AJAX) + Google Maps Api. On the server side I'm using REST services with RestEasy.

I tried to work with Jackson to transform the Entity to JSON, but, the Jackson fails to transform geometric data in json. Does anyone know how to transform this spatial data into JSON?

My Entity:

public class Rota {
private LineString caminho;
public Rota() {
public Rota(Integer id, Usuario usuario, String descricao, LineString     lineString) { = id;
    this.usuario = usuario;
    this.descricao = descricao;
    this.caminho = lineString;
// getters and setters
@Type(type = "org.hibernate.spatial.GeometryType")
public LineString getCaminho() {
    return caminho;
public void setCaminho(LineString caminho) {
    this.caminho = caminho;
// hashcode and equals method

My REST service:

private RotaBC rotaBC;

public Rota show(@PathParam("id") String id) {

The error:

15:05:16,447 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sharecar].[default]] (http-- Servlet.service() for servlet default threw exception: java.lang.ClassNotFoundException:$Reference from [Module "org.codehaus.jackson.jackson-mapper-asl:main" from local module loader @1d332b (roots: /opt/demoiselle/server/jboss-7.1/modules)] ... at org.jboss.modules.ConcurrentClassLoader.loadClass( at ... at at at

share|improve this question
Out of curiosity, how are you saving the route from google as a spatial object? – djq Jan 24 '13 at 5:11
GeometryFactory gf = new GeometryFactory(); Coordinate c[] = new Coordinate[pontos.length]; String ap[]; for (int i = 0; i < c.length; i++) { ap = pontos[i].split(","); c[i] = new Coordinate(Double.parseDouble(ap[0]), Double.parseDouble(ap[1])); } Rota r = new Rota(id, usuario, descricao, gf.createLineString(c)); rotaBC.create(r); – Luciano Borges Jan 25 '13 at 19:08
By JavaScript I take the geometry add do this: var a = aPontos.toString().substring(1, aPontos.toString().length - 1).split('),('); after I send the var a by ajax/post. – Luciano Borges Jan 25 '13 at 19:10 – Luciano Borges Jan 25 '13 at 19:11
What are you saving in your database? – djq Jan 25 '13 at 19:59
up vote 2 down vote accepted

To get json (or geojson) from PostGIS there is the function ST_geojson() which will return a geometric object in geojson form.

share|improve this answer
I'm using PostgreSQL 8.4 – Luciano Borges Jan 25 '13 at 19:11
ST_GeoJson is a PostGIS function, not PostGreSQL – djq Jan 25 '13 at 19:58
I know, but, the PostGIS that PostgreSQL 8.4 uses does not have this function. – Luciano Borges Jan 25 '13 at 20:04
Are you sure? According to the docs it was introduced in Postgis 1.3.4 – djq Jan 25 '13 at 21:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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