Search in sources :

Example 1 with JTSMultiPoint

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint in project geotoolkit by Geomatys.

the class FeatureFilterSpatialTest method testSpatialFilter.

/**
 * Test that we get acces attributs without knowing the namespace
 */
@Test
public void testSpatialFilter() throws Exception {
    /**
     *******************************************************************************************
     *                                                                                           *
     *                            AggregateGeoFeature                                            *
     *                                                                                           *
     ********************************************************************************************
     */
    final GenericName description = NamesExt.create("http://www.opengis.net/gml", "description");
    final GenericName name = NamesExt.create("http://www.opengis.net/gml", "name");
    final GenericName multiPointProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "multiPointProperty");
    final GenericName multiCurveProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "multiCurveProperty");
    final GenericName multiSurfaceProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "multiSurfaceProperty");
    final GenericName doubleProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "doubleProperty");
    final GenericName intRangeProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "intRangeProperty");
    final GenericName strProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "strProperty");
    final GenericName featureCode = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "featureCode");
    final GenericName id = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "id");
    FeatureTypeBuilder sftb = new FeatureTypeBuilder();
    sftb.setName(NamesExt.create("http://cite.opengeospatial.org/gmlsf", "AggregateGeoFeature"));
    sftb.addAttribute(String.class).setName(description);
    sftb.addAttribute(String.class).setName(name);
    sftb.addAttribute(MultiPoint.class).setName(multiPointProperty).setCRS(CommonCRS.WGS84.geographic());
    sftb.addAttribute(MultiLineString.class).setName(multiCurveProperty).setCRS(CommonCRS.WGS84.geographic());
    sftb.addAttribute(MultiPolygon.class).setName(multiSurfaceProperty).setCRS(CommonCRS.WGS84.geographic());
    sftb.addAttribute(Double.class).setName(doubleProperty);
    sftb.addAttribute(String.class).setName(intRangeProperty);
    sftb.addAttribute(String.class).setName(strProperty);
    sftb.addAttribute(String.class).setName(featureCode);
    sftb.addAttribute(String.class).setName(id).addRole(AttributeRole.IDENTIFIER_COMPONENT);
    final FeatureType aggregateGeoFeatureType = sftb.build();
    /**
     *******************************************************************************************
     *                            AggregateGeoFeature 1                                          *
     ********************************************************************************************
     */
    final Feature aggregateGeoFeature1 = aggregateGeoFeatureType.newInstance();
    aggregateGeoFeature1.setPropertyValue(AttributeConvention.IDENTIFIER, "f005");
    aggregateGeoFeature1.setPropertyValue(description.toString(), "description-f005");
    aggregateGeoFeature1.setPropertyValue(name.toString(), "name-f005");
    GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
    Point[] points = new Point[3];
    points[0] = factory.createPoint(new Coordinate(70.83, 29.86));
    points[1] = factory.createPoint(new Coordinate(68.87, 31.08));
    points[2] = factory.createPoint(new Coordinate(71.96, 32.19));
    aggregateGeoFeature1.setPropertyValue(multiPointProperty.toString(), factory.createMultiPoint(points));
    aggregateGeoFeature1.setPropertyValue(doubleProperty.toString(), 2012.78);
    aggregateGeoFeature1.setPropertyValue(strProperty.toString(), "Ma quande lingues coalesce...");
    aggregateGeoFeature1.setPropertyValue(featureCode.toString(), "BK030");
    aggregateGeoFeature1.setPropertyValue(id.toString(), "f005");
    /**
     *******************************************************************************************
     *                                                                                           *
     *                            EntitéGénérique                                                *
     *                                                                                           *
     ********************************************************************************************
     */
    final GenericName attributGeometrie = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "attribut.Géométrie");
    final GenericName boolProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "boolProperty");
    final GenericName str4Property = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "str4Property");
    final GenericName featureRef = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "featureRef");
    sftb = new FeatureTypeBuilder();
    sftb.setName(NamesExt.create("http://cite.opengeospatial.org/gmlsf", "EntitéGénérique"));
    sftb.addAttribute(String.class).setName(description);
    sftb.addAttribute(String.class).setName(name);
    sftb.addAttribute(Geometry.class).setName(attributGeometrie).setCRS(CommonCRS.WGS84.geographic());
    sftb.addAttribute(Boolean.class).setName(boolProperty);
    sftb.addAttribute(String.class).setName(str4Property);
    sftb.addAttribute(String.class).setName(featureRef);
    sftb.addAttribute(String.class).setName(id).addRole(AttributeRole.IDENTIFIER_COMPONENT);
    final FeatureType entiteGeneriqueType = sftb.build();
    /**
     *******************************************************************************************
     *                            EntitéGénérique 1                                              *
     ********************************************************************************************
     */
    final Feature entiteGenerique1 = entiteGeneriqueType.newInstance();
    entiteGenerique1.setPropertyValue(description.toString(), "description-f004");
    entiteGenerique1.setPropertyValue(name.toString(), "name-f004");
    Coordinate[] exteriorCoord = new Coordinate[5];
    exteriorCoord[0] = new Coordinate(60.5, 0);
    exteriorCoord[1] = new Coordinate(64, 0);
    exteriorCoord[2] = new Coordinate(64, 6.25);
    exteriorCoord[3] = new Coordinate(60.5, 6.25);
    exteriorCoord[4] = new Coordinate(60.5, 0);
    LinearRing exterior = factory.createLinearRing(exteriorCoord);
    Coordinate[] interiorCoord = new Coordinate[4];
    interiorCoord[0] = new Coordinate(61.5, 2);
    interiorCoord[1] = new Coordinate(62.5, 2);
    interiorCoord[2] = new Coordinate(62, 4);
    interiorCoord[3] = new Coordinate(61.5, 2);
    LinearRing interior = factory.createLinearRing(interiorCoord);
    LinearRing[] interiors = new LinearRing[1];
    interiors[0] = interior;
    entiteGenerique1.setPropertyValue(attributGeometrie.toString(), factory.createPolygon(exterior, interiors));
    entiteGenerique1.setPropertyValue(boolProperty.toString(), false);
    entiteGenerique1.setPropertyValue(str4Property.toString(), "abc3");
    entiteGenerique1.setPropertyValue(featureRef.toString(), "name-f003");
    entiteGenerique1.setPropertyValue(id.toString(), "f004");
    /**
     *******************************************************************************************
     *                            EntitéGénérique 2                                              *
     ********************************************************************************************
     */
    final Feature entiteGenerique2 = entiteGeneriqueType.newInstance();
    entiteGenerique2.setPropertyValue(description.toString(), "description-f007");
    entiteGenerique2.setPropertyValue(name.toString(), "name-f007");
    Coordinate[] exteriorCoord2 = new Coordinate[6];
    exteriorCoord2[0] = new Coordinate(35, 15);
    exteriorCoord2[1] = new Coordinate(40, 16);
    exteriorCoord2[2] = new Coordinate(39, 20);
    exteriorCoord2[3] = new Coordinate(37, 22.5);
    exteriorCoord2[4] = new Coordinate(36, 18);
    exteriorCoord2[5] = new Coordinate(35, 15);
    LinearRing exterior2 = factory.createLinearRing(exteriorCoord);
    Coordinate[] interiorCoord2 = new Coordinate[7];
    interiorCoord2[0] = new Coordinate(37.1, 17.5);
    interiorCoord2[1] = new Coordinate(37.2, 17.6);
    interiorCoord2[2] = new Coordinate(37.3, 17.7);
    interiorCoord2[3] = new Coordinate(37.4, 17.8);
    interiorCoord2[4] = new Coordinate(37.5, 17.9);
    interiorCoord2[5] = new Coordinate(37, 17.9);
    interiorCoord2[6] = new Coordinate(37.1, 17.5);
    LinearRing interior2 = factory.createLinearRing(interiorCoord);
    LinearRing[] interiors2 = new LinearRing[1];
    interiors2[0] = interior;
    entiteGenerique2.setPropertyValue(attributGeometrie.toString(), factory.createPolygon(exterior2, interiors2));
    entiteGenerique2.setPropertyValue(boolProperty.toString(), false);
    entiteGenerique2.setPropertyValue(str4Property.toString(), "def4");
    entiteGenerique2.setPropertyValue(id.toString(), "f007");
    /**
     *******************************************************************************************
     *                            EntitéGénérique 3                                              *
     ********************************************************************************************
     */
    final Feature entiteGenerique3 = entiteGeneriqueType.newInstance();
    entiteGenerique3.setPropertyValue(description.toString(), "description-f017");
    entiteGenerique3.setPropertyValue(name.toString(), "name-f017");
    Coordinate[] lineCoord = new Coordinate[5];
    lineCoord[0] = new Coordinate(50.174, 4.899);
    lineCoord[1] = new Coordinate(52.652, 5.466);
    lineCoord[2] = new Coordinate(53.891, 6.899);
    lineCoord[3] = new Coordinate(54.382, 7.780);
    lineCoord[4] = new Coordinate(54.982, 8.879);
    entiteGenerique3.setPropertyValue(attributGeometrie.toString(), factory.createLineString(lineCoord));
    entiteGenerique3.setPropertyValue(boolProperty.toString(), false);
    entiteGenerique3.setPropertyValue(str4Property.toString(), "qrst");
    entiteGenerique3.setPropertyValue(featureRef.toString(), "name-f015");
    entiteGenerique3.setPropertyValue(id.toString(), "f017");
    /*
         * Filter equals on aggregateGeoFeature1
         */
    CoordinateReferenceSystem crs = CommonCRS.WGS84.geographic();
    JTSMultiPoint multiPoint = new JTSMultiPoint();
    multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(70.83, 29.86), crs));
    multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(68.87, 31.08), crs));
    multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(71.96, 32.19), crs));
    BinarySpatialOperator equalsfilter = FF.equals(FF.property("{http://cite.opengeospatial.org/gmlsf}multiPointProperty"), FF.literal(multiPoint));
    boolean match = equalsfilter.test(aggregateGeoFeature1);
    assertTrue(match);
    /*
         * Filter intersects on entitiGenerique*
         */
    multiPoint = new JTSMultiPoint();
    multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(38.83, 16.22), crs));
    multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(62.07, 2.48), crs));
    BinarySpatialOperator intfilter = FF.intersects(FF.property("{http://cite.opengeospatial.org/gmlsf}attribut.Géométrie"), FF.literal(multiPoint));
    match = intfilter.test(entiteGenerique1);
    assertFalse(match);
    match = intfilter.test(entiteGenerique2);
    assertFalse(match);
    match = intfilter.test(entiteGenerique3);
    assertFalse(match);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) Point(org.locationtech.jts.geom.Point) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) Feature(org.opengis.feature.Feature) GenericName(org.opengis.util.GenericName) Coordinate(org.locationtech.jts.geom.Coordinate) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) LinearRing(org.locationtech.jts.geom.LinearRing) BinarySpatialOperator(org.opengis.filter.BinarySpatialOperator) Test(org.junit.Test)

