Skip to content

Commit

Permalink
Adding javadocs to vector tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
smithkm committed May 18, 2017
1 parent 38b55fc commit 9c5642e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@
import org.geoserver.wms.WMSMapContent;
import org.geoserver.wms.map.RawMap;

/**
* WebMap that uses a DeferredFileOutputStream for its content rather than a byte array.
*
*/
public class DeferredFileOutputStreamWebMap extends RawMap {

private DeferredFileOutputStream mapContents;

/**
* @param mapContent Unencoded map content
* @param mapContents Stream to which the encoded map has been written. This will be closed.
* @param mimeType Format of the map
* @throws IOException
*/
public DeferredFileOutputStreamWebMap(WMSMapContent mapContent,
DeferredFileOutputStream mapContents, String mimeType) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;

/**
* A chainable unary operation on a geometry.
*
*/
abstract class Pipeline {

protected static final Geometry EMPTY = new GeometryFactory().createPoint((Coordinate) null);

/**
* Pipeline terminator which returns the geometry without change.
*/
static final Pipeline END = new Pipeline() {

@Override
Expand All @@ -29,11 +36,21 @@ protected final Geometry _run(Geometry geom) {

private Pipeline next = END;

/**
* Set the next operation in the pipeline
* @param step
*/
void setNext(Pipeline step) {
Preconditions.checkNotNull(next);
this.next = step;
}

/**
* Execute pipeline including all downstream pipelines.
* @param geom
* @return
* @throws Exception
*/
Geometry execute(Geometry geom) throws Exception {
Preconditions.checkNotNull(next, getClass().getName());
Geometry g = _run(geom);
Expand All @@ -43,5 +60,11 @@ Geometry execute(Geometry geom) throws Exception {
return next.execute(g);
}

/**
* Implementation of the pipeline. A unary operation on a geometry.
* @param geom
* @return
* @throws Exception
*/
protected abstract Geometry _run(Geometry geom) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

class PipelineBuilder {

// The base simplification tolerance for screen coordinates.
private static final double PIXEL_BASE_SAMPLE_SIZE = 0.25;

static class Context {

@Nullable
Expand Down Expand Up @@ -85,6 +88,15 @@ private PipelineBuilder(Context context) {
this.context = context;
}

/**
*
* @param renderingArea The extent of the tile in target CRS
* @param paintArea The extent of the tile in screen/pixel coordinates
* @param sourceCrs The CRS of the features
* @param overSampleFactor Divisor for simplification tolerance.
* @return
* @throws FactoryException
*/
public static PipelineBuilder newBuilder(ReferencedEnvelope renderingArea, Rectangle paintArea,
CoordinateReferenceSystem sourceCrs, double overSampleFactor) throws FactoryException {

Expand Down Expand Up @@ -129,7 +141,7 @@ private static Context createContext(ReferencedEnvelope mapArea, Rectangle paint
throw Throwables.propagate(e);
}

context.screenSimplificationDistance = 0.25 / overSampleFactor;
context.screenSimplificationDistance = PIXEL_BASE_SAMPLE_SIZE / overSampleFactor;
// use min so generalize "less" (if pixel is different size in X and Y)
context.targetCRSSimplificationDistance = Math.min(spans_targetCRS[0], spans_targetCRS[1])
/ overSampleFactor;
Expand All @@ -142,16 +154,27 @@ private static Context createContext(ReferencedEnvelope mapArea, Rectangle paint
return context;
}

/**
* Prepares features for subsequent manipulation
* @return
*/
public PipelineBuilder preprocess() {
addLast(new PreProcess(context.projectionHandler, context.screenMap));
return this;
}

/**
* Flatten singleton feature collections
* @return
*/
public PipelineBuilder collapseCollections() {
addLast(new CollapseCollections());
return this;
}

/**
* @return the completed pipeline
*/
public Pipeline build() {
return first;
}
Expand Down Expand Up @@ -218,6 +241,11 @@ protected Geometry _run(Geometry geom) throws TransformException, FactoryExcepti

}

/**
* Transform from source CRS to target.
* @param transformToScreenCoordinates If true, further transfrorm from target to screen coordinates
* @return
*/
public PipelineBuilder transform(final boolean transformToScreenCoordinates) {
final MathTransform sourceToScreen = context.sourceToScreen;
final MathTransform sourceToTargetCrs = context.sourceToTargetCrs;
Expand All @@ -228,6 +256,11 @@ public PipelineBuilder transform(final boolean transformToScreenCoordinates) {
return this;
}

/**
* Simplify the geometry
* @param isTransformToScreenCoordinates Use screen coordinate space simplification tolerance
* @return
*/
public PipelineBuilder simplify(boolean isTransformToScreenCoordinates) {

double pixelDistance = context.screenSimplificationDistance;
Expand All @@ -240,6 +273,12 @@ public PipelineBuilder simplify(boolean isTransformToScreenCoordinates) {
return this;
}

/**
* Clip to the area of the tile plus its gutter
* @param clipToMapBounds Do we actually want to clip. Does nothing if false.
* @param transformToScreenCoordinates is the pipeline working in screen coordinates
* @return
*/
public PipelineBuilder clip(boolean clipToMapBounds, boolean transformToScreenCoordinates) {
if (clipToMapBounds) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,28 @@

import com.vividsolutions.jts.geom.Geometry;

/**
* Collects features into a vector tile
*/
public interface VectorTileBuilder {

/**
* Add a feature to the tile
* @param layerName The name of the feature set
* @param featureId The identifier of the feature within the feature set
* @param geometryName The name of the geometry property
* @param geometry The geometry value
* @param properties The non-geometry attributes of the feature
*/
void addFeature(String layerName, String featureId, String geometryName, Geometry geometry,
Map<String, Object> properties);


/**
* Build the tile
* @param mapContent The context for building the tile.
* @return A WebMap containing the completed tile
* @throws IOException
*/
WebMap build(WMSMapContent mapContent) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@

public interface VectorTileBuilderFactory {

/**
* A set of identifiers for the format produced by builders from this factory. May include
* MIME type or file extension.
*/
Set<String> getOutputFormats();

/**
* The MIME type of the format produced by builders from this factory.
*/
String getMimeType();

/**
* Create a builder
* @param screenSize The extent of the tile in screen coordinates
* @param mapArea The extent of the tile in target CRS coordinates
*/
VectorTileBuilder newBuilder(Rectangle screenSize, ReferencedEnvelope mapArea);

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,25 @@ public VectorTileMapOutputFormat(WMS wms, VectorTileBuilderFactory tileBuilderFa
this.tileBuilderFactory = tileBuilderFactory;
}

/**
* Multiplies density of simplification from its base value.
* @param factor
*/
public void setOverSamplingFactor(double factor) {
this.overSamplingFactor = factor;
}

/**
* Does this format use features clipped to the extent of the tile instead of whole features
* @param clip
*/
public void setClipToMapBounds(boolean clip) {
this.clipToMapBounds = clip;
}

/**
* Does this format use screen coordinates
*/
public void setTransformToScreenCoordinates(boolean useScreenCoords) {
this.transformToScreenCoordinates = useScreenCoords;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public class VectorMapRenderUtils {

private static final FilterFactory2 FF = CommonFactoryFinder.getFilterFactory2();

/**
* Creates a query selecting those features relevant to the style and extent of the given map,
* for the given layer.
* @param layer
* @param mapContent
* @return
* @throws IOException
*/
public static Query getStyleQuery(Layer layer, WMSMapContent mapContent) throws IOException {

final ReferencedEnvelope renderingArea = mapContent.getRenderingArea();
Expand Down

0 comments on commit 9c5642e

Please sign in to comment.