Search in sources :

Example 6 with Polygonal

use of com.revolsys.geometry.model.Polygonal in project com.revolsys.open by revolsys.

the class RecordIoTestSuite method assertGeometry.

private static void assertGeometry(final ClockDirection polygonRingDirection, final Geometry expectedGeometry, final Geometry actualGeometry) {
    if (expectedGeometry instanceof Polygonal) {
        Polygonal expectedPolygonal = (Polygonal) expectedGeometry;
        expectedPolygonal = expectedPolygonal.toClockDirection(polygonRingDirection);
        assertGeometry(expectedPolygonal, actualGeometry);
    } else {
        assertGeometry(expectedGeometry, actualGeometry);
    }
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal)

Example 7 with Polygonal

use of com.revolsys.geometry.model.Polygonal in project com.revolsys.open by revolsys.

the class FileGdbIoTest method doWriteReadTest.

public static void doWriteReadTest(GeometryFactory geometryFactory, final DataType dataType, Geometry geometry) {
    final int axisCount = geometryFactory.getAxisCount();
    if (geometry.isEmpty() || axisCount == 4) {
        return;
    }
    geometryFactory = GeometryFactory.fixed(geometryFactory.getCoordinateSystemId(), axisCount, GeometryFactory.newScalesFixed(axisCount, 10000000.0));
    geometry = geometry.convertGeometry(geometryFactory);
    final String geometryTypeString = dataType.toString();
    String name = "/tmp/revolsystest/io/gdb/" + geometryTypeString + "_" + axisCount;
    if (geometry.isGeometryCollection()) {
        name += "_" + geometry.getGeometryCount();
    }
    if (geometry instanceof Polygonal) {
        name += "_" + geometry.getGeometryComponents(LinearRing.class).size();
    }
    final File file = new File(name + "_" + geometry.getVertexCount() + ".gdb");
    FileUtil.deleteDirectory(file);
    file.getParentFile().mkdirs();
    try (final FileGdbRecordStore recordStore = FileGdbRecordStoreFactory.newRecordStore(file)) {
        recordStore.setCreateMissingTables(true);
        recordStore.setCreateMissingRecordStore(true);
        recordStore.initialize();
        final PathName typePath = PathName.newPathName("/" + geometryTypeString);
        final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
        recordDefinition.addField("ID", DataTypes.INT, true);
        recordDefinition.addField("NAME", DataTypes.STRING, 50, false);
        recordDefinition.addField("GEOMETRY", dataType, true);
        recordDefinition.setGeometryFactory(geometryFactory);
        recordStore.getRecordDefinition(recordDefinition);
        try (Writer<Record> writer = recordStore.newRecordWriter()) {
            writer.setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
            writer.setProperty(IoConstants.GEOMETRY_TYPE, dataType);
            final Record record = recordStore.newRecord(typePath);
            record.setValue("ID", 1);
            record.setGeometryValue(geometry);
            writer.write(record);
        }
        try (Reader<Record> reader = recordStore.getRecords(typePath)) {
            final List<Record> objects = reader.toList();
            Assert.assertEquals("Geometry Count", 1, objects.size());
            final Geometry actual = objects.get(0).getGeometry();
            Assert.assertEquals("Empty", geometry.isEmpty(), actual.isEmpty());
            if (!geometry.isEmpty()) {
                final int geometryAxisCount = geometry.getAxisCount();
                Assert.assertEquals("Axis Count", geometryAxisCount, actual.getAxisCount());
                if (!actual.equals(geometryAxisCount, geometry)) {
                    // Allow for conversion of multi part to single part
                    if (geometry.getGeometryCount() != 1 || !actual.equals(geometryAxisCount, geometry.getGeometry(0))) {
                        TestUtil.failNotEquals("Geometry Equal Exact", geometry, actual);
                    }
                }
            }
        }
    }
}
Also used : FileGdbRecordStore(com.revolsys.gis.esri.gdb.file.FileGdbRecordStore) Polygonal(com.revolsys.geometry.model.Polygonal) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) Geometry(com.revolsys.geometry.model.Geometry) Record(com.revolsys.record.Record) PathName(com.revolsys.io.PathName) LinearRing(com.revolsys.geometry.model.LinearRing) File(java.io.File)

Example 8 with Polygonal

use of com.revolsys.geometry.model.Polygonal in project com.revolsys.open by revolsys.

