Skip to content

Instantly share code, notes, and snippets.

View h-a-graham's full-sized avatar

Hugh Graham h-a-graham

View GitHub Profile
@mhweber
mhweber / explode.py
Created July 25, 2016 17:45 — forked from debboutr/explode.py
Explode MultiPolygon geometry into individual Polygon geometries in a shapefile using GeoPandas and Shapely
import geopands as gpd
from shapely.geometry.polygon import Polygon
from shapely.geometry.multipolygon import MultiPolygon
def explode(indata):
indf = gpd.GeoDataFrame.from_file(indata)
outdf = gpd.GeoDataFrame(columns=indf.columns)
for idx, row in indf.iterrows():
if type(row.geometry) == Polygon:
outdf = outdf.append(row,ignore_index=True)
@aubricus
aubricus / License
Last active May 17, 2024 21:09
Python Progress Bar
Copyright 2020 Aubrey Taylor
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTH
@rmania
rmania / geopandas_convert_geometry_3D_2D.py
Created March 13, 2017 21:06
flatten geometry series (3D to 2D) in geopandas dataframe
# Often when reading in a ShapeFile from Basemap, you'll get: "ValueError: readshapefile can only handle 2D shape types"
# A trick can be to convert your geometry in your GeoPandas Dataframe and restoring the new flattened 2D geometry
# series back into a shapefile and try again.
# edit from http://stackoverflow.com/questions/33417764/basemap-readshapefile-valueerror
from shapely.geometry import Polygon, MultiPolygon, shape, Point
import geopandas as gp
def convert_3D_2D(geometry):
'''
@kigiri
kigiri / aligning-images.md
Created September 18, 2018 09:11 — forked from DavidWells/aligning-images.md
Guide to aligning images in github readme.md files

Aligning images

left alignment

This is the code you need to align images to the left:

xx <- seq(2667400, length = ncol(volcano), by = 10)
yy <- seq(6478905, length = nrow(volcano), by = 10)
image(xx, yy, t(volcano[,ncol(volcano):1]), asp = 1)

Created on 2020-05-10 by the reprex package (v0.3.0)

@z3tt
z3tt / github.R
Last active May 23, 2024 08:35
Configure GitHub for Rstudio
#### 1. Sign up at GitHub.com ################################################
## If you do not have a GitHub account, sign up here:
## https://github.com/join
# ----------------------------------------------------------------------------
#### 2. Install git ##########################################################
## If you do not have git installed, please do so:
alos <- "/vsicurl/https://opentopography.s3.sdsc.edu/raster/AW3D30/AW3D30_global.vrt"
##eng_wales in Hugh's example (but I reduce the dimensions, for now)
g <- list(extent = c(82667.22, 655646.4, 5337.574, 657533.7), dimension = c(28575, 29006), projection = "EPSG:27700")
library(gdalio)
gdalio_set_default_grid(g)
source(system.file("raster_format/raster_format.codeR", package = "gdalio", mustWork = TRUE))
r <- gdalio_raster(alos)
@tylermorganwall
tylermorganwall / submarine_cable_map.R
Last active April 19, 2024 07:36
Submarine Cable Map Dataviz
library(geojsonsf)
library(sf)
library(rayrender)
#Data source: https://github.com/telegeography/www.submarinecablemap.com
cables = geojson_sf("cable-geo.json")
cablescene = list()
counter = 1
for(i in 1:length(cables$geometry)) {
  library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1
edge0 <- function(x, y, ndiscr = 18) {
  dx <- if(length(x) > 1) diff(x) else diff(y)
  sf::st_set_crs(sf::st_segmentize(sf::st_sfc(sf::st_linestring(cbind(x, y))), dx/ndiscr), 
               "OGC:CRS84")
}
north <- function(x = c(-180, 180), y = 90, ndiscr = 18) {
 edge0(x, y, ndiscr)  
@mdsumner
mdsumner / reprojecting-geotiff-zoom.md
Created December 7, 2021 12:45
py rasterio from an R user perspective