Skip to content

Instantly share code, notes, and snippets.

View mtreg's full-sized avatar

Mike Treglia mtreg

View GitHub Profile
@mtreg
mtreg / postgis_raster_polygon_issue.txt
Created September 4, 2018 15:59
PostGIS Raster Polygon Overlay Issue
Related to GIS-StackExchange thread here: https://gis.stackexchange.com/questions/294482/error-quantifying-land-cover-classes-by-polygon-in-postgis?noredirect=1#comment473338_294482
@mtreg
mtreg / nyc_ortho_imagery_download.R
Created May 7, 2019 02:46
Automate download of orthoimagery tiles from NY GIS Clearinghouse via R
# Based on helpful example here: http://felixfan.github.io/download-files/
# Regular NY Download page here: http://gis.ny.gov/gateway/mg/2018/new_york_city/18ic_c_new_york_city_l06_4bd.htm
url = "ftp://ftp.gis.ny.gov/ortho/nysdop9/new_york_city/spcs/tiles/"
filenames = getURL(url, ftp.use.epsv = FALSE, dirlistonly = TRUE)
filenames <- strsplit(filenames, "\r\n")
filenames = unlist(filenames)
filenames
for (filename in filenames) {
@mtreg
mtreg / .block
Created May 23, 2019 20:59 — forked from timelyportfolio/.block
leaflet + plotly crosstalk no shiny
license: mit
@mtreg
mtreg / plotly_sunburst_challenge.R
Created August 7, 2019 00:36
Gist for post about how to go from regular dataframe in R to format needed for plotly sunburst
library(plotly)
# Create some fake data - say ownership and land use data with acreage
df <- data.frame(ownership=c(rep("private", 3), rep("public",3),rep("mixed", 3)),
landuse=c(rep(c("residential", "recreation", "commercial"),3)),
acres=c(108,143,102, 300,320,500, 37,58,90))
# Just try some quick pie charts of acreage by landuse and ownership
plot_ly(data=df, labels= ~landuse, values= ~acres, type='pie')
plot_ly(data=df, labels= ~ownership, values= ~acres, type='pie')
@mtreg
mtreg / gdbs_compile_layers.R
Created December 11, 2020 21:13
R code that aggregates data from different gdb files that is thematically the same, based on a prefix of layer names (defined by user), and standardizes to a user-defined coordinate reference system
############################################################
#' Compile layers from different gdb files with same, specified prefix, and desired coordinate system
#'
#' Compiles layers with standard prefix from multiple gdb files (specified by user) into single sf object.
#' This was originally developed to get respective layers from separate geodatabases that resulted from running the ACPF toolbox
#' into single layers (e.g., all stream reach datasets into one layer, rather than spread across many gdb files) but may have broader applicability.
#' (ACPF stands for Agricultural Conservaton Planning Framework; see https://acpf4watersheds.org/toolbox/)
#'
#' The handling of different projections is currently fairly crude - it just automatically reprojects files to the desired projection
#' (even if already in that projection), though that step is generally fairly quick.
@mtreg
mtreg / gpkg_lyr_from_ziparchive_zenodo.R
Created July 13, 2023 14:56
Load layer from gpkg in zipped folder within a Zenodo repository directly into R
# Example of loading data from gpkg in zipped folder on Zenodo into R
# Data from the repository 'The State of the Urban Forest in New York City - Supplemental Datasets'
# at https://zenodo.org/record/5210261
# Load sf package
library(sf)
# URL to Files on Zenodo
vurl <- "/vsizip//vsicurl/https://zenodo.org/record/5210261/files/canopy_streettree_summaries.zip/canopystreettree_supp.gpkg"
@mtreg
mtreg / test.md
Last active September 26, 2023 19:14
test for embedding webmap

test