Skip to content

10_prepare_shape_fields

mike edited this page May 4, 2018 · 1 revision

Maritimes/Mar.utils - Preparing Field Names for use in Shapefiles

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

prepare_shape_fields.r

Shapefiles are limited in the naming conventions of the fields - they can only be 10 characters, and must be devoid of special characters that are allowed in R. This function attempts to ensure that the shortened names that result from calls to writeOGR() can still be understood and are not simply truncated. In the example blow, you can see that the phrases following the periods dound in the original names are know to the script to be important, and are shortened and retained.

> names(df)
 [1] "EXTRANEOUSGARBAGE.COMBINED"    "EXTRANEOUSGARBAGE.CAUGHT"      "EXTRANEOUSGARBAGE.LICENSE"     "EXTRANEOUSGARBAGE.VESSEL"      "EXTRANEOUSGARBAGE.MARFIS"      "EXTRANEOUSGARBAGE.TEMPERATURE"
 [7] "EXTRANEOUSGARBAGE.BOTTOM"      "EXTRANEOUSGARBAGE.SURFACE"     "EXTRANEOUSGARBAGE.SALINITY"    "EXTRANEOUSGARBAGE.WEIGHT"      "EXTRANEOUSGARBAGE.DEPTH"      
> names(prepare_shape_fields(df))
 [1] "EXTRANCOMB" "EXTRANCGHT" "EXTRANELIC" "EXTRANEVES" "EXTRANMARF" "EXTRANTEMP" "EXTRANBOTT" "EXTRANSURF" "EXTRANESAL" "EXTRANEOWT" "EXTRANEDEP"
> 

Clone this wiki locally