use of org.geotoolkit.gml.xml.v311.GeometryPropertyType in project ddf by codice.
the class Wfs20JTStoGML321Converter method createGeometryPropertyType.
private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
if (geometry instanceof Point) {
PointType pointType = convertToPointType((Point) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
} else if (geometry instanceof LineString) {
LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
} else if (geometry instanceof Polygon) {
PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
} else if (geometry instanceof MultiPoint) {
MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
} else if (geometry instanceof MultiLineString) {
MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
} else if (geometry instanceof MultiPolygon) {
MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
} else if (geometry instanceof GeometryCollection) {
MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
} else {
throw new IllegalArgumentException();
}
return geometryPropertyType;
}
use of org.geotoolkit.gml.xml.v311.GeometryPropertyType in project arctic-sea by 52North.
the class GmlEncoderv321 method createGeomteryPropertyType.
private XmlObject createGeomteryPropertyType(AbstractGeometry element, EncodingContext ctx) throws EncodingException {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance();
if (element.isReferenced()) {
geometryPropertyType.setHref(element.getGmlId());
} else {
AbstractGeometryType xmlObject = createAbstractGeometry(element, ctx);
geometryPropertyType.setAbstractGeometry(xmlObject);
XmlHelper.substituteElement(geometryPropertyType.getAbstractGeometry(), xmlObject);
}
return geometryPropertyType;
}
use of org.geotoolkit.gml.xml.v311.GeometryPropertyType in project arctic-sea by 52North.
the class GmlEncoderv321 method createPosition.
private XmlObject createPosition(Geometry geom, EncodingContext ctx) throws EncodingException {
String foiId = ctx.<String>get(XmlBeansEncodingFlags.GMLID).orElse(null);
if (geom instanceof Point) {
PointType xbPoint = PointType.Factory.newInstance(getXmlOptions());
xbPoint.setId(getGmlID(geom, foiId));
createPointFromJtsGeometry((Point) geom, xbPoint);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
PointDocument xbPointDoc = PointDocument.Factory.newInstance(getXmlOptions());
xbPointDoc.setPoint(xbPoint);
return xbPointDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbPoint);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POINT_32, PointType.type);
return geometryPropertyType;
}
return xbPoint;
} else if (geom instanceof LineString) {
LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
xbLineString.setId(getGmlID(geom, foiId));
createLineStringFromJtsGeometry((LineString) geom, xbLineString);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
LineStringDocument xbLineStringDoc = LineStringDocument.Factory.newInstance(getXmlOptions());
xbLineStringDoc.setLineString(xbLineString);
return xbLineStringDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbLineString);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_LINESTRING_32, LineStringType.type);
return geometryPropertyType;
}
return xbLineString;
} else if (geom instanceof MultiLineString) {
MultiCurveType xbMultiCurve = MultiCurveType.Factory.newInstance(getXmlOptions());
xbMultiCurve.setId(getGmlID(geom, foiId));
xbMultiCurve.setSrsName(getSrsName(geom));
for (int i = 0; i < geom.getNumGeometries(); ++i) {
Geometry lineString = geom.getGeometryN(i);
LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
xbLineString.setId(getGmlID(geom, foiId));
xbLineString.addNewPosList().setStringValue(JTSHelper.getCoordinatesString(lineString));
CurvePropertyType xbCurveMember = xbMultiCurve.addNewCurveMember();
xbCurveMember.addNewAbstractCurve().set(xbLineString);
XmlHelper.substituteElement(xbCurveMember.getAbstractCurve(), xbLineString);
}
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
MultiCurveDocument xbMultiCurveDoc = MultiCurveDocument.Factory.newInstance(getXmlOptions());
xbMultiCurveDoc.setMultiCurve(xbMultiCurve);
return xbMultiCurveDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType xbGeometryProperty = GeometryPropertyType.Factory.newInstance(getXmlOptions());
xbGeometryProperty.addNewAbstractGeometry().set(xbMultiCurve);
XmlHelper.substituteElement(xbGeometryProperty.getAbstractGeometry(), xbMultiCurve);
return xbGeometryProperty;
} else {
return xbMultiCurve;
}
} else if (geom instanceof Polygon) {
PolygonType xbPolygon = PolygonType.Factory.newInstance(getXmlOptions());
xbPolygon.setId(getGmlID(geom, foiId));
createPolygonFromJtsGeometry((Polygon) geom, xbPolygon);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
PolygonDocument xbPolygonDoc = PolygonDocument.Factory.newInstance(getXmlOptions());
xbPolygonDoc.setPolygon(xbPolygon);
return xbPolygonDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbPolygon);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POLYGON_32, PolygonType.type);
return geometryPropertyType;
}
return xbPolygon;
} else if (geom instanceof MultiPoint) {
MultiPointType xbMultiPoint = MultiPointType.Factory.newInstance(getXmlOptions());
String id = getGmlID(geom, foiId);
xbMultiPoint.setId(id);
createMultiPointFromJtsGeometry((MultiPoint) geom, xbMultiPoint, id);
if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
MultiPointDocument xbMultiPointDoc = MultiPointDocument.Factory.newInstance(getXmlOptions());
xbMultiPointDoc.setMultiPoint(xbMultiPoint);
return xbMultiPointDoc;
} else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
geometryPropertyType.setAbstractGeometry(xbMultiPoint);
geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_MULTI_POINT_32, PolygonType.type);
return geometryPropertyType;
}
return xbMultiPoint;
} else {
throw new UnsupportedEncoderInputException(this, geom);
}
}
use of org.geotoolkit.gml.xml.v311.GeometryPropertyType 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.GeometryPropertyType 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;
}
Aggregations