Search in sources :

Example 6 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class SurfaceGeometryTest method testSurfaceGml32_patches.

/**
 * Test surface geometry consisting of multiple patches read from a GML 3.2
 * file.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testSurfaceGml32_patches() throws Exception {
    InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-gml32_patches.xml").toURI());
    LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-4.5, 3), new Coordinate(0.5, 4.5), new Coordinate(5, 3), new Coordinate(8.5, 2), new Coordinate(3, -4.5), new Coordinate(1, 1), new Coordinate(-3, -1), new Coordinate(-4.5, 3) });
    Polygon composedPolygon = geomFactory.createPolygon(shell);
    // one instance expected
    ResourceIterator<Instance> it = instances.iterator();
    try {
        // PolygonPatch with LinearRings defined through coordinates
        assertTrue("First sample feature missing", it.hasNext());
        Instance instance = it.next();
        checkSingleGeometry(instance, referenceChecker(composedPolygon));
    } finally {
        it.close();
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) LinearRing(com.vividsolutions.jts.geom.LinearRing) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test) AbstractHandlerTest(eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)

Example 7 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class PolygonHandler method createGeometry.

/**
 * @see GeometryHandler#createGeometry(Instance, int, IOProvider)
 */
@SuppressWarnings("unchecked")
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing[] holes = null;
    Polygon polygon = null;
    CRSDefinition crs = null;
    // for use with GML 2
    // to parse outer linear rings
    Collection<Object> values = PropertyResolver.getValues(instance, "outerBoundaryIs.LinearRing", false);
    if (values != null && !values.isEmpty()) {
        Iterator<Object> iterator = values.iterator();
        List<LinearRing> outerRing = new ArrayList<>(1);
        while (iterator.hasNext()) {
            Object value = iterator.next();
            if (value instanceof Instance) {
                // outerRing must be a
                // GeometryProperty<LinearRing> instance
                GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                outerRing.add(ring.getGeometry());
                crs = checkCommonCrs(crs, ring.getCRSDefinition());
            }
        }
        // to parse inner linear rings
        values = PropertyResolver.getValues(instance, "innerBoundaryIs.LinearRing", false);
        if (values != null && !values.isEmpty()) {
            iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
    }
    // to parse inner linear rings
    if (polygon == null) {
        values = PropertyResolver.getValues(instance, "interior.LinearRing", false);
        Collection<Object> ringValues = PropertyResolver.getValues(instance, "interior.Ring", false);
        values = combineCollections(values, ringValues);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        // to parse outer linear rings
        values = PropertyResolver.getValues(instance, "exterior.LinearRing", false);
        ringValues = PropertyResolver.getValues(instance, "exterior.Ring", false);
        values = combineCollections(values, ringValues);
        List<LinearRing> outerRing = new ArrayList<>(1);
        if (values != null && !values.isEmpty()) {
            LinearRing outer = null;
            Iterator<Object> iterator = values.iterator();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // outerRing must be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    outer = ring.getGeometry();
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            outerRing.add(outer);
            polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
        }
    }
    if (polygon != null) {
        if (crs == null) {
            crs = GMLGeometryUtil.findCRS(instance);
        }
        return new DefaultGeometryProperty<Polygon>(crs, polygon);
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 8 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class WindingOrderTest method setUp.

/**
 * Setup for different tests
 */
@BeforeClass
public static void setUp() {
    GeometryFactory factory = new GeometryFactory();
    r1 = factory.createLinearRing(new Coordinate[] { new Coordinate(10, 30), new Coordinate(20, 0), new Coordinate(0, 0), new Coordinate(10, 30) });
    r2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87445, 8.64729), new Coordinate(49.87582, 8.65441), new Coordinate(49.87095, 8.65694), new Coordinate(49.86978, 8.65032), new Coordinate(49.87197, 8.64758), new Coordinate(49.87341, 8.64688), new Coordinate(49.87445, 8.64729) });
    h1 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87327, 8.64991), new Coordinate(49.8735, 8.6521), new Coordinate(49.87253, 8.65239), new Coordinate(49.8723, 8.65045), new Coordinate(49.87327, 8.64991) });
    h2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87203, 8.65208), new Coordinate(49.87209, 8.6531), new Coordinate(49.87156, 8.65312), new Coordinate(49.87145, 8.65227), new Coordinate(49.87203, 8.65208) });
    clockWise1 = factory.createPolygon(r1);
    clockWise2 = factory.createPolygon(r2, new LinearRing[] { h1, h2 });
    clockWise2WOHoles = factory.createPolygon(r2);
    clockWise3 = factory.createMultiPolygon(new Polygon[] { clockWise1, clockWise2 });
    clockWise4 = factory.createGeometryCollection(new Geometry[] { clockWise2, clockWise2WOHoles, clockWise3, r2 });
    if (crs1 == null) {
        try {
            crs1 = CRS_CACHE.get(code1);
        } catch (Exception e) {
            throw new IllegalStateException("Invalid CRS code", e);
        }
    }
    if (crs2 == null) {
        try {
            crs2 = CRS_CACHE.get(code2);
        } catch (Exception e) {
            throw new IllegalStateException("Invalid CRS code", e);
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRing(com.vividsolutions.jts.geom.LinearRing) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) BeforeClass(org.junit.BeforeClass)

Example 9 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class WindingOrder method unifyWindingOrderForPolyGon.

/**
 * Unify order of the polygon as counterClockwise or not including all its
 * holes.
 *
 * @param poly Polygon object for unifying
 * @param counterClockWise boolean value. true, if want shell of Polygon as
 *            counter clock wise and holes as clockwise, else false.
 * @return Polygon unified object.
 */
public static Polygon unifyWindingOrderForPolyGon(Polygon poly, boolean counterClockWise) {
    // Checking and reversing Shell
    LinearRing shell = unifyWindingOrderForLinearRing((LinearRing) poly.getExteriorRing(), counterClockWise);
    Polygon revPoly;
    // Checking and reversing Holes
    if (poly.getNumInteriorRing() > 0) {
        LinearRing[] holes = new LinearRing[poly.getNumInteriorRing()];
        for (int i = 0; i < poly.getNumInteriorRing(); i++) {
            holes[i] = unifyWindingOrderForLinearRing((LinearRing) poly.getInteriorRingN(i), !counterClockWise);
        }
        // Create New Polygon using unified shell and holes both.
        revPoly = factory.createPolygon(shell, holes);
    } else
        // Create New Polygon using unified shell only
        revPoly = factory.createPolygon(shell);
    return revPoly;
}
Also used : LinearRing(com.vividsolutions.jts.geom.LinearRing) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 10 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class InteriorPointTest method testMulti1.

/**
 * Test with a multi-polygon.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testMulti1() throws Exception {
    LinearRing outer1 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87585, 8.64984), new Coordinate(49.87597, 8.65059), new Coordinate(49.87557, 8.65071), new Coordinate(49.87545, 8.64993), new Coordinate(49.87585, 8.64984) });
    Polygon poly1 = factory.createPolygon(outer1);
    LinearRing outer2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87599, 8.6507), new Coordinate(49.8761, 8.65147), new Coordinate(49.87568, 8.6516), new Coordinate(49.87558, 8.65081), new Coordinate(49.87599, 8.6507) });
    Polygon poly2 = factory.createPolygon(outer2);
    testPointWithin(factory.createMultiPolygon(new Polygon[] { poly1, poly2 }));
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRing(com.vividsolutions.jts.geom.LinearRing) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Aggregations

LinearRing (com.vividsolutions.jts.geom.LinearRing)101 Polygon (com.vividsolutions.jts.geom.Polygon)72 Coordinate (com.vividsolutions.jts.geom.Coordinate)52 Test (org.junit.Test)42 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)28 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Resource (org.openrdf.model.Resource)24 Statement (org.openrdf.model.Statement)24 URI (org.openrdf.model.URI)24 Value (org.openrdf.model.Value)24 ValueFactory (org.openrdf.model.ValueFactory)24 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)24 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)24 ArrayList (java.util.ArrayList)22 StatementConstraints (org.apache.rya.indexing.StatementConstraints)12 LineString (com.vividsolutions.jts.geom.LineString)10 Point (com.vividsolutions.jts.geom.Point)10 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)9 Geometry (com.vividsolutions.jts.geom.Geometry)8