Giter Site home page Giter Site logo

nf's Introduction

New approach for gris.

## we expect that these attributes, taken together are "unique vertices" potentially shared by neighbours
v_atts <- c("x_", "y_")

library(spbabel) ## devtools::install_github("mdsumner/spbabel")
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
source("R/grist.r")
#library(maptools)
#data(wrld_simpl)
#install.packages("rworldxtra")
library(rworldxtra)
#> Loading required package: sp
data(countriesHigh)
library(dplyr)
#x <- gris2(wrld_simpl)
x <- gris2(countriesHigh)
verts <- with(x, o %>% filter(NAME == "Japan") %>% select(object_) %>% inner_join(b) %>% inner_join(bXv) %>% inner_join(v))
#> Joining by: "object_"
#> Joining by: "branch_"
#> Joining by: "vertex_"
library(ggplot2)
ggplot(verts) + aes(x = x_, y = y_, fill = branch_, group = branch_) + geom_polygon()

## say we add the segments, then subset
x$s <- grist(x)
xa <- list(o =x$o %>% filter(NAME == "Japan"))
xa$b <- inner_join(x$b, xa$o %>% select(object_))
#> Joining by: "object_"
xa$bXv <- inner_join(x$bXv, xa$b %>% select(branch_))
#> Joining by: "branch_"
xa$v <- inner_join(x$v, xa$bXv %>% select(vertex_)) %>% distinct()
#> Joining by: "vertex_"
xa$s <- inner_join(x$s, xa$b %>% select(branch_))
#> Joining by: "branch_"

verts <- with(xa, o %>% select(object_) %>% inner_join(b) %>% inner_join(bXv) %>% inner_join(v))
#> Joining by: "object_"
#> Joining by: "branch_"
#> Joining by: "vertex_"
library(ggplot2)
ggplot(verts) + aes(x = x_, y = y_, fill = branch_, group = branch_) + geom_polygon()

tr <- RTriangle::triangulate(p = RTriangle::pslg(xa$v %>% dplyr::select(x_, y_) %>% as.matrix(), 
                                                 S = seg2struct(xa) %>% as.matrix()),                                               a = 0.1)

plot(tr$P, pch = ".")
apply(tr$T, 1, function(a) lines(tr$P[a, ]))

#> NULL

nf's People

Contributors

mdsumner avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.