Reputation: 876
I work with postgis and I have library for java to select data.now I want to convert this data to Geojson because Geoext need GeoJson Object to display data .Can anybody help me?
ResultSet resultSet = s.executeQuery("select * from a1");
while (resultSet.next()) {
PGgeometry mp = (PGgeometry) resultSet.getObject("geom");
MultiPolygon mp1 = (MultiPolygon) mp.getGeometry();
//TODO
}
}
Upvotes: 1
Views: 2137
Reputation: 43672
Use ST_AsGeoJSON in the query, and receive the GeoJSON text from the server.
String query = "select ST_GeoJSON(geom) AS geojson, * from a1"
ResultSet resultSet = s.executeQuery(query);
while (resultSet.next()) {
String geoJSON = resultSet.getString("geojson");
/* etc */
}
Upvotes: 3