Example 2 with JTSMultiPoint

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint in project geotoolkit by Geomatys.

the class JTSUtils method toISO.

/**
 * Creates a 19107 primitive geometry from the given JTS geometry.
 */
public static Geometry toISO(final org.locationtech.jts.geom.Geometry jtsGeom, CoordinateReferenceSystem crs) {
    if (jtsGeom == null) {
        return null;
    }
    if (crs == null) {
        // try to extract the crs from the srid
        final int srid = jtsGeom.getSRID();
        if (srid != 0) {
            final String strCRS = SRIDGenerator.toSRS(srid, SRIDGenerator.Version.V1);
            try {
                crs = CRS.forCode(strCRS);
            } catch (FactoryException ex) {
                Logger.getLogger("org.geotoolkit.geometry.isoonjts").log(Level.SEVERE, null, ex);
            }
        }
    }
    // TODO use factory finder when primitive factory and geometry factory are ready.
    // FactoryFinder.getPrimitiveFactory(hints);
    final PrimitiveFactory pf = new JTSPrimitiveFactory(crs);
    // FactoryFinder.getGeometryFactory(hints);
    final GeometryFactory gf = new JTSGeometryFactory(crs);
    if (jtsGeom instanceof org.locationtech.jts.geom.Point) {
        org.locationtech.jts.geom.Point candidate = (org.locationtech.jts.geom.Point) jtsGeom;
        DirectPosition dp = pointToDirectPosition(candidate, crs);
        return pf.createPoint(dp);
    } else if (jtsGeom instanceof org.locationtech.jts.geom.LineString) {
        org.locationtech.jts.geom.LineString candidate = (org.locationtech.jts.geom.LineString) jtsGeom;
        LineString ls = gf.createLineString(new ArrayList<Position>());
        PointArray pointList = ls.getControlPoints();
        for (int i = 0, n = candidate.getNumPoints(); i < n; i++) {
            pointList.add(coordinateToDirectPosition(candidate.getCoordinateN(i), crs));
        }
        return (JTSLineString) ls;
    } else if (jtsGeom instanceof org.locationtech.jts.geom.LinearRing) {
        return linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsGeom, crs);
    } else if (jtsGeom instanceof org.locationtech.jts.geom.Polygon) {
        org.locationtech.jts.geom.Polygon jtsPolygon = (org.locationtech.jts.geom.Polygon) jtsGeom;
        Ring externalRing = linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getExteriorRing(), crs);
        ArrayList internalRings = new ArrayList();
        for (int i = 0, n = jtsPolygon.getNumInteriorRing(); i < n; i++) {
            internalRings.add(linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getInteriorRingN(i), crs));
        }
        SurfaceBoundary boundary = pf.createSurfaceBoundary(externalRing, internalRings);
        Polygon polygon = gf.createPolygon(boundary);
        return (JTSPolygon) polygon;
    /*ArrayList<Polygon> patches = new ArrayList<Polygon>();
            patches.add(polygon);
            PolyhedralSurface result = gf.createPolyhedralSurface(patches);
            return result;*/
    } else if (jtsGeom instanceof GeometryCollection) {
        org.locationtech.jts.geom.GeometryCollection jtsCollection = (org.locationtech.jts.geom.GeometryCollection) jtsGeom;
        boolean multiPoint = jtsGeom instanceof MultiPoint;
        boolean multiCurve = jtsGeom instanceof MultiLineString;
        boolean multiSurface = jtsGeom instanceof MultiPolygon;
        // determine it by analyzing its content.
        if (!(multiPoint || multiCurve || multiSurface || jtsGeom.isEmpty())) {
            multiPoint = multiCurve = multiSurface = true;
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n && (multiPoint || multiCurve || multiSurface); i++) {
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Point)) {
                    multiPoint = false;
                }
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.LineString)) {
                    multiCurve = false;
                }
                if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Polygon)) {
                    multiSurface = false;
                }
            }
        }
        AbstractJTSAggregate result;
        if (multiPoint) {
            result = new JTSMultiPoint(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        } else if (multiCurve) {
            result = new JTSMultiCurve(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                Geometry element = toISO(jtsCollection.getGeometryN(i), crs);
                if (element instanceof JTSLineString) {
                    JTSCurve curve = new JTSCurve(crs);
                    curve.getSegments().add((JTSLineString) element);
                    element = curve;
                }
                elements.add(element);
            }
        } else if (multiSurface) {
            result = new JTSMultiSurface(crs);
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        } else {
            result = new JTSMultiPrimitive();
            Set elements = result.getElements();
            for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
                // result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
                elements.add(toISO(jtsCollection.getGeometryN(i), crs));
            }
        }
        return result;
    } else {
        throw new IllegalArgumentException("Unsupported geometry type: " + jtsGeom.getGeometryType());
    }
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) MultiLineString(org.locationtech.jts.geom.MultiLineString) GeometryFactory(org.opengis.geometry.coordinate.GeometryFactory) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) Set(java.util.Set) FactoryException(org.opengis.util.FactoryException) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) ArrayList(java.util.ArrayList) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) LineString(org.opengis.geometry.coordinate.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) JTSMultiCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) JTSPolygon(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon) Polygon(org.opengis.geometry.coordinate.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) AbstractJTSAggregate(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.AbstractJTSAggregate) JTSGeometryFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSGeometryFactory) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) JTSMultiSurface(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiSurface) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) JTSPrimitiveFactory(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory) PrimitiveFactory(org.opengis.geometry.primitive.PrimitiveFactory) PointArray(org.opengis.geometry.coordinate.PointArray) MultiPoint(org.locationtech.jts.geom.MultiPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSMultiPrimitive(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPrimitive) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Geometry(org.opengis.geometry.Geometry) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString) LineString(org.opengis.geometry.coordinate.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Ring(org.opengis.geometry.primitive.Ring)

Example 3 with JTSMultiPoint

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint in project geotoolkit by Geomatys.

the class ISOGeomTest method hello.

@Test
public void hello() throws NoSuchAuthorityCodeException, FactoryException {
    GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
    Point[] points = new Point[3];
    points[0] = factory.createPoint(new Coordinate(70.83, 29.86));
    points[1] = factory.createPoint(new Coordinate(68.87, 31.08));
    points[2] = factory.createPoint(new Coordinate(71.96, 32.19));
    Geometry jtsGeom = factory.createMultiPoint(points);
    CoordinateReferenceSystem crs = CommonCRS.WGS84.geographic();
    JTSMultiPoint isoGeom = new JTSMultiPoint();
    isoGeom.getElements().add(new JTSPoint(new GeneralDirectPosition(70.83, 29.86), crs));
    isoGeom.getElements().add(new JTSPoint(new GeneralDirectPosition(68.87, 31.08), crs));
    isoGeom.getElements().add(new JTSPoint(new GeneralDirectPosition(71.96, 32.19), crs));
    BinarySpatialOperator<Object> filter = FF.equals(FF.literal(jtsGeom), FF.literal(isoGeom));
    boolean match = filter.test(null);
    assertTrue(match);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) Point(org.locationtech.jts.geom.Point) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 4 with JTSMultiPoint

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method MultiPointUnmarshalingTest.

/**
 * Test multiPoint Marshalling.
 */
@Test
public void MultiPointUnmarshalingTest() throws Exception {
    CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
    assertTrue(crs != null);
    DirectPosition p1 = new GeneralDirectPosition(crs);
    p1.setOrdinate(0, 402000);
    p1.setOrdinate(1, 3334850);
    JTSPoint pt1 = new JTSPoint(p1);
    DirectPosition p2 = new GeneralDirectPosition(crs);
    p2.setOrdinate(0, 402200);
    p2.setOrdinate(1, 3335200);
    JTSPoint pt2 = new JTSPoint(p2);
    JTSMultiPoint expResult = new JTSMultiPoint(crs);
    expResult.getElements().add(pt1);
    expResult.getElements().add(pt2);
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiPoint srsName=\"urn:ogc:def:crs:epsg::27572\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + "  <gml:pointMember>" + '\n' + "    <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "    </gml:Point>" + '\n' + "  </gml:pointMember>" + '\n' + "  <gml:pointMember>" + '\n' + "    <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + "    </gml:Point>" + '\n' + "  </gml:pointMember>" + '\n' + "</gml:MultiPoint>" + '\n';
    JTSMultiPoint result = (JTSMultiPoint) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
    assertEquals(expResult, result);
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) StringReader(java.io.StringReader) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Example 5 with JTSMultiPoint

use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method MultiPointMarshalingTest.

/**
 * Test multiPoint Marshalling.
 */
@Test
public void MultiPointMarshalingTest() throws Exception {
    CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
    assertTrue(crs != null);
    DirectPosition p1 = new GeneralDirectPosition(crs);
    p1.setOrdinate(0, 402000);
    p1.setOrdinate(1, 3334850);
    JTSPoint pt1 = new JTSPoint(p1);
    DirectPosition p2 = new GeneralDirectPosition(crs);
    p2.setOrdinate(0, 402200);
    p2.setOrdinate(1, 3335200);
    JTSPoint pt2 = new JTSPoint(p2);
    JTSMultiPoint multiPoint = new JTSMultiPoint(crs);
    multiPoint.getElements().add(pt1);
    multiPoint.getElements().add(pt2);
    StringWriter sw = new StringWriter();
    m.marshal(factory.createJTSMultiPoint(multiPoint), sw);
    String result = sw.toString();
    result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
    String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiPoint xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::27572\" >" + '\n' + "  <gml:pointMember>" + '\n' + "    <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + "    </gml:Point>" + '\n' + "  </gml:pointMember>" + '\n' + "  <gml:pointMember>" + '\n' + "    <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + "      <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + "    </gml:Point>" + '\n' + "  </gml:pointMember>" + '\n' + "</gml:MultiPoint>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) StringWriter(java.io.StringWriter) JTSPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint) JTSMultiPoint(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Aggregations

GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)5 JTSMultiPoint (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPoint)5 JTSPoint (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)3 DirectPosition (org.opengis.geometry.DirectPosition)3 Test (org.junit.Test)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2 MultiPoint (org.locationtech.jts.geom.MultiPoint)2 Point (org.locationtech.jts.geom.Point)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 AbstractJTSAggregate (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.AbstractJTSAggregate)1 JTSMultiCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiCurve)1 JTSMultiPrimitive (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.aggregate.JTSMultiPrimitive)1