use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint in project geotoolkit by Geomatys.
the class FeatureFilterSpatialTest method testSpatialFilter.
/**
* Test that we get acces attributs without knowing the namespace
*/
@Test
public void testSpatialFilter() throws Exception {
/**
*******************************************************************************************
* *
* AggregateGeoFeature *
* *
********************************************************************************************
*/
final GenericName description = NamesExt.create("http://www.opengis.net/gml", "description");
final GenericName name = NamesExt.create("http://www.opengis.net/gml", "name");
final GenericName multiPointProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "multiPointProperty");
final GenericName multiCurveProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "multiCurveProperty");
final GenericName multiSurfaceProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "multiSurfaceProperty");
final GenericName doubleProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "doubleProperty");
final GenericName intRangeProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "intRangeProperty");
final GenericName strProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "strProperty");
final GenericName featureCode = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "featureCode");
final GenericName id = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "id");
FeatureTypeBuilder sftb = new FeatureTypeBuilder();
sftb.setName(NamesExt.create("http://cite.opengeospatial.org/gmlsf", "AggregateGeoFeature"));
sftb.addAttribute(String.class).setName(description);
sftb.addAttribute(String.class).setName(name);
sftb.addAttribute(MultiPoint.class).setName(multiPointProperty).setCRS(CommonCRS.WGS84.geographic());
sftb.addAttribute(MultiLineString.class).setName(multiCurveProperty).setCRS(CommonCRS.WGS84.geographic());
sftb.addAttribute(MultiPolygon.class).setName(multiSurfaceProperty).setCRS(CommonCRS.WGS84.geographic());
sftb.addAttribute(Double.class).setName(doubleProperty);
sftb.addAttribute(String.class).setName(intRangeProperty);
sftb.addAttribute(String.class).setName(strProperty);
sftb.addAttribute(String.class).setName(featureCode);
sftb.addAttribute(String.class).setName(id).addRole(AttributeRole.IDENTIFIER_COMPONENT);
final FeatureType aggregateGeoFeatureType = sftb.build();
/**
*******************************************************************************************
* AggregateGeoFeature 1 *
********************************************************************************************
*/
final Feature aggregateGeoFeature1 = aggregateGeoFeatureType.newInstance();
aggregateGeoFeature1.setPropertyValue(AttributeConvention.IDENTIFIER, "f005");
aggregateGeoFeature1.setPropertyValue(description.toString(), "description-f005");
aggregateGeoFeature1.setPropertyValue(name.toString(), "name-f005");
GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
Point[] points = new Point[3];
points[0] = factory.createPoint(new Coordinate(70.83, 29.86));
points[1] = factory.createPoint(new Coordinate(68.87, 31.08));
points[2] = factory.createPoint(new Coordinate(71.96, 32.19));
aggregateGeoFeature1.setPropertyValue(multiPointProperty.toString(), factory.createMultiPoint(points));
aggregateGeoFeature1.setPropertyValue(doubleProperty.toString(), 2012.78);
aggregateGeoFeature1.setPropertyValue(strProperty.toString(), "Ma quande lingues coalesce...");
aggregateGeoFeature1.setPropertyValue(featureCode.toString(), "BK030");
aggregateGeoFeature1.setPropertyValue(id.toString(), "f005");
/**
*******************************************************************************************
* *
* EntitéGénérique *
* *
********************************************************************************************
*/
final GenericName attributGeometrie = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "attribut.Géométrie");
final GenericName boolProperty = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "boolProperty");
final GenericName str4Property = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "str4Property");
final GenericName featureRef = NamesExt.create("http://cite.opengeospatial.org/gmlsf", "featureRef");
sftb = new FeatureTypeBuilder();
sftb.setName(NamesExt.create("http://cite.opengeospatial.org/gmlsf", "EntitéGénérique"));
sftb.addAttribute(String.class).setName(description);
sftb.addAttribute(String.class).setName(name);
sftb.addAttribute(Geometry.class).setName(attributGeometrie).setCRS(CommonCRS.WGS84.geographic());
sftb.addAttribute(Boolean.class).setName(boolProperty);
sftb.addAttribute(String.class).setName(str4Property);
sftb.addAttribute(String.class).setName(featureRef);
sftb.addAttribute(String.class).setName(id).addRole(AttributeRole.IDENTIFIER_COMPONENT);
final FeatureType entiteGeneriqueType = sftb.build();
/**
*******************************************************************************************
* EntitéGénérique 1 *
********************************************************************************************
*/
final Feature entiteGenerique1 = entiteGeneriqueType.newInstance();
entiteGenerique1.setPropertyValue(description.toString(), "description-f004");
entiteGenerique1.setPropertyValue(name.toString(), "name-f004");
Coordinate[] exteriorCoord = new Coordinate[5];
exteriorCoord[0] = new Coordinate(60.5, 0);
exteriorCoord[1] = new Coordinate(64, 0);
exteriorCoord[2] = new Coordinate(64, 6.25);
exteriorCoord[3] = new Coordinate(60.5, 6.25);
exteriorCoord[4] = new Coordinate(60.5, 0);
LinearRing exterior = factory.createLinearRing(exteriorCoord);
Coordinate[] interiorCoord = new Coordinate[4];
interiorCoord[0] = new Coordinate(61.5, 2);
interiorCoord[1] = new Coordinate(62.5, 2);
interiorCoord[2] = new Coordinate(62, 4);
interiorCoord[3] = new Coordinate(61.5, 2);
LinearRing interior = factory.createLinearRing(interiorCoord);
LinearRing[] interiors = new LinearRing[1];
interiors[0] = interior;
entiteGenerique1.setPropertyValue(attributGeometrie.toString(), factory.createPolygon(exterior, interiors));
entiteGenerique1.setPropertyValue(boolProperty.toString(), false);
entiteGenerique1.setPropertyValue(str4Property.toString(), "abc3");
entiteGenerique1.setPropertyValue(featureRef.toString(), "name-f003");
entiteGenerique1.setPropertyValue(id.toString(), "f004");
/**
*******************************************************************************************
* EntitéGénérique 2 *
********************************************************************************************
*/
final Feature entiteGenerique2 = entiteGeneriqueType.newInstance();
entiteGenerique2.setPropertyValue(description.toString(), "description-f007");
entiteGenerique2.setPropertyValue(name.toString(), "name-f007");
Coordinate[] exteriorCoord2 = new Coordinate[6];
exteriorCoord2[0] = new Coordinate(35, 15);
exteriorCoord2[1] = new Coordinate(40, 16);
exteriorCoord2[2] = new Coordinate(39, 20);
exteriorCoord2[3] = new Coordinate(37, 22.5);
exteriorCoord2[4] = new Coordinate(36, 18);
exteriorCoord2[5] = new Coordinate(35, 15);
LinearRing exterior2 = factory.createLinearRing(exteriorCoord);
Coordinate[] interiorCoord2 = new Coordinate[7];
interiorCoord2[0] = new Coordinate(37.1, 17.5);
interiorCoord2[1] = new Coordinate(37.2, 17.6);
interiorCoord2[2] = new Coordinate(37.3, 17.7);
interiorCoord2[3] = new Coordinate(37.4, 17.8);
interiorCoord2[4] = new Coordinate(37.5, 17.9);
interiorCoord2[5] = new Coordinate(37, 17.9);
interiorCoord2[6] = new Coordinate(37.1, 17.5);
LinearRing interior2 = factory.createLinearRing(interiorCoord);
LinearRing[] interiors2 = new LinearRing[1];
interiors2[0] = interior;
entiteGenerique2.setPropertyValue(attributGeometrie.toString(), factory.createPolygon(exterior2, interiors2));
entiteGenerique2.setPropertyValue(boolProperty.toString(), false);
entiteGenerique2.setPropertyValue(str4Property.toString(), "def4");
entiteGenerique2.setPropertyValue(id.toString(), "f007");
/**
*******************************************************************************************
* EntitéGénérique 3 *
********************************************************************************************
*/
final Feature entiteGenerique3 = entiteGeneriqueType.newInstance();
entiteGenerique3.setPropertyValue(description.toString(), "description-f017");
entiteGenerique3.setPropertyValue(name.toString(), "name-f017");
Coordinate[] lineCoord = new Coordinate[5];
lineCoord[0] = new Coordinate(50.174, 4.899);
lineCoord[1] = new Coordinate(52.652, 5.466);
lineCoord[2] = new Coordinate(53.891, 6.899);
lineCoord[3] = new Coordinate(54.382, 7.780);
lineCoord[4] = new Coordinate(54.982, 8.879);
entiteGenerique3.setPropertyValue(attributGeometrie.toString(), factory.createLineString(lineCoord));
entiteGenerique3.setPropertyValue(boolProperty.toString(), false);
entiteGenerique3.setPropertyValue(str4Property.toString(), "qrst");
entiteGenerique3.setPropertyValue(featureRef.toString(), "name-f015");
entiteGenerique3.setPropertyValue(id.toString(), "f017");
/*
* Filter equals on aggregateGeoFeature1
*/
CoordinateReferenceSystem crs = CommonCRS.WGS84.geographic();
JTSMultiPoint multiPoint = new JTSMultiPoint();
multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(70.83, 29.86), crs));
multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(68.87, 31.08), crs));
multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(71.96, 32.19), crs));
BinarySpatialOperator equalsfilter = FF.equals(FF.property("{http://cite.opengeospatial.org/gmlsf}multiPointProperty"), FF.literal(multiPoint));
boolean match = equalsfilter.test(aggregateGeoFeature1);
assertTrue(match);
/*
* Filter intersects on entitiGenerique*
*/
multiPoint = new JTSMultiPoint();
multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(38.83, 16.22), crs));
multiPoint.getElements().add(new JTSPoint(new GeneralDirectPosition(62.07, 2.48), crs));
BinarySpatialOperator intfilter = FF.intersects(FF.property("{http://cite.opengeospatial.org/gmlsf}attribut.Géométrie"), FF.literal(multiPoint));
match = intfilter.test(entiteGenerique1);
assertFalse(match);
match = intfilter.test(entiteGenerique2);
assertFalse(match);
match = intfilter.test(entiteGenerique3);
assertFalse(match);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint in project geotoolkit by Geomatys.
the class AbstractJTSGeometry method getBoundary.
/**
* Returns the boundary of this geometry. Returns null if the boundary is
* empty.
*/
@Override
public Boundary getBoundary() {
// PENDING(CSD):
// Need to find out if MultiPrimitives are handled correctly. (I think
// they are, but 19107's boundary semantics for multi-primitives are
// not well-specified.)
// Need to find out if GeometryCollections are handled correctly. (I
// don't think they are, but it's not clear what it would mean, nor is
// it obvious why anyone would call it in the first place.)
org.locationtech.jts.geom.Geometry jtsGeom = getJTSGeometry();
// compute the boundary of a collection object in 19107.
if (jtsGeom instanceof org.locationtech.jts.geom.GeometryCollection) {
throw new UnsupportedOperationException("Boundary cannot be computed for multi-primitives.");
}
org.locationtech.jts.geom.Geometry jtsBoundary = jtsGeom.getBoundary();
int d = jtsGeom.getDimension();
if (d == 0) {
// be NULL.
return null;
} else if (d == 1) {
// If d is 1, then the boundary is either empty (if it's a ring) or
// it's two points at either end of the curve.
// We've ruled out the possibility of multi-primitives (see the
// instanceof check above), so we know that the boundary can't be
// more than 2 points.
org.locationtech.jts.geom.Coordinate[] coords = jtsBoundary.getCoordinates();
// null).
if ((coords == null) || (coords.length == 0)) {
JTSCurveBoundary result = new JTSCurveBoundary(getCoordinateReferenceSystem(), null, null);
return result;
} else {
// endpoints.
if (coords.length != 2) {
// Should this be an assert instead?
throw new RuntimeException("ERROR: One dimensional " + "primitive had wrong number of boundary points (" + coords.length + ")");
}
CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
JTSCurveBoundary result = new JTSCurveBoundary(crs, new JTSPoint(JTSUtils.coordinateToDirectPosition(coords[0], crs)), new JTSPoint(JTSUtils.coordinateToDirectPosition(coords[1], crs)));
return result;
}
} else if (d == 2) {
// If d == 2, then the boundary is a collection of rings.
// In particular, the JTS tests indicate that it'll be a
// MultiLineString.
org.locationtech.jts.geom.MultiLineString mls = (org.locationtech.jts.geom.MultiLineString) jtsBoundary;
int n = mls.getNumGeometries();
CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
Ring exteriorRing = JTSUtils.linearRingToRing((org.locationtech.jts.geom.LineString) mls.getGeometryN(0), crs);
Ring[] interiorRings = new Ring[n - 1];
for (int i = 1; i < n; i++) {
interiorRings[n - 1] = JTSUtils.linearRingToRing((org.locationtech.jts.geom.LineString) mls.getGeometryN(i), crs);
}
JTSSurfaceBoundary result = new JTSSurfaceBoundary(crs, exteriorRing, interiorRings);
return result;
} else {
throw new UnsupportedOperationException("Computing the boundary " + "for geometries of dimension larger than 2 is not " + "supported.");
}
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint in project geotoolkit by Geomatys.
the class ISOGeomTest method hello.
@Test
public void hello() throws NoSuchAuthorityCodeException, FactoryException {
GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
Point[] points = new Point[3];
points[0] = factory.createPoint(new Coordinate(70.83, 29.86));
points[1] = factory.createPoint(new Coordinate(68.87, 31.08));
points[2] = factory.createPoint(new Coordinate(71.96, 32.19));
Geometry jtsGeom = factory.createMultiPoint(points);
CoordinateReferenceSystem crs = CommonCRS.WGS84.geographic();
JTSMultiPoint isoGeom = new JTSMultiPoint();
isoGeom.getElements().add(new JTSPoint(new GeneralDirectPosition(70.83, 29.86), crs));
isoGeom.getElements().add(new JTSPoint(new GeneralDirectPosition(68.87, 31.08), crs));
isoGeom.getElements().add(new JTSPoint(new GeneralDirectPosition(71.96, 32.19), crs));
BinarySpatialOperator<Object> filter = FF.equals(FF.literal(jtsGeom), FF.literal(isoGeom));
boolean match = filter.test(null);
assertTrue(match);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method PointMarshalingTest.
/**
* Test point Marshalling.
*/
@Test
public void PointMarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::4326");
assertTrue(crs != null);
DirectPosition dp = new GeneralDirectPosition(crs);
dp.setOrdinate(0, 2.1);
dp.setOrdinate(1, 12.6);
JTSPoint point = new JTSPoint(dp, crs);
StringWriter sw = new StringWriter();
m.marshal(factory.createJTSPoint(point), sw);
String result = sw.toString();
result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:Point xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::4326\" >" + '\n' + " <gml:pos>2.1 12.6</gml:pos>" + '\n' + "</gml:Point>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
pool.recycle(m);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPoint in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method MultiPointUnmarshalingTest.
/**
* Test multiPoint Marshalling.
*/
@Test
public void MultiPointUnmarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::27572");
assertTrue(crs != null);
DirectPosition p1 = new GeneralDirectPosition(crs);
p1.setOrdinate(0, 402000);
p1.setOrdinate(1, 3334850);
JTSPoint pt1 = new JTSPoint(p1);
DirectPosition p2 = new GeneralDirectPosition(crs);
p2.setOrdinate(0, 402200);
p2.setOrdinate(1, 3335200);
JTSPoint pt2 = new JTSPoint(p2);
JTSMultiPoint expResult = new JTSMultiPoint(crs);
expResult.getElements().add(pt1);
expResult.getElements().add(pt2);
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiPoint srsName=\"urn:ogc:def:crs:epsg::27572\" xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:pointMember>" + '\n' + " <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:pos>402200.0 3335200.0</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </gml:pointMember>" + '\n' + " <gml:pointMember>" + '\n' + " <gml:Point srsName=\"urn:ogc:def:crs:epsg::27572\">" + '\n' + " <gml:pos>402000.0 3334850.0</gml:pos>" + '\n' + " </gml:Point>" + '\n' + " </gml:pointMember>" + '\n' + "</gml:MultiPoint>" + '\n';
JTSMultiPoint result = (JTSMultiPoint) ((JAXBElement) un.unmarshal(new StringReader(xml))).getValue();
assertEquals(expResult, result);
}
Aggregations