@Override public void addFeature( String layerName, String featureId, String geometryName, Geometry geometry, Map<String, Object> properties) { encoder.addFeature(layerName, properties, geometry); }
List<Integer> commands(Geometry geometry) { if (geometry instanceof MultiLineString) { return commands((MultiLineString) geometry); } if (geometry instanceof Polygon) { return commands((Polygon) geometry); } if (geometry instanceof MultiPolygon) { return commands((MultiPolygon) geometry); } return commands(geometry.getCoordinates(), shouldClosePath(geometry), geometry instanceof MultiPoint); }
/** * Create a {@link VectorTileEncoder} with the given extent value. * <p> * The extent value control how detailed the coordinates are encoded in the * vector tile. 4096 is a good default, 256 can be used to reduce density. * <p> * The clip buffer value control how large the clipping area is outside of * the tile for geometries. 0 means that the clipping is done at the tile * border. 8 is a good default. * * @param extent * a int with extent value. 4096 is a good value. * @param clipBuffer * a int with clip buffer size for geometries. 8 is a good value. * @param autoScale * when true, the encoder expects coordinates in the 0..255 range * and will scale them automatically to the 0..extent-1 range * before encoding. when false, the encoder expects coordinates * in the 0..extent-1 range. * */ public VectorTileEncoder(int extent, int clipBuffer, boolean autoScale) { this.extent = extent; this.autoScale = autoScale; final int size = autoScale ? 256 : extent; clipGeometry = createTileEnvelope(clipBuffer, size); }
splitAndAddFeatures(layerName, attributes, (GeometryCollection) geometry); return; if (!clipCovers(geometry)) { return; geometry = clipGeometry(geometry); splitAndAddFeatures(layerName, attributes, (GeometryCollection) geometry); return;
featureBuilder.tags = toIntArray(feature.tags); featureBuilder.setType(toGeomType(geometry)); featureBuilder.geometry = toIntArray(commands(geometry));
@Override public RawMap build(WMSMapContent mapContent) throws IOException { byte[] contents = encoder.encode(); return new RawMap(mapContent, contents, MIME_TYPE); }
r.add(commandAndLength(Command.MoveTo, multiPoint ? cs.length : 1)); r.add(zigZagEncode(_x - x)); r.add(zigZagEncode(_y - y)); r.add(commandAndLength(Command.LineTo, lineToLength)); } else { r.set(lineToIndex, commandAndLength(Command.LineTo, lineToLength)); r.add(commandAndLength(Command.ClosePath, 1));
if (!clipCovers(geometry)) { return; geometry = clipGeometry(geometry);
featureBuilder.setType(toGeomType(geometry)); featureBuilder.addAllGeometry(commands(geometry));
/** * // // // Ex.: MoveTo(3, 6), LineTo(8, 12), LineTo(20, 34), ClosePath // * Encoded as: [ 9 3 6 18 5 6 12 22 15 ] // == command type 7 (ClosePath), * length 1 // ===== relative LineTo(+12, +22) == LineTo(20, 34) // === * relative LineTo(+5, +6) == LineTo(8, 12) // == [00010 010] = command type * 2 (LineTo), length 2 // === relative MoveTo(+3, +6) // == [00001 001] = * command type 1 (MoveTo), length 1 // Commands are encoded as uint32 * varints, vertex parameters are // encoded as sint32 varints (zigzag). * Vertex parameters are // also encoded as deltas to the previous position. * The original // position is (0,0) * * @param cs * @return */ List<Integer> commands(Coordinate[] cs, boolean closePathAtEnd) { return commands(cs, closePathAtEnd, false); }
@Override public RawMap build(WMSMapContent mapContent) throws IOException { byte[] contents = encoder.encode(); return new RawMap(mapContent, contents, MIME_TYPE); } }
r.add(commandAndLength(Command.MoveTo, multiPoint ? cs.length : 1)); r.add(zigZagEncode(_x - x)); r.add(zigZagEncode(_y - y)); r.add(commandAndLength(Command.LineTo, lineToLength)); } else { r.set(lineToIndex, commandAndLength(Command.LineTo, lineToLength)); r.add(commandAndLength(Command.ClosePath, 1));
/** * // // // Ex.: MoveTo(3, 6), LineTo(8, 12), LineTo(20, 34), ClosePath // * Encoded as: [ 9 3 6 18 5 6 12 22 15 ] // == command type 7 (ClosePath), * length 1 // ===== relative LineTo(+12, +22) == LineTo(20, 34) // === * relative LineTo(+5, +6) == LineTo(8, 12) // == [00010 010] = command type * 2 (LineTo), length 2 // === relative MoveTo(+3, +6) // == [00001 001] = * command type 1 (MoveTo), length 1 // Commands are encoded as uint32 * varints, vertex parameters are // encoded as sint32 varints (zigzag). * Vertex parameters are // also encoded as deltas to the previous position. * The original // position is (0,0) * * @param cs * @return */ List<Integer> commands(Coordinate[] cs, boolean closePathAtEnd) { return commands(cs, closePathAtEnd, false); }
@Override public void addFeature(String layerName, String featureId, String geometryName, Geometry geometry, Map<String, Object> properties) { encoder.addFeature(layerName, properties, geometry); }
exteriorRing = (LineString) exteriorRing.reverse(); commands.addAll(commands(exteriorRing.getCoordinates(), true)); interiorRing = (LineString) interiorRing.reverse(); commands.addAll(commands(interiorRing.getCoordinates(), true)); GeometryCollection gc = (GeometryCollection) geometry; for (int i = 0; i < gc.getNumGeometries(); i++) { commands.addAll(commands(gc.getGeometryN(i).getCoordinates(), false)); return commands(geometry.getCoordinates(), shouldClosePath(geometry), geometry instanceof MultiPoint);
List<Integer> commands(MultiPolygon mp) { List<Integer> commands = new ArrayList<Integer>(); for (int i = 0; i < mp.getNumGeometries(); i++) { Polygon polygon = (Polygon) mp.getGeometryN(i); commands.addAll(commands(polygon)); } return commands; }
/** * Create a {@link VectorTileEncoder} with the given extent value. * <p> * The extent value control how detailed the coordinates are encoded in the * vector tile. 4096 is a good default, 256 can be used to reduce density. * <p> * The clip buffer value control how large the clipping area is outside of * the tile for geometries. 0 means that the clipping is done at the tile * border. 8 is a good default. * * @param extent * a int with extent value. 4096 is a good value. * @param clipBuffer * a int with clip buffer size for geometries. 8 is a good value. * @param autoScale * when true, the encoder expects coordinates in the 0..255 range * and will scale them automatically to the 0..extent-1 range * before encoding. when false, the encoder expects coordinates * in the 0..extent-1 range. * @param autoincrementIds * */ public VectorTileEncoder(int extent, int clipBuffer, boolean autoScale, boolean autoincrementIds) { this.extent = extent; this.autoScale = autoScale; this.autoincrementIds = autoincrementIds; this.autoincrement = 1; final int size = autoScale ? 256 : extent; clipGeometry = createTileEnvelope(clipBuffer, size); }
public void addFeature(String layerName, Map<String, ?> attributes, Geometry geometry) { this.addFeature(layerName, attributes, geometry, this.autoincrementIds ? this.autoincrement++ : -1); }
List<Integer> commands(MultiLineString mls) { List<Integer> commands = new ArrayList<Integer>(); for (int i = 0; i < mls.getNumGeometries(); i++) { commands.addAll(commands(mls.getGeometryN(i).getCoordinates(), false)); } return commands; }
private void splitAndAddFeatures(String layerName, Map<String, ?> attributes, GeometryCollection geometry) { for (int i = 0; i < geometry.getNumGeometries(); i++) { Geometry subGeometry = geometry.getGeometryN(i); addFeature(layerName, attributes, subGeometry); } }