r - Parse JSON to a dataframe -


not sure how this:

i have stored (in a):

[   "multipolygon (((-95.0000000372529 40.999989970587194, -94.5000000372529 40.999989970587194, -94.5000000372529 40.499989970587194, -95.0000000372529 40.499989970587194)))" ]  typeof(a) # prints "character" class(a)  # prints "json" 

and convert data.frame looks (no need round numbers, easier type that)

  x1  x2 1 -95 40 2 -94 40 3 -94 40 4 -95 40 

i tried

a.df<-as.data.frame(as.matrix(a)) 

but prints

 v1 1 [\n  "multipolygon (((-95.0000000372529 40.999989970587194, -94.5000000372529 40.999989970587194, -94.5000000372529 40.499989970587194, -95.0000000372529 40.499989970587194)))"\n]\n 

library(sf) library(jsonlite) library(tidyverse)  x <- fromjson('[   "multipolygon (((-95.0000000372529 40.999989970587194, -94.5000000372529 40.999989970587194, -94.5000000372529 40.499989970587194, -95.0000000372529 40.499989970587194)))" ]')  map(x, st_as_sfc) %>%   map(~as.data.frame(.[[1]][[1]])) ## [[1]] ##      x1       x2 ## 1 -95.0 40.99999 ## 2 -94.5 40.99999 ## 3 -94.5 40.49999 ## 4 -95.0 40.49999 

now:

wkt2geojson('[   "multipolygon (((-95.0000000372529 40.999989970587194, -94.5000000372529 40.999989970587194, -94.5000000372529 40.499989970587194, -95.0000000372529 40.499989970587194)))" ]') 

also kinda works tosses warnings.

knowing actual source created wkt in such configuration wld helpful


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -