Store values based on geographic data calculation (which polygon is a point within?)

This page summarizes the projects mentioned and recommended in the original post on /r/drupal

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • php-polylabel

    PHP port of https://github.com/mapbox/polylabel

  • So this is something doable, but I'd say it required some advanced drupal chops and a few prior geo/mapping skills to know what each module does and how they work with each other. I have done this kinda thing since Drupal 6 and it still took me a few weeks of work to go from a few CSVs to a beautiful map with facets, per type styled polygons/points with nice labels, clustering, infowindows...

  • js-markerwithlabel

    Google Maps Marker with Label

  • So this is something doable, but I'd say it required some advanced drupal chops and a few prior geo/mapping skills to know what each module does and how they work with each other. I have done this kinda thing since Drupal 6 and it still took me a few weeks of work to go from a few CSVs to a beautiful map with facets, per type styled polygons/points with nice labels, clustering, infowindows...

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • GeoTools

    Geo-related tools PHP 7.3+ library built atop Geocoder and React libraries (by thephpleague)

  • // Loop on all loaded zones_entities /* @var $zone_geofield \Drupal\geofield\Plugin\Field\FieldType\GeoFieldItem */ $zone_geofield = $your_zone_entity->get('field_your_geofield')->getValue(); /* @var \Drupal\geofield\GeoPHP\GeoPHPInterface $geo_php_wrapper */ $geo_php_wrapper = \Drupal::service('geofield.geophp'); // or inserted via DI /* @var \Geometry$polygon*/ $polygon = $geo_php_wrapper->load($zone_geofield->value); /* @var $entity_geofield \Drupal\geofield\Plugin\Field\FieldType\GeoFieldItem */ $entity_geofield = $your_current_entity->get('field_your_geofield')->getValue(); $point = $geo_php_wrapper->load($entity_geofield->value); if( geoPHP::geosInstalled() ) { $in_zone = $polygon->contains($point); } else { // https://github.com/thephpleague/geotools#polygon $geotools_polygon = new \League\Geotools\Polygon\Polygon( $polygon->asArray() ); $geotools_point = \League\Geotools\Coordinate\Coordinate( $point->asArray() ); $in_zone = $geotools_polygon->pointInPolygon( $geotools_point ); } if( $in_zone ) { // Do things like filling a reference field $entity->set('field_ref_' . $your_zone_entity->bundle()', $your_zone_entity->id() ); }

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts