Search in sources :

Example 16 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project geotoolkit by Geomatys.

the class ShapeType method equals.

/**
 * Verify if this entry is identical to specified object.
 */
@Override
public boolean equals(final Object object) {
    if (object == this) {
        return true;
    }
    if (object instanceof ShapeType) {
        final ShapeType that = (ShapeType) object;
        AbstractGeometryType thatgeom = null;
        if (that.abstractGeometry != null) {
            thatgeom = that.abstractGeometry.getValue();
        }
        AbstractGeometryType thisgeom = null;
        if (this.abstractGeometry != null) {
            thisgeom = this.abstractGeometry.getValue();
        }
        return Objects.equals(thisgeom, thatgeom) && Objects.equals(this.actuate, that.actuate) && Objects.equals(this.href, that.href) && Objects.equals(this.remoteSchema, that.remoteSchema) && Objects.equals(this.role, that.role) && Objects.equals(this.show, that.show) && Objects.equals(this.nilReason, that.nilReason) && Objects.equals(this.type, that.type) && Objects.equals(this.arcrole, that.arcrole);
    }
    return false;
}
Also used : AbstractGeometryType(org.geotoolkit.gml.xml.v321.AbstractGeometryType)

Example 17 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project geotoolkit by Geomatys.

the class OGC110toGTTransformer method visitSpatialOp.

/**
 * Transform a SLD spatial Filter v1.1 in GT filter.
 */
