Skip to content

06_identify_area

mike edited this page May 4, 2018 · 1 revision

Maritimes/Mar.utils - Determining the Which Polygon a Point is in

May 2, 2018 - Mike McMahon (mike.mcmahon@dfo-mpo.gc.ca)

identifyArea.R

This function takes a df with coordinate fields in decimal degrees, and overlays it a shapefile (agg.poly.shp). It adds a column to the df indicating which polygon within the shapefile each point falls within. If no polygon is provided, the df will be assessed against NAFO subdivisions.

# initial data
> head(data)
     MISSION SETNO LATITUDE LONGITUDE TOTNO
3 ATC1970176    15 44.16667 -59.85000    41
4 ATC1970176    17 44.33333 -60.51667   560
5 ATC1970176     1 44.31667 -62.20000   947
6 ATC1970176    23 43.41667 -60.56667     7
7 ATC1970176    26 43.53333 -59.83333  3463
8 ATC1970176    28 43.65000 -59.30000   102

> #default uses NAFO Subdivisions
> head(identify_area(df=data))
     MISSION SETNO LATITUDE LONGITUDE TOTNO NAFO_BEST
3 ATC1970176    15 44.16667 -59.85000    41      <NA>
4 ATC1970176    17 44.33333 -60.51667   560       4WE
5 ATC1970176     1 44.31667 -62.20000   947       4WK
6 ATC1970176    23 43.41667 -60.56667     7       4WG
7 ATC1970176    26 43.53333 -59.83333  3463       4WG
8 ATC1970176    28 43.65000 -59.30000   102       4WG
>
> # but we can use custom shapefiles and fields too
> head(identify_area(df=data, agg.poly.shp = "/mnt/R_PED/Shared/Spatial/Science/Strata/ped_groundfish/MaritimesRegionEcosystemAssessmentStrata(2014-).shp",agg.poly.field = "StrataID"))
     MISSION SETNO LATITUDE LONGITUDE TOTNO StrataID
3 ATC1970176    15 44.16667 -59.85000    41      457
4 ATC1970176    17 44.33333 -60.51667   560      457
5 ATC1970176     1 44.31667 -62.20000   947      462
6 ATC1970176    23 43.41667 -60.56667     7      454
7 ATC1970176    26 43.53333 -59.83333  3463      497
8 ATC1970176    28 43.65000 -59.30000   102      453

Clone this wiki locally