Search in sources :

Example 1 with SampleGeometryCollection3D

use of org.datanucleus.samples.jtsgeometry.SampleGeometryCollection3D in project tests by datanucleus.

the class JtsGeometry3dMappingTest method testGeometryCollection3DMapping.

public void testGeometryCollection3DMapping() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    SampleGeometryCollection3D sampleGeometryCollection;
    SampleGeometryCollection3D sampleGeometryCollection_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        Point point = geomFactory.createPoint(new Coordinate(10.0, 10.0, 100.0));
        LineString linestring = geomFactory.createLineString(new Coordinate[] { new Coordinate(0.0, 50.0, 100.0), new Coordinate(100.0, 50.0, 100.0) });
        LinearRing extRing = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(25.0, 25.0, 100), new Coordinate(75.0, 25.0, 100.0), new Coordinate(75.0, 75.0, 100.0), new Coordinate(25.0, 75.0, 100.0), new Coordinate(25.0, 25.0, 100) });
        Polygon polygon = geomFactory.createPolygon(extRing, null);
        GeometryCollection collection = geomFactory.createGeometryCollection(new Geometry[] { point, linestring, polygon });
        sampleGeometryCollection = new SampleGeometryCollection3D(7101, "Collection of 3-dimensional geometries", collection);
        pm.makePersistent(sampleGeometryCollection);
        id = JDOHelper.getObjectId(sampleGeometryCollection);
        sampleGeometryCollection = (SampleGeometryCollection3D) pm.detachCopy(sampleGeometryCollection);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometryCollection_read = (SampleGeometryCollection3D) pm.getObjectById(id, true);
        assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) SampleGeometryCollection3D(org.datanucleus.samples.jtsgeometry.SampleGeometryCollection3D) Point(com.vividsolutions.jts.geom.Point) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)1 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)1 LineString (com.vividsolutions.jts.geom.LineString)1 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 Point (com.vividsolutions.jts.geom.Point)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleGeometryCollection3D (org.datanucleus.samples.jtsgeometry.SampleGeometryCollection3D)1