use of org.geotoolkit.gml.xml.v311.PointPropertyType in project arctic-sea by 52North.
the class PointPropertyTypeEncoder method encode.
@Override
public PointPropertyType encode(Point point, EncodingContext ec) throws EncodingException {
PointPropertyType ppt = PointPropertyType.Factory.newInstance();
ppt.setPoint(encodePointType(point, ec));
return ppt;
}
use of org.geotoolkit.gml.xml.v311.PointPropertyType in project geotoolkit by Geomatys.
the class JAXPStreamFeatureWriter method setId.
/**
* @param inc auto increment value, ids must be unique
*/
private void setId(AbstractGeometry gmlGeometry, String id) {
if (gmlGeometry.getId() == null || gmlGeometry.getId().isEmpty()) {
// do not override ids if they exist
gmlGeometry.setId(id + (gidInc));
gidInc++;
}
if (gmlGeometry instanceof MultiCurve) {
for (CurveProperty po : ((MultiCurve) gmlGeometry).getCurveMember()) {
final AbstractCurve child = po.getAbstractCurve();
if (child instanceof AbstractGeometry) {
setId((AbstractGeometry) child, id);
}
}
} else if (gmlGeometry instanceof MultiSurface) {
for (SurfaceProperty po : ((MultiSurface) gmlGeometry).getSurfaceMember()) {
final AbstractSurface child = po.getAbstractSurface();
if (child instanceof AbstractGeometry) {
setId((AbstractGeometry) child, id);
}
}
} else if (gmlGeometry instanceof MultiGeometryType) {
for (GeometryPropertyType po : ((MultiGeometryType) gmlGeometry).getGeometryMember()) {
final AbstractGeometryType child = po.getAbstractGeometry();
if (child instanceof AbstractGeometry) {
setId((AbstractGeometry) child, id);
}
}
} else if (gmlGeometry instanceof MultiSolidType) {
for (SolidPropertyType po : ((MultiSolidType) gmlGeometry).getSolidMember()) {
final AbstractSolidType child = po.getAbstractSolid().getValue();
if (child instanceof AbstractGeometry) {
setId((AbstractGeometry) child, id);
}
}
} else if (gmlGeometry instanceof MultiPointType) {
for (PointPropertyType po : ((MultiPointType) gmlGeometry).getPointMember()) {
final PointType child = po.getPoint();
if (child instanceof AbstractGeometry) {
setId((AbstractGeometry) child, id);
}
}
}
}
use of org.geotoolkit.gml.xml.v311.PointPropertyType 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));
}
use of org.geotoolkit.gml.xml.v311.PointPropertyType in project geotoolkit by Geomatys.
the class GMLUtilities method getGMLFromISO.
/**
* @param geometry The ISO geometry to convert.
* @return A GML 3.1.1 geometry matching given geometry definition.
* @deprecated This method should not be used for multiple reasons:
* <ol>
* <li>OpenGIS definition is based on an obsolete ISO-19107 draft</li>
* <li>The GML version is fixed and obsolete</li>
* <li>Only partial management of geometries</li>
* </ol>
*/
public static AbstractGeometryType getGMLFromISO(final org.opengis.geometry.Geometry geometry) {
if (geometry instanceof Point) {
Point point = (Point) geometry;
PointType gmlPoint = new PointType(null, point.getDirectPosition());
return gmlPoint;
} else if (geometry instanceof OrientableSurface) {
OrientableSurface surface = (OrientableSurface) geometry;
SurfaceBoundary boundary = surface.getBoundary();
Ring exterior = boundary.getExterior();
List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
for (Primitive p : exterior.getElements()) {
curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlExterior = new RingType();
gmlExterior.getCurveMember().addAll(curves);
List<Ring> interiors = boundary.getInteriors();
List<RingType> gmlInteriors = new ArrayList<RingType>();
for (Ring interior : interiors) {
List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
for (Primitive p : interior.getElements()) {
intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlinterior = new RingType();
gmlinterior.getCurveMember().addAll(intcurves);
gmlInteriors.add(gmlinterior);
}
PolygonType poly = new PolygonType(gmlExterior, gmlInteriors);
return poly;
} else if (geometry instanceof MultiSurface) {
MultiSurface multiPrim = (MultiSurface) geometry;
List<PolygonPropertyType> geometries = new ArrayList<PolygonPropertyType>();
for (Geometry prim : multiPrim.getElements()) {
PolygonType element = (PolygonType) getGMLFromISO(prim);
PolygonPropertyType gp = new PolygonPropertyType((PolygonType) element);
geometries.add(gp);
}
MultiPolygonType gmlMulti = new MultiPolygonType(null, geometries);
return gmlMulti;
} else if (geometry instanceof MultiCurve) {
MultiCurve multiPrim = (MultiCurve) geometry;
List<CurvePropertyType> geometries = new ArrayList<CurvePropertyType>();
for (OrientableCurve prim : multiPrim.getElements()) {
AbstractCurveType element = (AbstractCurveType) getGMLFromISO(prim);
CurvePropertyType gp = new CurvePropertyType((AbstractCurveType) element);
geometries.add(gp);
}
MultiCurveType gmlMulti = new MultiCurveType(geometries);
return gmlMulti;
} else if (geometry instanceof MultiPoint) {
MultiPoint multiPrim = (MultiPoint) geometry;
List<PointPropertyType> geometries = new ArrayList<PointPropertyType>();
for (Point prim : multiPrim.getElements()) {
PointType element = (PointType) getGMLFromISO(prim);
PointPropertyType gp = new PointPropertyType((PointType) element);
geometries.add(gp);
}
MultiPointType gmlMulti = new MultiPointType(null, geometries);
return gmlMulti;
} else if (geometry instanceof MultiPrimitive) {
MultiPrimitive multiPrim = (MultiPrimitive) geometry;
List<GeometryPropertyType> geometries = new ArrayList<GeometryPropertyType>();
for (Primitive prim : multiPrim.getElements()) {
AbstractGMLType element = getGMLFromISO(prim);
GeometryPropertyType gp = new GeometryPropertyType((AbstractGeometryType) element);
geometries.add(gp);
}
MultiGeometryType gmlMulti = new MultiGeometryType(geometries);
return gmlMulti;
} else if (geometry instanceof Curve) {
Curve curve = (Curve) geometry;
List<? extends CurveSegment> segments = curve.getSegments();
List<LineStringSegmentType> gmlSegments = new ArrayList<LineStringSegmentType>();
for (CurveSegment segment : segments) {
CurveInterpolationType interpolation = CurveInterpolationType.fromValue(segment.getInterpolation().identifier());
PointArray array = GeometricUtilities.getSamplePoints(segment);
List<DirectPosition> positions = new ArrayList<DirectPosition>();
for (int i = 0; i < array.size(); i++) {
positions.add(array.getDirectPosition(i, null));
}
LineStringSegmentType gmlSegment = new LineStringSegmentType(segment.getNumDerivativesAtStart(), segment.getNumDerivativesAtEnd(), segment.getNumDerivativesInterior(), interpolation, positions);
gmlSegments.add(gmlSegment);
}
CurveType gmlCurve = new CurveType(gmlSegments);
return gmlCurve;
} else if (geometry instanceof LineString) {
LineString line = (LineString) geometry;
PointArray array = GeometricUtilities.getSamplePoints(line);
List<DirectPosition> positions = new ArrayList<DirectPosition>();
for (int i = 0; i < array.size(); i++) {
positions.add(array.getDirectPosition(i, null));
}
LineStringType gmlLine = new LineStringType(positions);
return gmlLine;
} else if (geometry instanceof Polygon) {
Polygon polygon = (Polygon) geometry;
SurfaceBoundary boundary = polygon.getBoundary();
Ring exterior = boundary.getExterior();
List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
for (Primitive p : exterior.getElements()) {
curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlExterior = new RingType();
gmlExterior.getCurveMember().addAll(curves);
List<Ring> interiors = boundary.getInteriors();
List<RingType> gmlInteriors = new ArrayList<RingType>();
for (Ring interior : interiors) {
List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
for (Primitive p : interior.getElements()) {
intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlinterior = new RingType();
gmlinterior.getCurveMember().addAll(intcurves);
gmlInteriors.add(gmlinterior);
}
PolygonType gmlPolygon = new PolygonType(gmlExterior, gmlInteriors);
return gmlPolygon;
} else if (geometry instanceof PolyhedralSurface) {
PolyhedralSurface polySurface = (PolyhedralSurface) geometry;
List<PolygonPatchType> gmlPatches = new ArrayList<PolygonPatchType>();
List<? extends Polygon> patches = polySurface.getPatches();
for (Polygon polygon : patches) {
SurfaceInterpolationType interpolation = SurfaceInterpolationType.fromValue(polygon.getInterpolation().identifier());
SurfaceBoundary boundary = polygon.getBoundary();
Ring exterior = boundary.getExterior();
List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
for (Primitive p : exterior.getElements()) {
curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlExterior = new RingType();
gmlExterior.getCurveMember().addAll(curves);
List<Ring> interiors = boundary.getInteriors();
List<RingType> gmlInteriors = new ArrayList<RingType>();
for (Ring interior : interiors) {
List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
for (Primitive p : interior.getElements()) {
intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlinterior = new RingType();
gmlinterior.getCurveMember().addAll(intcurves);
gmlInteriors.add(gmlinterior);
}
PolygonPatchType patche = new PolygonPatchType(interpolation, gmlExterior, gmlInteriors);
gmlPatches.add(patche);
}
PolygonPatchArrayPropertyType pathArray = new PolygonPatchArrayPropertyType(gmlPatches);
PolyhedralSurfaceType gmlPolySurface = new PolyhedralSurfaceType(pathArray);
return gmlPolySurface;
} else {
System.out.println("unexpected iso geometry type:" + geometry.getClass().getName());
}
return null;
}
use of org.geotoolkit.gml.xml.v311.PointPropertyType in project geotoolkit by Geomatys.
the class GeometryTransformer method getCoordinates.
/**
* Check that given geometry is a primitive geometry (implements {@link WithCoordinates}), and
* get its points.
* @param source The geometry to extract points from.
* @return Found points, never null, but can be empty.
* @throws UnconvertibleObjectException If the given geometry does not implement {@link WithCoordinates}.
*/
private Spliterator<Coordinate> getCoordinates(final Object source) throws UnconvertibleObjectException {
List<Double> values = null;
if (source instanceof WithCoordinates) {
final Coordinates coords = ((WithCoordinates) source).getCoordinates();
if (coords != null) {
/* HACK : In GML 3, coordinates are just a list of decimal values.
* The grouping by coordinate is done using "srsDimension" attribute
* on parent geometry type. However, with GML 2, there's another
* possibility : Coordinates use two distinct separators : one for
* decimal value separation, and another for coordinate separation.
* To manage both ways, we first check if coordinates object has
* succeeded in splitting underlying decimals in coordinates. If
* it does (return arrays with more than one element), we use
* that approach. Otherwise, we fallback on standard way which
* will try to determine manually the number of dimensions.
*/
Iterator<double[]> it = coords.points().iterator();
if (it.hasNext() && it.next().length > 1) {
return coords.points().map(GeometryTransformer::toCoordinate).spliterator();
} else {
values = coords.getValues();
}
} else if (source instanceof Point) {
DirectPosition dp = ((Point) source).getPos();
if (dp != null) {
return Stream.of(convertDirectPosition(dp)).spliterator();
} else
// recognized object, but no value. Empty geometry
return Spliterators.emptySpliterator();
}
}
// TODO : below conditions should be removed when proper abstraction is setup on GML geometry definition.
if (values == null) {
final boolean isLineString = source instanceof org.geotoolkit.gml.xml.LineString;
final boolean isLineStringSegment = source instanceof org.geotoolkit.gml.xml.LineStringSegment;
if (isLineString || isLineStringSegment) {
final DirectPositionList posList;
if (isLineString) {
posList = ((org.geotoolkit.gml.xml.LineString) source).getPosList();
} else {
posList = ((org.geotoolkit.gml.xml.LineStringSegment) source).getPosList();
}
if (posList != null) {
values = posList.getValue();
} else {
final List<? extends DirectPosition> pList;
if (isLineString) {
pList = ((org.geotoolkit.gml.xml.LineString) source).getPos();
} else {
pList = ((org.geotoolkit.gml.xml.LineStringSegment) source).getPos();
}
if (pList != null) {
return pList.stream().map(GeometryTransformer::convertDirectPosition).filter(Objects::nonNull).spliterator();
} else {
// We've identified a line, but there's no data in it
values = Collections.EMPTY_LIST;
}
}
} else if (source instanceof org.geotoolkit.gml.xml.LinearRing) {
// Note : do not check "getCoordinates", because it should have been done above.
values = asDoubles(() -> ((org.geotoolkit.gml.xml.LinearRing) source).getPosList());
} else if (source instanceof org.geotoolkit.gml.xml.v311.GeodesicStringType) {
values = asDoubles(() -> ((org.geotoolkit.gml.xml.v311.GeodesicStringType) source).getPosList());
} else if (source instanceof org.geotoolkit.gml.xml.v321.GeodesicStringType) {
values = asDoubles(() -> ((org.geotoolkit.gml.xml.v321.GeodesicStringType) source).getPosList());
} else if (source instanceof Curve) {
CurveSegmentArrayProperty segments = ((Curve) source).getSegments();
if (segments != null) {
final List<? extends AbstractCurveSegment> curveSegments = segments.getAbstractCurveSegment();
if (curveSegments != null) {
return curveSegments.stream().flatMap(seg -> StreamSupport.stream(getCoordinates(seg), false)).spliterator();
}
}
// If we arrive here, we've got an empty curve.
values = Collections.EMPTY_LIST;
} else if (source instanceof ArcByCenterPointType) {
final ArcByCenterPointType arc = (ArcByCenterPointType) source;
org.opengis.geometry.DirectPosition dp = arc.getPos();
if (dp == null) {
PointPropertyType pp = arc.getPointProperty();
if (pp == null) {
pp = arc.getPointRep();
}
if (pp == null) {
throw new UnconvertibleObjectException("Not enough information to build an arc.");
}
final Geometry point = new GeometryTransformer(pp.getPoint(), this).get();
dp = JTS.toEnvelope(point).getLowerCorner();
}
CoordinateReferenceSystem crs = dp.getCoordinateReferenceSystem();
if (crs == null) {
crs = getSrsName().map(this::findCRS).orElseThrow(() -> new UnconvertibleObjectException("Cannot create an arc without its coordinate reference system"));
final GeneralDirectPosition gdp = new GeneralDirectPosition(dp);
gdp.setCoordinateReferenceSystem(crs);
dp = gdp;
}
try {
final Measure startAngle, endAngle;
// If we miss a start or end angle, it means we're in presence of a circle.
if (arc.getStartAngle() == null || arc.getEndAngle() == null) {
startAngle = new Measure(0, Units.DEGREE);
endAngle = new Measure(360, Units.DEGREE);
} else {
startAngle = asMeasure(arc.getStartAngle());
endAngle = asMeasure(arc.getEndAngle());
}
final Coordinate[] coordinates = drawArc(dp, asMeasure(arc.getRadius()), startAngle, endAngle, ARC_PRECISION);
return Spliterators.spliterator(coordinates, Spliterator.ORDERED);
} catch (TransformException ex) {
throw new UnconvertibleObjectException("Cannot draw an arc.", ex);
}
} else if (source instanceof org.geotoolkit.gml.xml.v311.ArcByCenterPointType) {
// TODO : factorize with above case
final org.geotoolkit.gml.xml.v311.ArcByCenterPointType arc = (org.geotoolkit.gml.xml.v311.ArcByCenterPointType) source;
org.opengis.geometry.DirectPosition dp = arc.getPos();
if (dp == null) {
org.geotoolkit.gml.xml.v311.PointPropertyType pp = arc.getPointProperty();
if (pp == null) {
pp = arc.getPointRep();
}
if (pp == null) {
throw new UnconvertibleObjectException("Not enough information to build an arc.");
}
final Geometry point = new GeometryTransformer(pp.getPoint(), this).get();
dp = JTS.toEnvelope(point).getLowerCorner();
}
CoordinateReferenceSystem crs = dp.getCoordinateReferenceSystem();
if (crs == null) {
crs = getSrsName().map(this::findCRS).orElseThrow(() -> new UnconvertibleObjectException("Cannot create an arc without its coordinate reference system"));
final GeneralDirectPosition gdp = new GeneralDirectPosition(dp);
gdp.setCoordinateReferenceSystem(crs);
dp = gdp;
}
try {
final Measure startAngle, endAngle;
// If we miss a start or end angle, it means we're in presence of a circle.
if (arc.getStartAngle() == null || arc.getEndAngle() == null) {
startAngle = new Measure(0, Units.DEGREE);
endAngle = new Measure(360, Units.DEGREE);
} else {
startAngle = asMeasure(arc.getStartAngle());
endAngle = asMeasure(arc.getEndAngle());
}
final Coordinate[] coordinates = drawArc(dp, asMeasure(arc.getRadius()), startAngle, endAngle, ARC_PRECISION);
return Spliterators.spliterator(coordinates, Spliterator.ORDERED);
} catch (TransformException ex) {
throw new UnconvertibleObjectException("Cannot draw an arc.", ex);
}
}
}
if (values != null) {
if (values.isEmpty()) {
return Spliterators.emptySpliterator();
}
return new CoordinateSpliterator(values, getCoordinateDimension());
}
throw new UnconvertibleObjectException("Cannot extract coordinates from source geometry.");
}
Aggregations