I have two content types - assets and regions.
Assets have point locations.
Regions have a polygon 'location'.

As assets are added I would like to assign tags to these assets based upon the region it lies within. Ultimately I want to create entity_relationships from the asset to the region for quick use.

I would also like to query for assets by identifying a specific region (a spacial search).

Does anyone know if this is possible with modules & hacks already available and could provide a recipe? Or perhaps they could point me in the right direction?

Thanks!

Comments

Exploratus’s picture

Did you ever get an answer to this? Very interested. WOuld love to get nodes within a polygon of another node using views.

stopshinal’s picture

Nope - not yet.

stopshinal’s picture

Bump

Brandonian’s picture

Great question, @stopshinal. In order to do spatial queries with Geofield, you'll need to do the following, some of which will take some custom coding. Also, you'll need to use a PostGIS enabled Postgres database for your site's database.

1. Make sure you're using Geofield 2.x
2. Download https://github.com/phayes/geofield_postgis, which provides a PostGIS backend for geofield. I can't guarantee it's completely functional at this point, but I don't think we've modified anything that would break it at this point.
3. You'll need to manually query the database yourself for the intersection. You'll likely use something like http://postgis.refractions.net/documentation/manual-1.4/ST_Contains.html to do the actual query.

Hope this helps! This is an area (geospatial analysis) that I would actually love to have some extra help with in fleshing out better contrib tools for Geofield if you're interested.

stopshinal’s picture

Brandonian - Thanks for these directions! I wrote this off a while ago as too much to expect, but I see it's not so distant!

I'm coming into this with alot of interest but zero experience. For instance, here is my birds eye view of what I want to do - might you be able to reign this in a bit as I begin the discovery process?

I'd like to use views for it's display flexibility

Thinking about a large dataset - my initial thought was to build a proximity query off the polygon centroid and quickly gather nodes that could potentially lie within the polygon. I'm not up on processing - but would this step save any resource use? Otherwise it could be skipped and instead just jump right into Step 2.

Step 2 would then simply involve comparing these remaining nodes to the polygon with ST_Cointains. Those that return true are the winners.

As I said - i'm not up on Views, but I'm presuming this will all be possible as I dive in.

stopshinal’s picture

Using Pantheon for hosting prohibits the use of postGIS - could there be another solution?

held69’s picture

Aldus’s picture

Issue summary: View changes

Keeping it open, is anyone aware of some solution for displaying all nodes with a geofield point that is inside a given polygon (contextual argument in views), without changing database or such?

robertwb’s picture

hey @Aldus - this sandbox module (that I will repackage as a geofield plugin/sub-module soon) will do this. It supports a full range of spatial operators (within, contains, crosses, intersects).

https://www.drupal.org/sandbox/robertwb/2202159