ltog/osmi-addresses

Duplicated execution of code for distance calculation

Opened this issue · 0 comments

ltog commented

The code in

dist = linestring.Distance(&ogr_point);
and
void get_closest_node(
const OGRPoint& ogr_point,
const std::unique_ptr<OGRLineString>& closest_way,
std::unique_ptr<OGRPoint>& closest_node,
int& ind_closest_node) {
double min_dist = std::numeric_limits<double>::max();
double dist;
OGRPoint closest_node_candidate;
// iterate over all points of the closest way
for (int i=0; i<closest_way->getNumPoints(); i++){
closest_way->getPoint(i, &closest_node_candidate);
dist = ogr_point.Distance(&closest_node_candidate);
if (dist < min_dist) {
min_dist = dist;
ind_closest_node = i;
}
}
closest_way->getPoint(ind_closest_node, closest_node.get());
does about the same. The OGR function however doesn't return the closes node (or point).

This duplicated calculation should be removed.

Coordinates should maybe converted to Pseudo-Mercator.