Skip to content

Commit

Permalink
MapBox response on /items breaks georeferencing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandor777 committed Oct 1, 2018
1 parent ff90cef commit 7939081
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.geoserver.wfs3;

import org.apache.commons.lang3.StringUtils;
import org.geotools.geometry.jts.ReferencedEnvelope;

/** Current tiling request scope data, for context propagation */
public class TileDataRequest {
Expand All @@ -13,6 +14,7 @@ public class TileDataRequest {
private Long level;
private Long row;
private Long col;
private ReferencedEnvelope bboxEnvelope;

public TileDataRequest() {}

Expand Down Expand Up @@ -51,4 +53,12 @@ public Long getCol() {
public void setCol(Long col) {
this.col = col;
}

public ReferencedEnvelope getBboxEnvelope() {
return bboxEnvelope;
}

public void setBboxEnvelope(ReferencedEnvelope bboxEnvelope) {
this.bboxEnvelope = bboxEnvelope;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ private Filter getFullFilter(Map kvp) throws IOException {
filters.add(filterFactory.id(ids));
}
if (kvp.containsKey("bbox")) {
Filter bboxFilter = bboxFilter(kvp.get("bbox"));
Object bbox = kvp.get("bbox");
Filter bboxFilter = bboxFilter(bbox);
filters.add(bboxFilter);
// trace requested bbox envelope for use on MVT output crop
if (bbox instanceof ReferencedEnvelope)
tileData.setBboxEnvelope((ReferencedEnvelope) bbox);
}
if (kvp.containsKey("time")) {
Object timeSpecification = kvp.get("time");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected void write(
FeatureCollectionResponse featureCollection, OutputStream output, Operation getFeature)
throws IOException, ServiceException {
GetFeatureType getFeatureType = (GetFeatureType) getFeature.getParameters()[0];

Integer resolution =
getFeatureType.getResolution() != null ? getFeatureType.getResolution() : 256;
FeatureCollection collection = featureCollection.getFeatures().get(0);
Expand All @@ -73,12 +74,7 @@ protected void write(
.getType()
.getCoordinateReferenceSystem();
// get area envelope from GridSet if tile request data, else from collection
ReferencedEnvelope area =
ReferencedEnvelope.create(
tileData.isTileRequest()
? envelopeFromTileRequestData()
: collection.getBounds(),
refSys);
ReferencedEnvelope area = getArea(collection);
// Build the Pipeline (sort of coordinates transformer)
Pipeline pipeline = getPipeline(area, paintArea, refSys, resolution / 32);
// setup the vector tile encoder
Expand Down Expand Up @@ -205,6 +201,26 @@ private ReferencedEnvelope envelopeFromTileRequestData() {
}
}

private ReferencedEnvelope getArea(FeatureCollection collection) {
if (tileData.getBboxEnvelope() != null) {
return tileData.getBboxEnvelope();
}
CoordinateReferenceSystem refSys =
collection
.getSchema()
.getGeometryDescriptor()
.getType()
.getCoordinateReferenceSystem();
// get area envelope from GridSet if tile request data, else from collection
ReferencedEnvelope area =
ReferencedEnvelope.create(
tileData.isTileRequest()
? envelopeFromTileRequestData()
: collection.getBounds(),
refSys);
return area;
}

public TileDataRequest getTileData() {
return tileData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,28 @@ public void testItemsFeatureRoadsEncode() throws Exception {
"LINESTRING (134.0928 90.6752, 170.6752 74.6752, 213.3248 53.3248)",
featuresList.get(1).getGeometry().toText());
}

/** Tests mapbox protobuf encoding for features in items, with bbox filter */
@Test
public void testItemsFeatureBuildingsBBOX() throws Exception {
// get ptb inputstream
String roadSegments = getEncodedName(MockData.BUILDINGS);
// real building bbox is BBOX=0.002,0.001,0.0024,0.0008
// we will crop it to BBOX=0.002,0.001,0.0024,0.0003
String path =
"wfs3/collections/"
+ roadSegments
+ "/items?f=application%2Fx-protobuf%3Btype%3Dmapbox-vector&resolution=10000"
+ "&BBOX=0.002,0.001,0.0024,0.0003";
MockHttpServletResponse response = getAsServletResponse(path);
byte[] responseBytes = response.getContentAsByteArray();
VectorTileDecoder decoder = new VectorTileDecoder();
FeatureIterable fiter = decoder.decode(responseBytes);
List<Feature> featuresList = fiter.asList();
assertEquals(1, featuresList.size());
assertEquals("cite__Buildings", featuresList.get(0).getLayerName());
assertEquals(
"POLYGON ((0 73.1392, 0 0, 256 0, 256 73.1392, 0 73.1392))",
featuresList.get(0).getGeometry().toText());
}
}

0 comments on commit 7939081

Please sign in to comment.