@@ -114,12 +114,18 @@ |
} |
|
sql = "INSERT INTO " + layer.getSchemaTable() + " (" + LocalStringUtils.join(cols, ",") + ") " + |
- "VALUES ('" + LocalStringUtils.join(vals, "', '") + "');"; |
+ "VALUES ('" + LocalStringUtils.join(vals, "', '") + "') RETURNING id"; |
LOG.log(Level.INFO, sql); |
- stmt.executeUpdate(sql); |
+ stmt.execute(sql); |
+ ResultSet lastUpdated = stmt.getResultSet(); |
+ int id = -1; |
+ if (lastUpdated.next()) { |
+ id = lastUpdated.getInt(1); |
+ } |
+ LOG.log(Level.INFO, "Uploaded feature with id: " + id); |
|
stmt.close(); |
- return new Feature(layer, featureJSON); |
+ return new Feature(layer, featureJSON, id); |
} catch (SQLException|JSONException ex) { |
throw new csip.ServiceException(ex); |
} |
@@ -261,6 +267,98 @@ |
} |
|
@Override |
+ public Layer extent(Layer lyr) throws ServiceException { |
+ try { |
+ String table = "ext_" + SESSION_ID + "_" + new RandomString(4).nextString(); |
+ String schemaTable = SCHEMA + ".\"" + table + "\""; |
+ Statement stmt = conn.createStatement(); |
+ String sql = "CREATE SCHEMA IF NOT EXISTS " + SCHEMA; |
+ stmt.executeUpdate(sql); |
+ |
+ sql = "DROP TABLE IF EXISTS " + schemaTable; |
+ LOG.log(Level.INFO, sql); |
+ stmt.executeUpdate(sql); |
+ |
+ ArrayList<String> props = new ArrayList<>(Arrays.asList(new String[]{ |
+ "ST_Extent(" + lyr.getSchemaTable() + ".the_geom)::geometry AS the_geom ", |
+ getProperties(lyr, true) |
+ })); |
+ 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(SCHEMA, table, null); |
+ } catch (SQLException ex) { |
+ throw new csip.ServiceException(ex); |
+ } |
+ } |
+ |
+ @Override |
+ public Layer envelope(Layer lyr) throws ServiceException { |
+ try { |
+ String table = "env_" + SESSION_ID + "_" + new RandomString(4).nextString(); |
+ String schemaTable = SCHEMA + ".\"" + table + "\""; |
+ Statement stmt = conn.createStatement(); |
+ String sql = "CREATE SCHEMA IF NOT EXISTS " + SCHEMA; |
+ stmt.executeUpdate(sql); |
+ |
+ sql = "DROP TABLE IF EXISTS " + schemaTable; |
+ LOG.log(Level.INFO, sql); |
+ stmt.executeUpdate(sql); |
+ |
+ ArrayList<String> props = new ArrayList<>(Arrays.asList(new String[]{ |
+ "ST_Envelope(ST_Collect(" + lyr.getSchemaTable() + ".the_geom)) AS the_geom ", |
+ getProperties(lyr, true) |
+ })); |
+ 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(SCHEMA, table, null); |
+ } catch (SQLException ex) { |
+ throw new csip.ServiceException(ex); |
+ } |
+ } |
+ |
+ @Override |
+ public Layer area(Layer lyr) throws ServiceException { |
+ try { |
+ String table = "area_" + SESSION_ID + "_" + new RandomString(4).nextString(); |
+ String schemaTable = SCHEMA + ".\"" + table + "\""; |
+ Statement stmt = conn.createStatement(); |
+ String sql = "CREATE SCHEMA IF NOT EXISTS " + SCHEMA; |
+ stmt.executeUpdate(sql); |
+ |
+ sql = "DROP TABLE IF EXISTS " + schemaTable; |
+ LOG.log(Level.INFO, sql); |
+ stmt.executeUpdate(sql); |
+ |
+ ArrayList<String> colsExclude = new ArrayList<>(Arrays.asList(new String[]{"the_geom","id","calc_area"})); |
+ ArrayList<String> props = new ArrayList<>(Arrays.asList(new String[]{ |
+ lyr.getSchemaTable() + ".the_geom ", |
+ "ST_Area(" + lyr.getSchemaTable() + ".the_geom::geography) AS calc_area ", |
+ getProperties(lyr, true, colsExclude) |
+ })); |
+ 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(SCHEMA, table, null); |
+ } catch (SQLException ex) { |
+ throw new csip.ServiceException(ex); |
+ } |
+ } |
+ |
+ @Override |
public JSONObject toJSON(Layer lyr) throws ServiceException { |
try { |
Statement stmt = conn.createStatement(); |
@@ -373,10 +471,18 @@ |
} |
|
public String getProperties(Layer lyr, boolean useTableSuffix) throws ServiceException { |
+ ArrayList<String> colsExclude = new ArrayList<>(Arrays.asList(new String[]{ |
+ "the_geom", |
+ "id", |
+ })); |
+ return getProperties(lyr, useTableSuffix, colsExclude); |
+ } |
+ |
+ public String getProperties(Layer lyr, boolean useTableSuffix, ArrayList<String> colsExclude) throws ServiceException { |
ArrayList<String> props = new ArrayList<>(); |
ArrayList<String> cols = getColumns(lyr.schema, lyr.table); |
for (String col : cols) { |
- if (!col.equals("the_geom") && !col.equals("id")) { |
+ if (!colsExclude.contains(col)) { |
String prop = lyr.getSchemaTable() + "." + col + " AS " + col; |
if (useTableSuffix && hasSuffix(lyr)) { |
prop += "_" + lyr.table.charAt(lyr.table.length() - 1); |