Package com.vividsolutions.jcs.conflate.polygonmatch

Source Code of com.vividsolutions.jcs.conflate.polygonmatch.AbstractDistanceMatcher

package com.vividsolutions.jcs.conflate.polygonmatch;

import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import java.awt.geom.Point2D;

public abstract class AbstractDistanceMatcher extends IndependentCandidateMatcher {
    protected double maxDistance = 0;
   
    @Override
    public double match(Geometry target, Geometry candidate) {
        double distance = distance(target, candidate);
        if (maxDistance > 0) {
            return Math.max(0, 1 - (distance / maxDistance));
        } else {
            return 1
                    - (distance
                    / combinedEnvelopeDiagonalDistance(target, candidate));
        }
    }

    protected abstract double distance(Geometry target, Geometry candidate);

    private double combinedEnvelopeDiagonalDistance(
        Geometry target,
        Geometry candidate) {
        Envelope envelope = new Envelope(target.getEnvelopeInternal());
        envelope.expandToInclude(candidate.getEnvelopeInternal());
        return Point2D.distance(
            envelope.getMinX(),
            envelope.getMinY(),
            envelope.getMaxX(),
            envelope.getMaxY());
    }

    public void setMaxDistance(double maxDistance) {
        if (maxDistance < 0)
            this.maxDistance = 0;
        else
            this.maxDistance = maxDistance;
    }
}
TOP

Related Classes of com.vividsolutions.jcs.conflate.polygonmatch.AbstractDistanceMatcher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.