0

I have two polygon shapefiles, one of mine sites and one of parks. I've clipped one layer so that only mines within the park boundaries are shown. However, I want to take an attribute from the parks layer (park name) and add it into the mine layer so that when I export the table to excel it will show which park the mine is in. I can't merge the attribute tables because I need the park name to line up with the correct mine.

How do I copy the attributes from the Park layer to the Mine layer based on location?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338

1 Answers1

1

You can import your data to postgis via shp2pgsql

Then you can use an intersection sql like:

*Update mine set your_column =k.park_name
From park as k
Where intersects(st_pointonsurface(mine.the_geom),k.the_geom) and st_pointonsurface(mine.the_geom)&&k.the_geom*

Or you can use simple intersection. Note that intersection function return true even geometrically touches. So you can use additional criteria like area intersection.

*update mine set your_column= k.park_name
 from park as k 
where intersects(mine.the_geom, k.the_geom) 
and mine.the_geom&&k.the_geom
--and area(intersection(mine.the_geom,k.the_geom))> your_value*