aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2019-08-15 17:50:17 +0100
committerDave Arter <davea@mysociety.org>2019-08-16 14:25:13 +0100
commitb46e26d2610534c84ba95fff21fb78dd30125904 (patch)
tree00b88dd14f60d2d4bd31f54e1652e8e0f21e366c
parentb45dec26710e83aed051f4eebc2b0d3b80ff525a (diff)
[UK Councils] Allow lookup_site_code to handle Point geometries
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm15
1 files changed, 12 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index a95e0f997..c245ef1c6 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -329,16 +329,25 @@ sub _nearest_feature {
my $site_code = '';
my $nearest;
+ # We shouldn't receive anything aside from these geometry types, but belt and braces.
+ my $accept_types = $cfg->{accept_types} || {
+ LineString => 1,
+ MultiLineString => 1
+ };
+
for my $feature ( @{$features || []} ) {
next unless $cfg->{accept_feature}($feature);
-
- # We shouldn't receive anything aside from these two geometry types, but belt and braces.
- next unless $feature->{geometry}->{type} eq 'MultiLineString' || $feature->{geometry}->{type} eq 'LineString';
+ next unless $accept_types->{$feature->{geometry}->{type}};
my @linestrings = @{ $feature->{geometry}->{coordinates} };
if ( $feature->{geometry}->{type} eq 'LineString') {
@linestrings = ([ @linestrings ]);
}
+ # If it is a point, upgrade it to a one-segment zero-length
+ # MultiLineString so it can be compared by the distance function.
+ if ( $feature->{geometry}->{type} eq 'Point') {
+ @linestrings = ([ [ @linestrings ], [ @linestrings ] ]);
+ }
foreach my $coordinates (@linestrings) {
for (my $i=0; $i<@$coordinates-1; $i++) {