use of org.geotoolkit.gml.xml.v321.AbstractGeometryType 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.v321.AbstractGeometryType in project ddf by codice.
the class GeometryAdapter method unmarshalFrom.
public static Attribute unmarshalFrom(GeometryElement element) throws ConversionFailedException {
AttributeImpl attribute = null;
GML311ToJTSGeometryConverter converter = new GML311ToJTSGeometryConverter();
WKTWriter wktWriter = new WKTWriter();
for (Value xmlValue : element.getValue()) {
JAXBElement<AbstractGeometryType> xmlGeometry = xmlValue.getGeometry();
Geometry geometry = null;
if (xmlGeometry != null && xmlGeometry.getValue() != null) {
try {
geometry = converter.createGeometry(new DefaultRootObjectLocator(xmlValue), xmlGeometry.getValue());
} catch (ConversionFailedException e) {
LOGGER.debug("Unable to adapt goemetry. ", e);
}
}
if (geometry != null && !geometry.isEmpty()) {
String wkt = wktWriter.write(geometry);
if (attribute == null) {
attribute = new AttributeImpl(element.getName(), wkt);
} else {
attribute.addValue(wkt);
}
}
}
return attribute;
}
use of org.geotoolkit.gml.xml.v321.AbstractGeometryType in project ddf by codice.
the class CswFilterFactory method createBinarySpatialOpTypeUsingGeometry.
@SuppressWarnings("unchecked")
private BinarySpatialOpType createBinarySpatialOpTypeUsingGeometry(PropertyNameType propertyName, JAXBElement<? extends AbstractGeometryType> geometry) {
BinarySpatialOpType binarySpatialOpType = new BinarySpatialOpType();
binarySpatialOpType.getPropertyName().add(propertyName);
binarySpatialOpType.setGeometry((JAXBElement<AbstractGeometryType>) geometry);
return binarySpatialOpType;
}
use of org.geotoolkit.gml.xml.v321.AbstractGeometryType in project arctic-sea by 52North.
the class GmlEncoderv321 method createAbstractGeometry.
private AbstractGeometryType createAbstractGeometry(AbstractGeometry element, EncodingContext ctx) throws EncodingException {
XmlObject xbGeometry = createPosition(element.getGeometry(), ctx);
AbstractGeometryType abstractGeometryType = null;
if (xbGeometry instanceof AbstractGeometryType) {
abstractGeometryType = (AbstractGeometryType) xbGeometry;
} else if (xbGeometry instanceof GeometryPropertyType) {
abstractGeometryType = ((GeometryPropertyType) xbGeometry).getAbstractGeometry();
} else {
throw new UnsupportedEncoderInputException(this, element);
}
if (element.isSetIdentifier()) {
abstractGeometryType.setIdentifier(createCodeWithAuthorityType(element.getIdentifierCodeWithAuthority()));
}
if (element.isSetName()) {
for (org.n52.shetland.ogc.gml.CodeType codeType : element.getName()) {
abstractGeometryType.addNewName().set(createCodeType(codeType));
}
}
if (element.isSetDescription()) {
abstractGeometryType.addNewDescription().setStringValue(element.getDescription());
}
return abstractGeometryType;
}
use of org.geotoolkit.gml.xml.v321.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;
}
Aggregations