Comments (4)
Thanks for posting and for the code! Honestly I hadn't given data type conversions much thought before now, but that's something I should definitely add - I'll make an issue for it so that I remember to add it at some point. It'd definitely be nice to have a function that just converts it to an sf
object.
I've fiddled around with your code - I'm not all that familiar with sf
or wk
, but I was able to modify your code to use data.table
to create the rectangles, and it seems to run considerably faster:
library(soilDB)
library(sf)
library(wk)
library(data.table)
library(quadtree)
# make a bounding box and assign a CRS (4326: GCS, WGS84)
a.CA <- st_bbox(
c(xmin = -2280334, xmax = -2065433, ymin = 1755361, ymax = 1970262),
crs = st_crs(5070)
)
# convert bbox to sf geometry
a.CA <- st_as_sfc(a.CA)
pH_3060cm <- ISSR800.wcs(aoi = a.CA, var = 'ph_3060cm')
plot(pH_3060cm, axes = FALSE, xlab = '', ylab = '')
qt <- quadtree(pH_3060cm, split_threshold = 0.25, split_method = "sd", adj_type = "resample", resample_n_side = 128)
dt <- data.table(as_data_frame(qt))
cr <- st_crs(5070)
bbs_list <- dt[, list(bb = st_as_sf(rct(xmin, ymin, xmax, ymax, cr)))]$bb
bbs <- st_as_sf(bbs_list)
plot(bbs)
I ran a quick benchmark on it, and it was taking 163ms on my machine. So give that a shot and see if it works for you.
from quadtree.
Thanks! Your code is much faster / elegant that the hack I posted. It scales nicely too. Just tried all of the lower '48. About 5 seconds from start to finish!
What do you think about splitting categorical rasters based on Shannon entropy?
from quadtree.
That's not something I'm very familiar with... looks like it's an index for the variation in categorical data - is that correct? So the idea would be to split a quadrant if the variation is above some threshold - otherwise you'd assign the most common category to the cell? Am I interpreting that correctly?
It'd definitely be nice to add more support for categorical data. My use case for creating the package was entirely with continuous rasters, so I didn't give any thought to categorical data when writing the code. If that's something you think would be a useful addition I could certainly add an option for splitting based on the Shannon entropy - I don't think it'd be too difficult. That being said, I don't have a plethora of spare time these days (and won't for the next several months) so I can't guarantee that I'd get to it in a timely fashion - but I can certainly add it to the to-do.
For what it's worth, you should be able create a custom function that implements the Shannon entropy. You can write functions to define your own rules for splitting cells - see this section of the "Creating Quadtrees" vignette. You'd also need to write a custom "combine" function as well to pick the most common category.
from quadtree.
Functionality added in PR #17
from quadtree.
Related Issues (17)
- Migrate issues from GitLab to GitHub
- Create quadtrees from lines/polygons/points HOT 1
- Make Quadtree more space-efficient
- Arithmetic operations between quadtrees
- Manual splitting/merging of quadtree cells
- More support for binary quadtrees (in particular, set operations)
- Make 'quadtree' compatible with 'terra' HOT 2
- LCP finder finds wrong path
- LCP sometimes returns inconsistent results HOT 1
- 'ticks' parameter of 'add_legend' doesn't work correctly
- plot(<Quadtree>): legend doesn't show when alpha is small
- Add functions for data type conversions HOT 1
- as_raster() doesn't work for single cell quadtrees HOT 1
- Convert all `raster` functionality to `terra` HOT 4
- errors with raster-dev HOT 4
- quadtree from multi-band grid
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quadtree.