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);
}
}
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);
}
}
}
}
}
}
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;
}
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);
}
}
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;
}
Aggregations