Geofield Proximity to Polygon
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
Geofield Proximity to Polygons for Views
An add-on for the Geofield module to calculate distances from an origin point to polygons and multi-polygons in Views on single-valued and multi-valued Geofields.
Note: if your View only contains Geofield fields that hold single points (as opposed to polygons), then you do not need this module, as Geofield already has built-in proximity fields, filters and sorts for points. It also has a definition for the distance from an origin point to a polygon, but it is different from the rule this module uses.
The module employs the following rule:
if the origin/reference point is inside the polygon or one of the polygons that are part of the multi-polygon or multi-valued field, then zero is returned; otherwise the result is the distance to the closest vertex (corner point).
Automatically converts Geofield proximity fields, filters and sorts to exhibit the above behaviour.
No configuration. Just select as per normal, the Geofield proximity field, filter or sort in your View and the module does the rest.
References
- This module's PHP implementaton of a point-in-polygon algorithm was adapted from the C-code provided in "Point Inclusion in Polygon Test"
Copyright © 1970-2003, Wm. Randolph Franklin - The formula employed for the calculation of distances over the surface of the globe is the same in both Geofield and in this module, using the spherical law of cosines, which is equivalent to the haversine formula. See for instance "Calculate distance, bearing and more between Latitude/Longitude points".
Tip
When you use multi-valued geofields on a map, for example a Leaflet map, under the Multiple Field Settings of the Views UI configuration panel for the field, tick the box Display all values in the same row. When you use mutli-valued geofields in a table and you wish to see distances for each polygon that is part of the geofield, untick that same box.
Suggestions for extensions, roadmap
- extend module to also include distance calculations to linestrings and multi-linestrings
- improve algorithm to return distance to closest vertex or edge, whichever is closest
- point-in-polygon calculation is based on a flat coordinate system of latitude/longitude, but distance calculation takes curvature of the earth into account; address discrepancies that may occur for very wide geometries
