@Override public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress) throws SQLException, IOException{ GeoJsonWriteDriver geoJsonDriver = new GeoJsonWriteDriver(connection, tableReference, fileName); geoJsonDriver.write(progress); }
/** * Cache the column name and its index. * * @param resultSetMetaData * @throws SQLException */ private void cacheMetadata(ResultSetMetaData resultSetMetaData) throws SQLException { cachedColumnNames = new LinkedHashMap<String, Integer>(); for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { final String fieldTypeName = resultSetMetaData.getColumnTypeName(i); if (!fieldTypeName.equalsIgnoreCase("geometry") && isSupportedPropertyType(resultSetMetaData.getColumnType(i), fieldTypeName)) { cachedColumnNames.put(resultSetMetaData.getColumnName(i).toUpperCase(), i); columnCountProperties++; } } }
/** * Write coordinate array. * * @param coordinates * @param gen * @throws IOException */ private void writeCoordinates(Coordinate[] coordinates, JsonGenerator gen) throws IOException { gen.writeStartArray(); for (Coordinate coord : coordinates) { writeCoordinate(coord, gen); } gen.writeEndArray(); }
PreparedStatement ps = connection.prepareStatement(tableName, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = ps.executeQuery(); write(progress, resultSet, fileName, encoding); } else { throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'."); writeCRS(jsonGenerator, SFSUtilities.getAuthorityAndSRID(connection, parse, spatialFieldNames.get(0))); jsonGenerator.writeArrayFieldStart("features"); ResultSetMetaData resultSetMetaData = rs.getMetaData(); int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0)); cacheMetadata(resultSetMetaData); while (rs.next()) { writeFeature(jsonGenerator, rs, geoFieldIndex); copyProgress.endStep();
writeCRS(jsonGenerator,SFSUtilities.getAuthorityAndSRID(connection, parse, spatialFieldNames.get(0))); jsonGenerator.writeArrayFieldStart("features"); ProgressVisitor copyProgress = progress.subProcess(recordCount); cacheMetadata(resultSetMetaData); while (rs.next()) { writeFeature(jsonGenerator, rs, geoFieldIndex); copyProgress.endStep();
/** * Coordinates of LineString are an array of positions : * * { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] } * * @param geom * @param gen * @throws IOException */ private void write(LineString geom, JsonGenerator gen) throws IOException { gen.writeStringField("type", "LineString"); gen.writeFieldName("coordinates"); writeCoordinates(geom.getCoordinates(), gen); }
ResultSetMetaData resultSetMetaData = rs.getMetaData(); int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0)); cacheMetadata(resultSetMetaData); while (rs.next()) { writeFeature(jsonGenerator, rs, geoFieldIndex); copyProgress.endStep();
/** * Write a resulset to a geojson file * * @param progress * @param resultSet * @param file * @throws SQLException * @throws IOException */ public void write(ProgressVisitor progress, ResultSet resultSet, File file) throws SQLException, IOException { write(progress, resultSet, file, null); }
jsonGenerator.writeBoolean((boolean) array[i]); } else if (array[i] instanceof Object[]) { writeArray(jsonGenerator, (Object[]) array[i], false);
/** * Write the spatial table to GeoJSON format. * * @param progress * @throws SQLException * @throws java.io.IOException */ public void write(ProgressVisitor progress) throws SQLException, IOException { if (FileUtil.isExtensionWellFormated(fileName, "geojson")) { writeGeoJson(progress); } else { throw new SQLException("Only .geojson extension is supported"); } }
writeCRS(jsonGenerator, SFSUtilities.getAuthorityAndSRID(connection, parse, spatialFieldNames.get(0))); jsonGenerator.writeArrayFieldStart("features"); ResultSetMetaData resultSetMetaData = rs.getMetaData(); int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0)); cacheMetadata(resultSetMetaData); while (rs.next()) { writeFeature(jsonGenerator, rs, geoFieldIndex); copyProgress.endStep();
/** * Coordinates of LineString are an array of positions : * * { "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] } * * @param geom * @param gen * @throws IOException */ private void write(LineString geom, JsonGenerator gen) throws IOException { gen.writeStringField("type", "LineString"); gen.writeFieldName("coordinates"); writeCoordinates(geom.getCoordinates(), gen); }
gen.writeObjectFieldStart("geometry"); if (geom instanceof Point) { write((Point) geom, gen); } else if (geom instanceof MultiPoint) { write((MultiPoint) geom, gen); } else if (geom instanceof LineString) { write((LineString) geom, gen); } else if (geom instanceof MultiLineString) { write((MultiLineString) geom, gen); } else if (geom instanceof Polygon) { write((Polygon) geom, gen); } else if (geom instanceof MultiPolygon) { write((MultiPolygon) geom, gen); } else if (geom instanceof GeometryCollection) { write((GeometryCollection) geom, gen); } else { throw new RuntimeException("Unsupported Geomery type");
jsonGenerator.writeBoolean((boolean) array[i]); } else if (array[i] instanceof Object[]) { writeArray(jsonGenerator, (Object[]) array[i], false);
/** * Write the spatial table to GeoJSON format. * * @param progress * @throws SQLException * @throws java.io.IOException */ public void write(ProgressVisitor progress) throws SQLException, IOException { if (FileUtil.isExtensionWellFormated(fileName, "geojson")) { writeGeoJson(progress); } else { throw new SQLException("Only .geojson extension is supported"); } }
/** * Coordinates of a MultiPoint are an array of positions: * * { "type": "MultiPoint", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] } * * * @param points * @param gen * @throws IOException */ private void write(MultiPoint points, JsonGenerator gen) throws IOException { gen.writeStringField("type", "MultiPoint"); gen.writeFieldName("coordinates"); writeCoordinates(points.getCoordinates(), gen); }
/** * Export a table or a query to a geojson file * * @param connection * @param tableReference * @param fileName * @param progress * @param encoding * @throws SQLException * @throws IOException */ @Override public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress, String encoding) throws SQLException, IOException{ GeoJsonWriteDriver geoJsonDriver = new GeoJsonWriteDriver(connection); geoJsonDriver.write(progress,tableReference, fileName, encoding); }
gen.writeObjectFieldStart("geometry"); if (geom instanceof Point) { write((Point) geom, gen); } else if (geom instanceof MultiPoint) { write((MultiPoint) geom, gen); } else if (geom instanceof LineString) { write((LineString) geom, gen); } else if (geom instanceof MultiLineString) { write((MultiLineString) geom, gen); } else if (geom instanceof Polygon) { write((Polygon) geom, gen); } else if (geom instanceof MultiPolygon) { write((MultiPolygon) geom, gen); } else if (geom instanceof GeometryCollection) { write((GeometryCollection) geom, gen); } else { throw new RuntimeException("Unsupported Geomery type");
/** * Write coordinate array. * * @param coordinates * @param gen * @throws IOException */ private void writeCoordinates(Coordinate[] coordinates, JsonGenerator gen) throws IOException { gen.writeStartArray(); for (Coordinate coord : coordinates) { writeCoordinate(coord, gen); } gen.writeEndArray(); }
jsonGenerator.writeBoolean((boolean) array[i]); } else if (array[i] instanceof Object[]) { writeArray(jsonGenerator, (Object[]) array[i], false);