the class CascadedPolygonUnion method unionUsingEnvelopeIntersection.

/**
 * Unions two polygonal geometries, restricting computation
 * to the envelope intersection where possible.
 * The case of MultiPolygons is optimized to union only
 * the polygons which lie in the intersection of the two geometry's envelopes.
 * Polygons outside this region can simply be combined with the union result,
 * which is potentially much faster.
 * This case is likely to occur often during cascaded union, and may also
 * occur in real world data (such as unioning data for parcels on different street blocks).
 *
 * @param polygonal1 a polygonal geometry
 * @param polygonal2 a polygonal geometry
 * @param common the intersection of the envelopes of the inputs
 * @return the union of the inputs
 */
private Polygonal unionUsingEnvelopeIntersection(final Polygonal polygonal1, final Polygonal polygonal2, final BoundingBox common) {
    final List<Polygonal> disjointPolygons = new ArrayList<>();
    final Polygonal newPolygonal1 = extractByEnvelope(common, polygonal1, disjointPolygons);
    final Polygonal newPolygonal2 = extractByEnvelope(common, polygonal2, disjointPolygons);
    final Polygonal union = unionActual(newPolygonal1, newPolygonal2);
    disjointPolygons.add(union);
    final Polygonal overallUnion = this.geometryFactory.geometry(disjointPolygons);
    return overallUnion;
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) ArrayList(java.util.ArrayList)

Example 9 with Polygonal

use of com.revolsys.geometry.model.Polygonal in project com.revolsys.open by revolsys.

the class CascadedPolygonUnion method restrictToPolygons.

/**
 * Computes a {@link Polygonal} containing only {@link Polygonal} components.
 * Extracts the {@link Polygon}s from the input
 * and returns them as an appropriate {@link Polygonal} geometry.
 * <p>
 * If the input is already <tt>Polygonal</tt>, it is returned unchanged.
 * <p>
 * A particular use case is to filter out non-polygonal components
 * returned from an overlay operation.
 *
 * @param geometry the geometry to filter
 * @return a Polygonal geometry
 */
private static Polygonal restrictToPolygons(final Geometry geometry) {
    if (geometry instanceof Polygonal) {
        return (Polygonal) geometry;
    } else {
        final List<Polygon> polygons = geometry.getGeometries(Polygon.class);
        if (polygons.size() == 1) {
            return polygons.get(0);
        }
        final GeometryFactory geometryFactory = geometry.getGeometryFactory();
        return geometryFactory.polygonal(polygons);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon)

Example 10 with Polygonal

use of com.revolsys.geometry.model.Polygonal in project com.revolsys.open by revolsys.

the class GeometryTestUtil method multiPolygon.

public static Polygonal multiPolygon(final GeometryFactory geometryFactory, final int axisCount, final int partCount, final int ringCount) {
    final Polygon[] polygons = new Polygon[partCount];
    for (int partIndex = 0; partIndex < partCount; partIndex++) {
        polygons[partIndex] = polygon(geometryFactory, axisCount, partIndex, ringCount);
    }
    final Polygonal multiPolygon = geometryFactory.polygonal(polygons);
    return multiPolygon;
}
Also used : Polygonal(com.revolsys.geometry.model.Polygonal) Polygon(com.revolsys.geometry.model.Polygon) Point(com.revolsys.geometry.model.Point)

Aggregations

Polygonal (com.revolsys.geometry.model.Polygonal)41 Polygon (com.revolsys.geometry.model.Polygon)17 LinearRing (com.revolsys.geometry.model.LinearRing)12 Point (com.revolsys.geometry.model.Point)12 LineString (com.revolsys.geometry.model.LineString)9 Lineal (com.revolsys.geometry.model.Lineal)9 Punctual (com.revolsys.geometry.model.Punctual)9 Geometry (com.revolsys.geometry.model.Geometry)8 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)7 PolygonalEditor (com.revolsys.geometry.model.editor.PolygonalEditor)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 QuadEdgeDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 PathName (com.revolsys.io.PathName)2 Record (com.revolsys.record.Record)2 NoSuchElementException (java.util.NoSuchElementException)2 LocateFailureException (com.revolsys.elevation.tin.quadedge.LocateFailureException)1 QuadEdgeConformingDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeConformingDelaunayTinBuilder)1 IndexedPointInAreaLocator (com.revolsys.geometry.algorithm.locate.IndexedPointInAreaLocator)1