Skip to content

Commit

Permalink
SpatialFilter: restrict setter to allow only valid geometries
Browse files Browse the repository at this point in the history
Signed-off-by: qGYdXbY2 <[email protected]>
  • Loading branch information
qGYdXbY2 committed Jul 31, 2024
1 parent 360f355 commit 75adb47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ public void createJobWithExistingId(){
.statusCode(CONFLICT.code());
}

/* commented out, as SpatialFilter().withGeometry(.invalid.) is now throwing an exception
@Test
public void createJobWithInvalidFilter() {
/** Create job */
// Create job
Export job = new Export()
.withId(testJobId + CService.currentTimeMillis())
.withDescription("Job Description")
Expand All @@ -116,6 +117,7 @@ public void createJobWithInvalidFilter() {
//Add check if no config exists
}
*/

@Test
public void getJob(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonView;
import com.here.xyz.XyzSerializable.Public;
import com.here.xyz.models.geojson.exceptions.InvalidGeometryException;
import com.here.xyz.models.geojson.implementation.Geometry;

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
Expand All @@ -40,11 +41,12 @@ public Geometry getGeometry() {
return geometry;
}

public void setGeometry(Geometry geometry) {
public void setGeometry(Geometry geometry) throws InvalidGeometryException {
geometry.validate();
this.geometry = geometry;
}

public SpatialFilter withGeometry(Geometry geometry) {
public SpatialFilter withGeometry(Geometry geometry) throws InvalidGeometryException {
this.setGeometry(geometry);
return this;
}
Expand All @@ -62,6 +64,11 @@ public SpatialFilter withRadius(final int radius) {
return this;
}

public boolean isValidGeom()
{
return true;
}

/**
* @deprecated Use {@link #isClip()} instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.here.xyz.models.geojson.coordinates.BBox;
import com.here.xyz.models.geojson.coordinates.JTSHelper;
import com.here.xyz.models.geojson.exceptions.InvalidGeometryException;

import java.util.HashSet;
import java.util.List;

/**
Expand Down Expand Up @@ -189,8 +191,17 @@ public static void validateLinearRingCoordinates(final Object raw, boolean isExt
// reject Polygons that do not follow the right-hand rule.
//
// --> Therefore we will not check the right-hand rule here, even while it would be possible!
HashSet<String> hset = new HashSet<String>();

for (int i = 0; i < points.size(); i++) {
final Object point = points.get(i);
String strPoint = point.toString();

if( hset.contains(strPoint) && i < points.size() - 1 )
throw new InvalidGeometryException("Invalid Point (duplicate) at index #" + i + " in the LinearRing coordinates");
else
hset.add(strPoint);

if (!(point instanceof List)) {
throw new InvalidGeometryException("Expected Point at index #" + i + " in the LinearRing coordinates");
}
Expand Down

0 comments on commit 75adb47

Please sign in to comment.