Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Mar 27, 2024
1 parent fc053b0 commit 9a2671c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
9 changes: 6 additions & 3 deletions SSA-complexity/entropy-by-mukey.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
-- Just some notes, this is done automatically on SoilWeb with each refresh
--
--



-- Compute Shanon Entropy via component percentages by map unit KEY
--
--

-- Data are saved to csv.gz for now, no permanent place in SoilWeb


--
-- Of course we don't need to use area... because we are talking about proportions
--
Expand Down
19 changes: 18 additions & 1 deletion SSA-complexity/polygon-complexity-analysis-full.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ library(latticeExtra)
library(hexbin)
library(tactile)

x <- fread(file = 'mu-polygon-complexity.txt.gz', header = FALSE, showProgress = TRUE, stringsAsFactors = FALSE, verbose = TRUE)
# giant file
# no headers
x <- fread(file = 'mu-polygon-complexity.txt.gz', sep = '|', header = FALSE, showProgress = TRUE, stringsAsFactors = FALSE, verbose = TRUE)

# column names from inspection of original SQL query
head(x)
names(x) <- c('areasymbol', 'ogc_fid', 'mukey', 'fd', "log_sq_m", "n_pts", "invesintens", "coryear", "projectscale")

Expand All @@ -16,6 +19,20 @@ names(x) <- c('areasymbol', 'ogc_fid', 'mukey', 'fd', "log_sq_m", "n_pts", "inve
## -> consider filtering on vertex count
summary(x)

quantile(x$fd, probs = c(0.01, 0.99))
quantile(x$n_pts, probs = c(0.01, 0.99))
quantile(x$log_sq_m, probs = c(0.01, 0.99))

x[x$fd > 1.2 & x$log_sq_m > 10, ]

x[x$fd > 1.6, ]

x[x$n_pts < 5, ]

z <- x[x$n_pts > 100000, ]

soilDB::format_SQL_in_statement(z$ogc_fid)


## flag wacky polygons

Expand Down
35 changes: 31 additions & 4 deletions SSA-complexity/ssurgo-polygon-complexity.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
-- http://www.umass.edu/landeco/research/fragstats/documents/Metrics/Shape%20Metrics/Metrics/P9%20-%20FRAC.htm

-- Just some notes, this is done automatically on SoilWeb with each refresh
--
-- TODO: turn this into a parallel evaluation by areasymbol, save to new table
--



-- http://www.umass.edu/landeco/research/fragstats/documents/Metrics/Shape%20Metrics/Metrics/P9%20-%20FRAC.htm


SET search_path TO ssurgo, public;


Expand Down Expand Up @@ -230,4 +232,29 @@ ORDER BY fd DESC;
la075 | 1598653 | 12391751 | 1.30658553466144 | -89.7032856849138 | 29.3826119763685


-- ...

-- polygons with >100k vertices

SELECT areasymbol, mukey, ogc_fid,
( 2.0 * LN(0.25 * ST_Perimeter(wkb_geometry::geography)) ) / ( LN(ST_Area(wkb_geometry::geography)) ) AS fd,
ST_X(ST_PointOnSurface(wkb_geometry)), ST_Y(ST_PointOnSurface(wkb_geometry))
FROM ssurgo.mapunit_poly
WHERE ogc_fid IN ('6739046','7891209','17981002','20634415','20634252','21280440','21242820','21452139','21468805','21508411','25375620')
ORDER BY fd DESC;


areasymbol | mukey | ogc_fid | fd | st_x | st_y
------------+---------+----------+------------------+-------------------+------------------
oh161 | 2903473 | 25375620 | 1.48305886985374 | -84.5110824199522 | 40.848120713261
il019 | 242963 | 7891209 | 1.47047486606985 | -88.452415136349 | 40.0320937879904
ms029 | 567699 | 17981002 | 1.42649188601696 | -90.2934305588956 | 31.8202510102259
ia149 | 410340 | 6739046 | 1.39709339429339 | -95.9715033845025 | 42.7300941524345
nd019 | 3247674 | 20634252 | 1.39499739452672 | -98.856592183264 | 48.8431911123622
nd019 | 3247668 | 20634415 | 1.38967408635277 | -98.8046499406376 | 48.6615760313598
nd071 | 3247731 | 21242820 | 1.37048142153142 | -98.6269887653126 | 48.4876287436918
nd095 | 3247779 | 21508411 | 1.36807589479736 | -99.0060505782068 | 48.8928800252627
nd095 | 3247779 | 21468805 | 1.3668135990079 | -99.1801156615694 | 48.6998064541954
nd095 | 3247773 | 21452139 | 1.36645454839058 | -99.3420605643792 | 48.7256120470916
nd079 | 3247758 | 21280440 | 1.36126077977161 | -99.5978656882635 | 48.7089659658405


0 comments on commit 9a2671c

Please sign in to comment.