Search in sources :

Example 1 with LineMatchGraph

use of com.revolsys.geometry.algorithm.linematch.LineMatchGraph in project com.revolsys.open by revolsys.

the class CompareProcessor method processPartialMatch.

private void processPartialMatch(final Record sourceObject) {
    final Geometry sourceGeometry = sourceObject.getGeometry();
    if (sourceGeometry instanceof LineString) {
        final LineString sourceLine = (LineString) sourceGeometry;
        final LineIntersectsFilter intersectsFilter = new LineIntersectsFilter(sourceLine);
        final Predicate<Record> geometryFilter = new RecordGeometryFilter<>(intersectsFilter);
        final Predicate<Record> equalFilter = this.equalFilterFactory.apply(sourceObject);
        final Predicate<Record> filter = equalFilter.and(geometryFilter);
        final List<Record> otherObjects = this.otherIndex.queryList(sourceGeometry, filter);
        if (!otherObjects.isEmpty()) {
            final LineMatchGraph<Record> graph = new LineMatchGraph<>(sourceObject, sourceLine);
            for (final Record otherObject : otherObjects) {
                final LineString otherLine = otherObject.getGeometry();
                graph.add(otherLine);
            }
            final Lineal nonMatchedLines = graph.getNonMatchedLines(0);
            if (nonMatchedLines.isEmpty()) {
                removeObject(sourceObject);
            } else {
                removeObject(sourceObject);
                if (nonMatchedLines.getGeometryCount() == 1 && nonMatchedLines.getGeometry(0).getLength() == 1) {
                } else {
                    for (int j = 0; j < nonMatchedLines.getGeometryCount(); j++) {
                        final Geometry newGeometry = nonMatchedLines.getGeometry(j);
                        final Record newObject = Records.copy(sourceObject, newGeometry);
                        addSourceObject(newObject);
                    }
                }
            }
            for (int i = 0; i < otherObjects.size(); i++) {
                final Record otherObject = otherObjects.get(i);
                final Lineal otherNonMatched = graph.getNonMatchedLines(i + 1, 0);
                for (int j = 0; j < otherNonMatched.getGeometryCount(); j++) {
                    final Geometry newGeometry = otherNonMatched.getGeometry(j);
                    final Record newOtherObject = Records.copy(otherObject, newGeometry);
                    addOtherObject(newOtherObject);
                }
                removeOtherObject(otherObject);
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) RecordGeometryFilter(com.revolsys.record.filter.RecordGeometryFilter) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Record(com.revolsys.record.Record) LineMatchGraph(com.revolsys.geometry.algorithm.linematch.LineMatchGraph) LineIntersectsFilter(com.revolsys.geometry.filter.LineIntersectsFilter) Point(com.revolsys.geometry.model.Point)

Aggregations

LineMatchGraph (com.revolsys.geometry.algorithm.linematch.LineMatchGraph)1 LineIntersectsFilter (com.revolsys.geometry.filter.LineIntersectsFilter)1 Geometry (com.revolsys.geometry.model.Geometry)1 LineString (com.revolsys.geometry.model.LineString)1 Lineal (com.revolsys.geometry.model.Lineal)1 Point (com.revolsys.geometry.model.Point)1 Record (com.revolsys.record.Record)1 RecordGeometryFilter (com.revolsys.record.filter.RecordGeometryFilter)1