double SmallerOverlapExtractor::extract(const OsmMap& map, const ConstElementPtr& target,
  const ConstElementPtr& candidate) const
{
  ElementConverter ec(map.shared_from_this());
  shared_ptr<Geometry> g1 = ec.convertToGeometry(target);
  shared_ptr<Geometry> g2 = ec.convertToGeometry(candidate);

  if (g1->isEmpty() || g2->isEmpty())
  {
    return nullValue();
  }

  auto_ptr<Geometry> overlap;
  try
  {
    overlap.reset(g1->intersection(g2.get()));
  }
  catch (geos::util::TopologyException& e)
  {
    g1.reset(GeometryUtils::validateGeometry(g1.get()));
    g2.reset(GeometryUtils::validateGeometry(g2.get()));
    overlap.reset(g2->intersection(g1.get()));
  }

  double a1 = g1->getArea();
  double a2 = g2->getArea();
  double overlapArea = overlap->getArea();

  if (a1 == 0.0 || a2 == 0.0)
  {
    return 0.0;
  }

  return std::min(1.0, overlapArea / min(a1, a2));
}
double AbstractDistanceExtractor::combinedEnvelopeDiagonalDistance(const OsmMap& map,
  const boost::shared_ptr<const Element>& target, const boost::shared_ptr<const Element>& candidate) const
{
  ConstOsmMapPtr m = map.shared_from_this();
  boost::shared_ptr<Envelope> env(target->getEnvelope(m));
  boost::shared_ptr<Envelope> candidateEnv(candidate->getEnvelope(m));
  env->expandToInclude(candidateEnv.get());
  return sqrt(env->getWidth() * env->getWidth() + env->getHeight() * env->getHeight());
}
Ejemplo n.º 3
0
KnnWayIterator::KnnWayIterator(const OsmMap& map, ConstWayPtr way,
  const RStarTree* tree, const vector<long>& treeIdToWid, bool addError) :
  KnnIterator(tree, 0.0, 0.0, Box()),
  _map(map),
  _treeIdToWid(treeIdToWid)
{
  _wayId = way->getId();
  _ls = ElementConverter(map.shared_from_this()).convertToLineString(way);
  _lsFast = _ls.get();
  _indexSlush = _map.getIndex().getIndexSlush();
  _distanceCount = 0;
  _addError = addError;
  _baseAccuracy = way->getCircularError();
}
double HausdorffDistanceExtractor::distance(const OsmMap &map,
  const shared_ptr<const Element>& target, const shared_ptr<const Element> &candidate) const
{
  ElementConverter ec(map.shared_from_this());
  shared_ptr<Geometry> g1 = ec.convertToGeometry(target);
  shared_ptr<Geometry> g2 = ec.convertToGeometry(candidate);

  if (g1->isEmpty() || g2->isEmpty())
  {
    return nullValue();
  }

  return max(VertexHausdorffDistance(*g1, *g2).getDistance(),
    VertexHausdorffDistance(*g2, *g1).getDistance());
}
double WeightedShapeDistanceExtractor::_extract(const OsmMap& map, const ConstWayPtr& w1,
  const ConstWayPtr& w2) const
{
  return ProbabilityOfMatch::getInstance().parallelScore(map.shared_from_this(), w1, w2);
}
Ejemplo n.º 6
0
double LengthScoreExtractor::_extract(const OsmMap& map, const ConstWayPtr& w1,
                                      const ConstWayPtr& w2) const
{
  return ProbabilityOfMatch::getInstance().lengthScore(map.shared_from_this(), w1, w2);
}