Search in sources :

Example 1 with RepeatedPointTester

use of org.locationtech.jts.operation.valid.RepeatedPointTester in project ARLAS-server by gisaia.

the class ParamsParser method getValidWKT.

public static Geometry getValidWKT(String wktString) throws InvalidParameterException {
    GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
    Envelope affectedBounds = new Envelope(-360, 360, -180, 180);
    WKTReader wkt = new WKTReader(geometryFactory);
    Geometry geom;
    try {
        geom = wkt.read(wktString);
        List<Coordinate> filteredCoord = Arrays.stream(geom.getCoordinates()).filter(coordinate -> affectedBounds.contains(coordinate)).collect(Collectors.toList());
        if (filteredCoord.size() != geom.getCoordinates().length) {
            throw new InvalidParameterException("Coordinates must be contained in the Envelope -360, 360, -180, 180");
        }
        RepeatedPointTester tester = new RepeatedPointTester();
        for (int i = 0; i < geom.getNumGeometries(); i++) {
            IsValidOp validOp = new IsValidOp(geom.getGeometryN(i));
            TopologyValidationError err = validOp.getValidationError();
            if (err != null) {
                throw new InvalidParameterException(GeoUtil.INVALID_WKT + ": " + err.getMessage());
            }
            if (tester.hasRepeatedPoint(geom.getGeometryN(i))) {
                throw new InvalidParameterException(GeoUtil.INVALID_WKT + ": duplicate consecutive points detected in " + geom.getGeometryN(i).toText());
            }
        }
    } catch (org.locationtech.jts.io.ParseException ex) {
        throw new InvalidParameterException("Invalid WKT: " + ex.getMessage());
    }
    return geom;
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) WKTReader(org.locationtech.jts.io.WKTReader) StringUtils(org.apache.commons.lang3.StringUtils) GEO_AGGREGATION_TYPE_ENUMS(io.arlas.server.core.utils.CheckParams.GEO_AGGREGATION_TYPE_ENUMS) RepeatedPointTester(org.locationtech.jts.operation.valid.RepeatedPointTester) ArlasException(io.arlas.server.core.exceptions.ArlasException) Matcher(java.util.regex.Matcher) Pair(org.apache.commons.lang3.tuple.Pair) InvalidParameterException(io.arlas.server.core.exceptions.InvalidParameterException) IntParam(io.dropwizard.jersey.params.IntParam) GeoPoint(org.elasticsearch.common.geo.GeoPoint) CollectionReferenceManager(io.arlas.server.core.managers.CollectionReferenceManager) org.locationtech.jts.geom(org.locationtech.jts.geom) BadRequestException(io.arlas.server.core.exceptions.BadRequestException) DateTimeFormat(org.joda.time.format.DateTimeFormat) CollectionReference(io.arlas.server.core.model.CollectionReference) io.arlas.server.core.model.request(io.arlas.server.core.model.request) FieldType(io.arlas.server.core.model.response.FieldType) IsValidOp(org.locationtech.jts.operation.valid.IsValidOp) TopologyValidationError(org.locationtech.jts.operation.valid.TopologyValidationError) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) DateTimeParseException(java.time.format.DateTimeParseException) Orientation(org.locationtech.jts.algorithm.Orientation) Pattern(java.util.regex.Pattern) FluidSearchService(io.arlas.server.core.services.FluidSearchService) io.arlas.server.core.model.enumerations(io.arlas.server.core.model.enumerations) WKTReader(org.locationtech.jts.io.WKTReader) GeoPoint(org.elasticsearch.common.geo.GeoPoint) InvalidParameterException(io.arlas.server.core.exceptions.InvalidParameterException) IsValidOp(org.locationtech.jts.operation.valid.IsValidOp) TopologyValidationError(org.locationtech.jts.operation.valid.TopologyValidationError) RepeatedPointTester(org.locationtech.jts.operation.valid.RepeatedPointTester)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArlasException (io.arlas.server.core.exceptions.ArlasException)1 BadRequestException (io.arlas.server.core.exceptions.BadRequestException)1 InvalidParameterException (io.arlas.server.core.exceptions.InvalidParameterException)1 CollectionReferenceManager (io.arlas.server.core.managers.CollectionReferenceManager)1 CollectionReference (io.arlas.server.core.model.CollectionReference)1 io.arlas.server.core.model.enumerations (io.arlas.server.core.model.enumerations)1 io.arlas.server.core.model.request (io.arlas.server.core.model.request)1 FieldType (io.arlas.server.core.model.response.FieldType)1 FluidSearchService (io.arlas.server.core.services.FluidSearchService)1 GEO_AGGREGATION_TYPE_ENUMS (io.arlas.server.core.utils.CheckParams.GEO_AGGREGATION_TYPE_ENUMS)1 IntParam (io.dropwizard.jersey.params.IntParam)1 IOException (java.io.IOException)1 DateTimeParseException (java.time.format.DateTimeParseException)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 StringUtils (org.apache.commons.lang3.StringUtils)1