Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.here.xyz.jobs.datasets.filters.Filters;
import com.here.xyz.jobs.datasets.streams.Notifications;
import com.here.xyz.models.hub.Ref;
import com.here.xyz.util.geo.GeometryValidator;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = Id.NAME, property = "type")
Expand Down Expand Up @@ -90,6 +91,11 @@ public Filters getFilters() {
@Override
public void setFilters(Filters filters) {
this.filters = filters;
if(filters != null && filters.getSpatialFilter() != null && filters.getSpatialFilter().getGeometry() != null
&& GeometryValidator.isWorldBoundingBox(filters.getSpatialFilter().getGeometry())){
//Remove spatialFilter if it is a world bounding box
this.filters = null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@

import static com.here.xyz.models.hub.Ref.HEAD;

import com.here.xyz.XyzSerializable;
import com.here.xyz.events.PropertiesQuery;
import com.here.xyz.jobs.datasets.filters.SpatialFilter;
import com.here.xyz.jobs.steps.impl.transport.ExportSpaceToFiles;
import com.here.xyz.models.geojson.coordinates.PointCoordinates;
import com.here.xyz.models.geojson.implementation.Point;
import com.here.xyz.models.hub.Ref;

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import com.here.xyz.util.geo.GeometryValidator;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -46,7 +53,6 @@ public class ExportStepTest extends ExportTestBase {
*
*/


@BeforeEach
public void setUp() throws Exception {
putFeatureCollectionToSpace(SPACE_ID, readTestFeatureCollection("/testFeatureCollections/fcWithMixedGeometryTypes.geojson"));
Expand Down Expand Up @@ -94,4 +100,45 @@ public void exportWithSpatialAndPropertyFilter() throws Exception {
executeExportStepAndCheckResults(SPACE_ID, null, spatialFilter,
PropertiesQuery.fromString(propertiesQuery), new Ref(HEAD), hubQuery);
}

@Test
public void testWorldWideBBOX() throws IOException {
ExportSpaceToFiles step = XyzSerializable.deserialize("""
{
"type": "ExportSpaceToFiles",
"spatialFilter": {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-180.0,
-90.0
],
[
180,
-90.0
],
[
180.000,
90
],
[
-180,
90
],
[
-180,
-90
]
]
]
},
"clipped": true
}
}
""", ExportSpaceToFiles.class);

Assertions.assertTrue(GeometryValidator.isWorldBoundingBox(step.getSpatialFilter().getGeometry()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,18 @@ public BBox calculateBBox() {
}
return null;
}

public boolean isEqual(Position other) {
if (other == null || this.size() != other.size()) {
return false;
}

for (int i = 0; i < this.size(); i++) {
if (!this.get(i).equals(other.get(i))) {
return false;
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

package com.here.xyz.util.geo;

import com.here.xyz.models.geojson.coordinates.LinearRingCoordinates;
import com.here.xyz.models.geojson.coordinates.PolygonCoordinates;
import com.here.xyz.models.geojson.coordinates.Position;
import com.here.xyz.models.geojson.implementation.Geometry;
import com.here.xyz.models.geojson.implementation.Point;
import com.here.xyz.models.geojson.implementation.Polygon;

public class GeometryValidator {
public static int MAX_NUMBER_OF_COORDNIATES = 12_000;
Expand All @@ -46,6 +50,43 @@ public static void validateGeometry(Geometry geometry, int radius) throws Geomet
}
}

public static boolean isWorldBoundingBox(Geometry geometry) {
if (!(geometry instanceof Polygon)) {
return false;
}

Polygon polygon = (Polygon) geometry;
PolygonCoordinates coordinates = polygon.getCoordinates();

PolygonCoordinates expectedCoordinates = new PolygonCoordinates();
// Expected coordinates of a world bounding box
LinearRingCoordinates lrc = new LinearRingCoordinates();
lrc.add(new Position(-180.0, -90.0));
lrc.add(new Position(180.0, -90.0));
lrc.add(new Position(180.0, 90.0));
lrc.add(new Position(-180.0, 90.0));
lrc.add(new Position(-180.0, -90.0)); // close the ring
expectedCoordinates.add(lrc);

PolygonCoordinates inputCords = ((Polygon) geometry).getCoordinates();
if(inputCords.size() == 0)
return false;

LinearRingCoordinates inputLrc = inputCords.get(0);

if (lrc.size() != inputLrc.size()) {
return false;
}

for (int i = 0; i < lrc.size(); i++) {
if (!lrc.get(i).isEqual(inputLrc.get(i)) ) {
return false;
}
}

return true;
}

public static class GeometryException extends Exception {
public GeometryException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.here.xyz.test.util.geo;

import com.here.xyz.models.geojson.coordinates.LineStringCoordinates;
import com.here.xyz.models.geojson.coordinates.LinearRingCoordinates;
import com.here.xyz.models.geojson.coordinates.PointCoordinates;
import com.here.xyz.models.geojson.coordinates.PolygonCoordinates;
import com.here.xyz.models.geojson.coordinates.Position;
import com.here.xyz.models.geojson.exceptions.InvalidGeometryException;
import com.here.xyz.models.geojson.implementation.LineString;
import com.here.xyz.models.geojson.implementation.Point;
import com.here.xyz.models.geojson.implementation.Polygon;
import com.here.xyz.util.geo.GeometryValidator;
import com.here.xyz.util.geo.GeometryValidator.GeometryException;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -45,4 +48,20 @@ public void testInvalidGeometry() throws InvalidGeometryException {
Assertions.assertThrows(GeometryException.class, () -> GeometryValidator.validateGeometry(point, 0));
}

@Test
public void testIsWorldBoundingBox_withValidBBox() {
PolygonCoordinates expectedCoordinates = new PolygonCoordinates();
// Expected coordinates of a world bounding box
LinearRingCoordinates lrc = new LinearRingCoordinates();
lrc.add(new Position(-180.0, -90.0));
lrc.add(new Position(180.0, -90.0));
lrc.add(new Position(180.0, 90.0));
lrc.add(new Position(-180.0, 90.0));
lrc.add(new Position(-180.0, -90.0));

expectedCoordinates.add(lrc);
Polygon polygon = new Polygon().withCoordinates(expectedCoordinates);

Assertions.assertTrue(GeometryValidator.isWorldBoundingBox(polygon), "Should detect valid world bbox");
}
}