@@ -63,6 +63,8 @@ |
|
public abstract int deleteLayer(Layer lyr) throws csip.ServiceException; |
|
+ public abstract int findSRID(Layer lyr) throws csip.ServiceException; |
+ |
public abstract Layer intersect(Layer one, Layer two) throws csip.ServiceException; |
|
public abstract Layer union(Layer one, Layer two) throws csip.ServiceException; |
@@ -79,7 +81,11 @@ |
|
public abstract Layer area(Layer lyr) throws csip.ServiceException; |
|
+ public abstract Layer transform(Layer lyr, int SRID) throws csip.ServiceException; |
+ |
public abstract JSONObject toJSON(Layer lyr) throws csip.ServiceException; |
|
+ public abstract JSONObject toJSON(Layer lyr, int outputSRID) throws csip.ServiceException; |
+ |
public abstract String toWKT(Layer lyr) throws csip.ServiceException; |
} |
@@ -6,6 +6,7 @@ |
package m.gis; |
|
import csip.ModelDataService; |
+import csip.ServiceException; |
import org.codehaus.jettison.json.JSONArray; |
|
/** |
@@ -16,6 +17,7 @@ |
|
protected JSONArray result; |
protected GeoJSON layers; |
+ protected int outputSRID; |
|
protected Database db; |
|
@@ -27,6 +29,12 @@ |
result = new JSONArray(); |
JSONArray geojson = getJSONArrayParam("layer"); |
layers = new GeoJSON(geojson, db); |
+ |
+ try { |
+ outputSRID = getIntParam("outputSRID"); |
+ } catch (ServiceException ex) { |
+ outputSRID = GeoJSONParser.getSRIDInt(Constants.DEFAULT_CRS); |
+ } |
} |
|
@Override |
@@ -160,6 +160,27 @@ |
} |
|
@Override |
+ public int findSRID(Layer lyr) throws ServiceException { |
+ try { |
+ int srid = -1; |
+ Statement stmt = conn.createStatement(); |
+ String sql = "SELECT Find_SRID('" + |
+ lyr.schema + "', '" + |
+ lyr.table + "', 'the_geom') as srid"; |
+ LOG.log(Level.INFO, sql); |
+ ResultSet rs = stmt.executeQuery(sql); |
+ if (rs.next()) { |
+ srid = rs.getInt("srid"); |
+ } |
+ |
+ stmt.close(); |
+ return srid; |
+ } catch (SQLException ex) { |
+ throw new csip.ServiceException(ex); |
+ } |
+ } |
+ |
+ @Override |
public int deleteLayer(Layer lyr) throws ServiceException { |
return deleteTable(lyr.getSchemaTable()); |
} |
@@ -301,6 +322,30 @@ |
} |
|
@Override |
+ public Layer transform(Layer lyr, int SRID) throws ServiceException { |
+ try { |
+ String table = "tfm_" + SESSION_ID + "_" + new RandomString(4).nextString(); |
+ String schemaTable = Constants.DEFAULT_SCHEMA + ".\"" + table + "\""; |
+ Statement stmt = conn.createStatement(); |
+ |
+ ArrayList<String> props = new ArrayList<>(Arrays.asList(new String[]{ |
+ "ST_Transform(" + lyr.getSchemaTable() + ".the_geom, " + SRID + ") as the_geom ", |
+ getProperties(lyr, true) |
+ })); |
+ String sql = "CREATE TABLE " + schemaTable + " AS " + |
+ "SELECT " + LocalStringUtils.join(props, ", ") + " " + |
+ "FROM " + lyr.getSchemaTable(); |
+ LOG.log(Level.INFO, sql); |
+ stmt.executeUpdate(sql); |
+ |
+ stmt.close(); |
+ return new Layer(Constants.DEFAULT_SCHEMA, table, this); |
+ } catch (SQLException ex) { |
+ throw new csip.ServiceException(ex); |
+ } |
+ } |
+ |
+ @Override |
public Layer extent(Layer lyr) throws ServiceException { |
try { |
String table = "ext_" + SESSION_ID + "_" + new RandomString(4).nextString(); |
@@ -421,6 +466,21 @@ |
} |
} |
|
+ @Override |
+ public JSONObject toJSON(Layer lyr, int outputSRID) throws ServiceException { |
+ try { |
+ int SRID = findSRID(lyr); |
+ if (SRID != outputSRID) { |
+ LOG.log(Level.INFO, "Translating " + lyr.toString() + " from " + |
+ SRID + " to " + outputSRID); |
+ lyr = transform(lyr, outputSRID); |
+ } |
+ return toJSON(lyr); |
+ } catch (ServiceException ex) { |
+ throw ex; |
+ } |
+ } |
+ |
@Override |
public String toWKT(Layer lyr) throws ServiceException { |
String wkt = ""; |