Search in sources :

Example 1 with LengthType

use of org.geotoolkit.gml.xml.v321.LengthType in project geotoolkit by Geomatys.

the class GeometrytoJTSTest method gmlArcToJTSTest.

@Test
public void gmlArcToJTSTest() throws Exception {
    final LengthType radius = new LengthType();
    radius.setValue(2.0);
    radius.setUom("m");
    final AngleType startAngle = new AngleType();
    startAngle.setValue(0);
    startAngle.setUom("rad");
    final AngleType endAngle = new AngleType();
    endAngle.setValue(270);
    endAngle.setUom("°");
    final ArcByCenterPointType arc = new ArcByCenterPointType();
    arc.setStartAngle(startAngle);
    arc.setEndAngle(endAngle);
    arc.setRadius(radius);
    arc.setPointProperty(new PointPropertyType(new PointType(new DirectPosition2D(0, 0))));
    final CurveType gmlCurve = new CurveType();
    gmlCurve.setSrsName("EPSG:3857");
    gmlCurve.setSegments(new CurveSegmentArrayPropertyType(Collections.singletonList(arc)));
    Geometry geom = GeometrytoJTS.toJTS(gmlCurve);
    // For geometric comparison, we oppose pure jts solution to the SIS geodetic calculator.
    final GeometricShapeFactory f = new GeometricShapeFactory(GF);
    f.setCentre(new Coordinate(0, 0));
    f.setSize(radius.getValue() * 2);
    // with this value, we should get points on trigonometric circle cardinalities (0, PI/2, PI, etc.), which eases comparison in debug.
    f.setNumPoints(17);
    // JTS angles are not azimuth, but pure trigonometric
    Geometry expectedArc = f.createArc(Math.PI, 3 / 2.0 * Math.PI);
    Assert.assertTrue(expectedArc.buffer(0.2).contains(geom));
    // Now, test in reverse (counter-clockwise) order
    endAngle.setValue(-90);
    geom = GeometrytoJTS.toJTS(gmlCurve);
    expectedArc = f.createArc(0, Math.PI);
    Assert.assertTrue(expectedArc.buffer(0.2).contains(geom));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) CurveSegmentArrayPropertyType(org.geotoolkit.gml.xml.v321.CurveSegmentArrayPropertyType) GeometricShapeFactory(org.locationtech.jts.util.GeometricShapeFactory) LengthType(org.geotoolkit.gml.xml.v321.LengthType) ArcByCenterPointType(org.geotoolkit.gml.xml.v321.ArcByCenterPointType) CurveType(org.geotoolkit.gml.xml.v321.CurveType) Coordinate(org.locationtech.jts.geom.Coordinate) AngleType(org.geotoolkit.gml.xml.v321.AngleType) PointType(org.geotoolkit.gml.xml.v321.PointType) ArcByCenterPointType(org.geotoolkit.gml.xml.v321.ArcByCenterPointType) PointPropertyType(org.geotoolkit.gml.xml.v321.PointPropertyType) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test)

Example 2 with LengthType

use of org.geotoolkit.gml.xml.v321.LengthType in project ARLAS-server by gisaia.

the class MDMetadataBuilder method addSpatialResolution.

// TODO : spatial resolution Object
public static void addSpatialResolution(MDDataIdentificationType mdDataIdentificationType, InspireSpatialResolution spatialResolution) {
    MDResolutionPropertyType mdResolutionPropertyType = new MDResolutionPropertyType();
    MDResolutionType mdResolutionType = new MDResolutionType();
    // An equivalent scale is generally expressed as an integer value expressing the scale denominator.
    if (spatialResolution.unitOfMeasure == null || spatialResolution.unitOfMeasure.equals("")) {
        // in this case, it's an equivalent scale
        MDRepresentativeFractionPropertyType representativeFractionPropertyType = new MDRepresentativeFractionPropertyType();
        MDRepresentativeFractionType representativeFractionType = new MDRepresentativeFractionType();
        IntegerPropertyType integerPropertyType = new IntegerPropertyType();
        integerPropertyType.setInteger(BigInteger.valueOf(spatialResolution.value.intValue()));
        representativeFractionType.setDenominator(integerPropertyType);
        representativeFractionPropertyType.setMDRepresentativeFraction(representativeFractionType);
        mdResolutionType.setEquivalentScale(representativeFractionPropertyType);
    } else {
        DistancePropertyType distancePropertyType = new DistancePropertyType();
        LengthType distance = new LengthType();
        distance.setValue(spatialResolution.value.doubleValue());
        distance.setUom(spatialResolution.unitOfMeasure);
        distancePropertyType.setDistance(distance);
        mdResolutionType.setDistance(distancePropertyType);
    }
    mdDataIdentificationType.getSpatialResolution().add(mdResolutionPropertyType);
}
Also used : LengthType(net.opengis.gml._3.LengthType)

Aggregations

LengthType (net.opengis.gml._3.LengthType)1 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)1 AngleType (org.geotoolkit.gml.xml.v321.AngleType)1 ArcByCenterPointType (org.geotoolkit.gml.xml.v321.ArcByCenterPointType)1 CurveSegmentArrayPropertyType (org.geotoolkit.gml.xml.v321.CurveSegmentArrayPropertyType)1 CurveType (org.geotoolkit.gml.xml.v321.CurveType)1 LengthType (org.geotoolkit.gml.xml.v321.LengthType)1 PointPropertyType (org.geotoolkit.gml.xml.v321.PointPropertyType)1 PointType (org.geotoolkit.gml.xml.v321.PointType)1 Test (org.junit.Test)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 Geometry (org.locationtech.jts.geom.Geometry)1 GeometricShapeFactory (org.locationtech.jts.util.GeometricShapeFactory)1