use of org.geotoolkit.gml.xml.v212.PointType 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.v212.PointType in project ddf by codice.
the class WfsSourceTest method testQueryLatLonCoordinateOrder.
@Test
public void testQueryLatLonCoordinateOrder() throws Exception {
mapSchemaToFeatures(ONE_GML_PROPERTY_SCHEMA, ONE_FEATURE);
setUpMocks(Collections.singletonList("DWithin"), SRS_NAME, ONE_FEATURE, ONE_FEATURE);
source.setPollInterval(1);
final Map<String, Object> configuration = ImmutableMap.<String, Object>builder().put("wfsUrl", "http://localhost/wfs").put("coordinateOrder", LAT_LON_ORDER).put("forceSpatialFilter", "NO_FILTER").put("allowRedirects", false).put("disableCnCheck", false).put("pollInterval", 1).put("disableSorting", false).put("supportsStartIndex", false).put("forceAllGeometryOperands", false).build();
source.refresh(configuration);
final Filter withinFilter = builder.attribute(Metacard.ANY_GEO).is().withinBuffer().wkt(POINT_WKT, 10.0);
final Query withinQuery = new QueryImpl(withinFilter);
final ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(withinQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertThat(getFeatureType.getQuery(), hasSize(1));
final QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getFilter().getSpatialOps().getValue(), is(instanceOf(DistanceBufferType.class)));
final DistanceBufferType distanceBufferType = (DistanceBufferType) query.getFilter().getSpatialOps().getValue();
assertThat(distanceBufferType.getGeometry().getValue(), is(instanceOf(PointType.class)));
final PointType pointType = (PointType) distanceBufferType.getGeometry().getValue();
assertThat(pointType.getCoordinates().getValue(), is("-10.0,30.0"));
}
use of org.geotoolkit.gml.xml.v212.PointType in project ddf by codice.
the class WfsFilterDelegate method createPoint.
private JAXBElement<PointType> createPoint(Geometry geometry) {
Coordinate[] coordinates = geometry.getCoordinates();
if (coordinates != null && coordinates.length > 0) {
StringBuilder coordString = new StringBuilder();
coordString.append(coordinates[0].x).append(",").append(coordinates[0].y);
CoordinatesType coordinatesType = new CoordinatesType();
coordinatesType.setValue(coordString.toString());
PointType point = new PointType();
point.setSrsName(srsName);
point.setCoordinates(coordinatesType);
return gml320ObjectFactory.createPoint(point);
} else {
throw new IllegalArgumentException("Unable to parse Point coordinates from WKT String");
}
}
use of org.geotoolkit.gml.xml.v212.PointType in project ddf by codice.
the class WfsSourceTest method testQueryLonLatCoordinateOrder.
@Test
public void testQueryLonLatCoordinateOrder() throws Exception {
mapSchemaToFeatures(ONE_GML_PROPERTY_SCHEMA, ONE_FEATURE);
setUpMocks(Collections.singletonList("DWithin"), SRS_NAME, ONE_FEATURE, ONE_FEATURE);
source.setPollInterval(1);
final Map<String, Object> configuration = ImmutableMap.<String, Object>builder().put("wfsUrl", "http://localhost/wfs").put("coordinateOrder", LON_LAT_ORDER).put("forceSpatialFilter", "NO_FILTER").put("allowRedirects", false).put("disableCnCheck", false).put("pollInterval", 1).put("disableSorting", false).put("supportsStartIndex", false).put("forceAllGeometryOperands", false).build();
source.refresh(configuration);
final Filter withinFilter = builder.attribute(Metacard.ANY_GEO).is().withinBuffer().wkt(POINT_WKT, 10.0);
final Query withinQuery = new QueryImpl(withinFilter);
final ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(withinQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertThat(getFeatureType.getQuery(), hasSize(1));
final QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getFilter().getSpatialOps().getValue(), is(instanceOf(DistanceBufferType.class)));
final DistanceBufferType distanceBufferType = (DistanceBufferType) query.getFilter().getSpatialOps().getValue();
assertThat(distanceBufferType.getGeometry().getValue(), is(instanceOf(PointType.class)));
final PointType pointType = (PointType) distanceBufferType.getGeometry().getValue();
assertThat(pointType.getCoordinates().getValue(), is("30.0,-10.0"));
}
use of org.geotoolkit.gml.xml.v212.PointType in project ddf by codice.
the class WfsFilterDelegateTest method testPointLonLatOrder.
@Test
public void testPointLonLatOrder() {
final WfsFilterDelegate delegate = setupFilterDelegate(SPATIAL_OPERATORS.DWITHIN.getValue(), new LonLatCoordinateStrategy());
final FilterType filter = delegate.dwithin(Metacard.ANY_GEO, POINT, DISTANCE);
assertThat(filter.getSpatialOps().getValue(), is(instanceOf(DistanceBufferType.class)));
final DistanceBufferType distanceBufferType = (DistanceBufferType) filter.getSpatialOps().getValue();
assertThat(distanceBufferType.getGeometry().getValue(), is(instanceOf(PointType.class)));
final PointType pointType = (PointType) distanceBufferType.getGeometry().getValue();
assertThat(pointType.getCoordinates().getValue(), is("30.0,-10.0"));
}
Aggregations