get_centroid: Get a centroid from WKT or geojson

Description Usage Arguments Value Examples

View source: R/get_centroid.R

Description

Get a centroid from WKT or geojson

Usage

1

Arguments

x

Input, a wkt character string or geojson class object

Value

A length 2 numeric vector, with longitude first, latitude second

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# WKT
str <- "POINT (-116.4000000000000057 45.2000000000000028)"
get_centroid(str)
str <- 'MULTIPOINT ((100.000 3.101), (101.000 2.100), (3.140 2.180))'
get_centroid(str)
str <- "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),
 ((20 35, 45 20, 30 5, 10 10, 10 30, 20 35), (30 20, 20 25, 20 15, 30 20)))"
get_centroid(str)

# Geojson as geojson class
str <- "POINT (-116.4000000000000057 45.2000000000000028)"
get_centroid(wkt2geojson(str))
str <- 'MULTIPOINT ((100.000 3.101), (101.000 2.100), (3.140 2.180))'
get_centroid(wkt2geojson(str))
str <- "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),
 ((20 35, 45 20, 30 5, 10 10, 10 30, 20 35), (30 20, 20 25, 20 15, 30 20)))"
get_centroid(wkt2geojson(str))

Example output

Attaching package: 'wellknown'

The following object is masked from 'package:graphics':

    polygon

[1] -116.4   45.2
       [,1]  [,2]
[1,] 100.00 3.101
[2,] 101.00 2.100
[3,]   3.14 2.180
[1] 30.00000 28.33333
[1] -116.4   45.2
       [,1]  [,2]
[1,] 100.00 3.101
[2,] 101.00 2.100
[3,]   3.14 2.180
[1] 30.00000 28.33333

wellknown documentation built on May 26, 2021, 1:06 a.m.