Skip to contents

Extract longitude and latitude from string representing a geographical point in the format "POINT (longitude latitude) and converts it into a two-column tibble containing the longitude and latitude as numeric values. The names of the columns in the resulting tibble can be customized. The default names for the longitude and latitude columns are "Longitude" and "Latitude", respectively.

Usage

Text2Coords(String = NULL, Long_Name = "Longitude", Lat_Name = "Latitude")

Arguments

String

A string containing the coordinates in the format "POINT (longitude latitude)". This parameter is required and cannot be NULL.

Long_Name, Lat_Name

A string specifying the name to be used for the longitude and Longitude columns in the output tibble. Defaults to "Longitude" and "Latitude".

Value

A tibble with two columns containing the longitude and latitude values extracted from the input string. The names of these columns are determined by the Long_Name and Lat_Name parameters. If no names are provided, the default names ("Longitude" and "Latitude") are used.

two column tibble for Longitude & Latitude

Author

Ahmed El-Gabbas

Examples

c("POINT (11.761 46.286)", "POINT (14.8336 42.0422)",
  "POINT (16.179999 38.427214)") %>%
 lapply(Text2Coords)
#> [[1]]
#> # A tibble: 1 × 2
#>   Longitude Latitude
#>       <dbl>    <dbl>
#> 1      11.8     46.3
#> 
#> [[2]]
#> # A tibble: 1 × 2
#>   Longitude Latitude
#>       <dbl>    <dbl>
#> 1      14.8     42.0
#> 
#> [[3]]
#> # A tibble: 1 × 2
#>   Longitude Latitude
#>       <dbl>    <dbl>
#> 1      16.2     38.4
#> 

c("POINT (11.761 46.286)", "POINT (14.8336 42.0422)",
  "POINT (16.179999 38.427214)") %>%
 lapply(Text2Coords, Long_Name = "Long", Lat_Name = "Lat")
#> [[1]]
#> # A tibble: 1 × 2
#>    Long   Lat
#>   <dbl> <dbl>
#> 1  11.8  46.3
#> 
#> [[2]]
#> # A tibble: 1 × 2
#>    Long   Lat
#>   <dbl> <dbl>
#> 1  14.8  42.0
#> 
#> [[3]]
#> # A tibble: 1 × 2
#>    Long   Lat
#>   <dbl> <dbl>
#> 1  16.2  38.4
#>