public Filter visitSpatialOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v110.SpatialOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
    final org.geotoolkit.ogc.xml.v110.SpatialOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v110.BinarySpatialOpType) {
        final org.geotoolkit.ogc.xml.v110.BinarySpatialOpType binary = (org.geotoolkit.ogc.xml.v110.BinarySpatialOpType) ops;
        final JAXBElement<? extends AbstractGeometryType> geom = binary.getAbstractGeometry();
        final JAXBElement<EnvelopeType> env = binary.getEnvelope();
        final org.geotoolkit.ogc.xml.v110.PropertyNameType pnt = binary.getPropertyName().getValue();
        final Expression left = visitPropertyName(pnt);
        final Expression right;
        if (env != null && env.getValue() != null) {
            try {
                right = visitEnv(env);
            } catch (FactoryException ex) {
                throw new IllegalArgumentException("SRS name is unknowned : " + ex.getLocalizedMessage(), ex);
            }
        } else {
            right = visit(geom);
        }
        if (OGCJAXBStatics.FILTER_SPATIAL_CONTAINS.equalsIgnoreCase(OpName)) {
            return filterFactory.contains(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_CROSSES.equalsIgnoreCase(OpName)) {
            return filterFactory.crosses(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_DISJOINT.equalsIgnoreCase(OpName)) {
            return filterFactory.disjoint(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_EQUALS.equalsIgnoreCase(OpName)) {
            return filterFactory.equals(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_INTERSECTS.equalsIgnoreCase(OpName)) {
            return filterFactory.intersects(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_OVERLAPS.equalsIgnoreCase(OpName)) {
            return filterFactory.overlaps(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_TOUCHES.equalsIgnoreCase(OpName)) {
            return filterFactory.touches(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_WITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.within(left, right);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.DistanceBufferType) {
        final org.geotoolkit.ogc.xml.v110.DistanceBufferType dstOp = (org.geotoolkit.ogc.xml.v110.DistanceBufferType) ops;
        final org.geotoolkit.ogc.xml.v110.DistanceType dt = dstOp.getDistanceType();
        final JAXBElement<? extends AbstractGeometryType> geom = dstOp.getAbstractGeometry();
        final org.geotoolkit.ogc.xml.v110.PropertyNameType pnt = dstOp.getPropertyName();
        final Expression geom1 = visitPropertyName(pnt);
        final Expression geom2 = visit(geom);
        // TODO marche pas ? ou est la distance ? Double.valueOf(dt.getContent());
        final double distance = 0;
        final String units = dt.getUnits();
        if (OGCJAXBStatics.FILTER_SPATIAL_DWITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.dwithin(geom1, geom2, distance, units);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_BEYOND.equalsIgnoreCase(OpName)) {
            return filterFactory.beyond(geom1, geom2, distance, units);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v110.BBOXType) {
        final org.geotoolkit.ogc.xml.v110.BBOXType binary = (org.geotoolkit.ogc.xml.v110.BBOXType) ops;
        final EnvelopeType box = binary.getEnvelope();
        final String pnt = binary.getPropertyName();
        final Expression geom;
        if (pnt != null) {
            geom = visitPropertyName(pnt);
        } else {
            geom = null;
        }
        final double minx = box.getLowerCorner().getOrdinate(0);
        final double maxx = box.getUpperCorner().getOrdinate(0);
        final double miny = box.getLowerCorner().getOrdinate(1);
        final double maxy = box.getUpperCorner().getOrdinate(1);
        // final double minx = box.getPos().get(0).getOrdinate(0);
        // final double maxx = box.getPos().get(0).getOrdinate(1);
        // final double miny = box.getPos().get(1).getOrdinate(0);
        // final double maxy = box.getPos().get(1).getOrdinate(1);
        final String srs = box.getSrsName();
        if (OGCJAXBStatics.FILTER_SPATIAL_BBOX.equalsIgnoreCase(OpName)) {
            return filterFactory.bbox(geom, minx, miny, maxx, maxy, srs);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : FactoryException(org.opengis.util.FactoryException) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) SpatialOpsType(org.geotoolkit.ogc.xml.v110.SpatialOpsType) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) AbstractGeometryType(org.geotoolkit.gml.xml.v311.AbstractGeometryType) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression)

Example 18 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project geotoolkit by Geomatys.

the class OGC200toGTTransformer method visitSpatialOp.

/**
 * Transform a SLD spatial Filter v1.1 in GT filter.
 */
public Filter visitSpatialOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v200.SpatialOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
    final org.geotoolkit.ogc.xml.v200.SpatialOpsType ops = jax.getValue();
    final String OpName = jax.getName().getLocalPart();
    if (ops instanceof org.geotoolkit.ogc.xml.v200.BinarySpatialOpType) {
        final org.geotoolkit.ogc.xml.v200.BinarySpatialOpType binary = (org.geotoolkit.ogc.xml.v200.BinarySpatialOpType) ops;
        Object geom = binary.getAny();
        if (geom instanceof JAXBElement) {
            geom = ((JAXBElement) geom).getValue();
        }
        final Expression left = visitPropertyName(binary.getValueReference());
        final Expression right;
        if (geom instanceof EnvelopeType) {
            try {
                right = visitEnv((EnvelopeType) geom);
            } catch (FactoryException ex) {
                throw new IllegalArgumentException("SRS name is unknowned : " + ex.getLocalizedMessage(), ex);
            }
        } else if (geom instanceof AbstractGeometryType) {
            right = visit((AbstractGeometryType) geom);
        } else {
            throw new IllegalArgumentException("Unexpected geometry type:" + geom);
        }
        if (OGCJAXBStatics.FILTER_SPATIAL_CONTAINS.equalsIgnoreCase(OpName)) {
            return filterFactory.contains(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_CROSSES.equalsIgnoreCase(OpName)) {
            return filterFactory.crosses(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_DISJOINT.equalsIgnoreCase(OpName)) {
            return filterFactory.disjoint(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_EQUALS.equalsIgnoreCase(OpName)) {
            return filterFactory.equals(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_INTERSECTS.equalsIgnoreCase(OpName)) {
            return filterFactory.intersects(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_OVERLAPS.equalsIgnoreCase(OpName)) {
            return filterFactory.overlaps(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_TOUCHES.equalsIgnoreCase(OpName)) {
            return filterFactory.touches(left, right);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_WITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.within(left, right);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.DistanceBufferType) {
        final org.geotoolkit.ogc.xml.v200.DistanceBufferType dstOp = (org.geotoolkit.ogc.xml.v200.DistanceBufferType) ops;
        final org.geotoolkit.ogc.xml.v200.MeasureType dt = dstOp.getDistanceType();
        Object opAny = dstOp.getAny();
        if (opAny instanceof JAXBElement) {
            opAny = ((JAXBElement) opAny).getValue();
        }
        if (!(opAny instanceof AbstractGeometryType)) {
            throw new IllegalArgumentException("geometry type is unexpected:" + opAny);
        }
        final AbstractGeometryType geom = (AbstractGeometryType) opAny;
        final String pnt = dstOp.getPropertyName();
        final Expression geom1 = visitPropertyName(pnt);
        final Expression geom2 = visit(geom);
        // TODO marche pas ? ou est la distance ? Double.valueOf(dt.getContent());
        final double distance = 0;
        final String units = dt.getUom();
        if (OGCJAXBStatics.FILTER_SPATIAL_DWITHIN.equalsIgnoreCase(OpName)) {
            return filterFactory.dwithin(geom1, geom2, distance, units);
        } else if (OGCJAXBStatics.FILTER_SPATIAL_BEYOND.equalsIgnoreCase(OpName)) {
            return filterFactory.beyond(geom1, geom2, distance, units);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    } else if (ops instanceof org.geotoolkit.ogc.xml.v200.BBOXType) {
        final org.geotoolkit.ogc.xml.v200.BBOXType binary = (org.geotoolkit.ogc.xml.v200.BBOXType) ops;
        Object binAny = binary.getAny();
        if (binAny instanceof JAXBElement) {
            binAny = ((JAXBElement) binAny).getValue();
        }
        if (!(binAny instanceof EnvelopeType)) {
            throw new IllegalArgumentException("geometry type is unexpected:" + binAny);
        }
        final EnvelopeType box = (EnvelopeType) binAny;
        final String pnt = binary.getPropertyName();
        final Expression geom;
        if (pnt != null) {
            geom = visitPropertyName(pnt);
        } else {
            geom = null;
        }
        final double minx = box.getLowerCorner().getOrdinate(0);
        final double maxx = box.getUpperCorner().getOrdinate(0);
        final double miny = box.getLowerCorner().getOrdinate(1);
        final double maxy = box.getUpperCorner().getOrdinate(1);
        final String srs = box.getSrsName();
        if (OGCJAXBStatics.FILTER_SPATIAL_BBOX.equalsIgnoreCase(OpName)) {
            return filterFactory.bbox(geom, minx, miny, maxx, maxy, srs);
        }
        throw new IllegalArgumentException("Illegal filter element" + OpName + " : " + ops);
    }
    throw new IllegalArgumentException("Unknowed filter element" + jax);
}
Also used : EnvelopeType(org.geotoolkit.gml.xml.v321.EnvelopeType) FactoryException(org.opengis.util.FactoryException) AbstractGeometryType(org.geotoolkit.gml.xml.v321.AbstractGeometryType) org.geotoolkit.ogc.xml.v200(org.geotoolkit.ogc.xml.v200) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression)

Example 19 with AbstractGeometryType

use of org.geotoolkit.kml.xml.v220.AbstractGeometryType in project geotoolkit by Geomatys.

the class KMLStore method convert.

private static Geometry convert(Object geomType) throws DataStoreException {
    if (geomType instanceof JAXBElement)
        geomType = ((JAXBElement) geomType).getValue();
    Geometry geom = null;
    if (geomType instanceof ModelType) {
        final ModelType modelType = (ModelType) geomType;
        final LocationType location = modelType.getLocation();
        geom = GF.createPoint(new Coordinate(location.getLongitude(), location.getLatitude()));
    } else if (geomType instanceof PointType) {
        final PointType pointType = (PointType) geomType;
        final List<String> coordinates = pointType.getCoordinates();
        geom = GF.createPoint(toCoordinates(coordinates, 1, false));
    } else if (geomType instanceof PolygonType) {
        final PolygonType polygonType = (PolygonType) geomType;
        final CoordinateSequence outter = toCoordinates(polygonType.getOuterBoundaryIs().getLinearRing().getCoordinates(), 3, true);
        final List<BoundaryType> inners = polygonType.getInnerBoundaryIs();
        final LinearRing[] holes = new LinearRing[inners.size()];
        for (int i = 0; i < holes.length; i++) {
            holes[i] = GF.createLinearRing(toCoordinates(inners.get(i).getLinearRing().getCoordinates(), 3, true));
        }
        geom = GF.createPolygon(GF.createLinearRing(outter), holes);
    } else if (geomType instanceof LinearRingType) {
        final LinearRingType linearRingType = (LinearRingType) geomType;
        geom = GF.createLineString(toCoordinates(linearRingType.getCoordinates(), 3, true));
    } else if (geomType instanceof MultiGeometryType) {
        final MultiGeometryType multigeometryType = (MultiGeometryType) geomType;
        final List<JAXBElement<? extends AbstractGeometryType>> children = multigeometryType.getAbstractGeometryGroup();
        final Geometry[] childs = new Geometry[children.size()];
        for (int i = 0; i < childs.length; i++) {
            childs[i] = convert(children.get(i));
        }
        geom = GF.createGeometryCollection(childs);
    } else if (geomType instanceof LineStringType) {
        final LineStringType lineStringType = (LineStringType) geomType;
        geom = GF.createLineString(toCoordinates(lineStringType.getCoordinates(), 2, false));
    }
    if (geom != null) {
        JTS.setCRS(geom, CRS);
    }
    return geom;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) PackedCoordinateSequence(org.locationtech.jts.geom.impl.PackedCoordinateSequence) AbstractGeometryType(org.geotoolkit.kml.xml.v220.AbstractGeometryType) LinearRingType(org.geotoolkit.kml.xml.v220.LinearRingType) MultiGeometryType(org.geotoolkit.kml.xml.v220.MultiGeometryType) PolygonType(org.geotoolkit.kml.xml.v220.PolygonType) JAXBElement(javax.xml.bind.JAXBElement) LineStringType(org.geotoolkit.kml.xml.v220.LineStringType) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) ModelType(org.geotoolkit.kml.xml.v220.ModelType) PointType(org.geotoolkit.kml.xml.v220.PointType) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) LinearRing(org.locationtech.jts.geom.LinearRing) LocationType(org.geotoolkit.kml.xml.v220.LocationType) BoundaryType(org.geotoolkit.kml.xml.v220.BoundaryType)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)8 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)7 Geometry (org.locationtech.jts.geom.Geometry)5 AbstractGeometryType (org.geotoolkit.gml.xml.v311.AbstractGeometryType)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)2 QName (javax.xml.namespace.QName)2 AbstractGeometryType (net.opengis.gml.x32.AbstractGeometryType)2 GeometryPropertyType (net.opengis.gml.x32.GeometryPropertyType)2 CurveType (org.geotoolkit.gml.xml.v311.CurveType)2 LineStringType (org.geotoolkit.gml.xml.v311.LineStringType)2 MultiCurveType (org.geotoolkit.gml.xml.v311.MultiCurveType)2 MultiGeometryType (org.geotoolkit.gml.xml.v311.MultiGeometryType)2 MultiPointType (org.geotoolkit.gml.xml.v311.MultiPointType)2 MultiPolygonType (org.geotoolkit.gml.xml.v311.MultiPolygonType)2 PointType (org.geotoolkit.gml.xml.v311.PointType)2 PolygonType (org.geotoolkit.gml.xml.v311.PolygonType)2 PolyhedralSurfaceType (org.geotoolkit.gml.xml.v311.PolyhedralSurfaceType)2 AbstractGeometryType (org.geotoolkit.gml.xml.v321.AbstractGeometryType)2