This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Overview | |
You have two github repositories linked to your blog. | |
- blog-source > root dir of blog, contains all pelican conf and output | |
- underchemist.github.io > only the contents of output/ | |
# Writing and building locally | |
## fabric | |
The fabfile.py in the root of blog-source has a bunch of helper functions to aid with development. | |
- fab build > uses pelicanconf.py for config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rem Assumes visual studio build tools installed | |
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat | |
conda activate <env name> | |
conda install -c conda-forge gdal | |
rem Uninstalling pre-installed python bindings to show that we can compile ourselves | |
pip uninstall gdal | |
rem Set environment variables | |
set INCLUDE=C:\<conda install location>\envs\<env name>\Library\include;%INCLUDE% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conda create -n gdal242 python=3.7 | |
conda activate gdal242 | |
conda install -c gdal==2.4.2 | |
# from source with pip (MSVC build tools required) | |
git clone https://github.com/mapbox/rasterio.git | |
cd clone rasterio | |
set GDAL_VERSION=2.4.2 | |
# if you have a newer conda you can use %CONDA_PREFIX% | |
# note: --no-use-pep517 seems to be required as a workaround |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires rasterio, fiona, geojsonio-cli (npm or python clone) | |
rio bounds --feature *.tif | fio collect | geojsonio | |
# alternative | |
# find /path/to/some/dir -name "*.tif" -exec rio bounds --feature {} \; | fio collect | geojsonio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set CURL_CA_BUNDLE=C:\path\to\cert # for some reason this alone is not enough | |
set GDAL_HTTP_UNSAFESSL=YES | |
# get aws credentials i.e. through okta-awscli | |
gdalinfo /vsis3/bucket/key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Segmentize an input shapely polygon | |
For an input polygon, generate a new polygon composed of n points | |
interpolated along the linear geometry of each vertex of the input | |
polygon | |
""" | |
import numpy as np | |
import shapely | |
import shapely.geometry | |
import shapely.ops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LINEAR_GEOMS = (shapely.geometry.LineString, shapely.geometry.LinearRing) | |
VALID_GEOMS = (*LINEAR_GEOMS, shapely.geometry.Polygon) | |
def linspace(start, stop, n): | |
assert n >= 0 | |
try: | |
step = (stop - start) / (n-1) | |
except ZeroDivisionError: | |
step = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import product, chain | |
def block_windows(src, xsize, ysize): | |
height, width = src.shape | |
nrows, rmod = divmod(height, ysize) | |
ncols, cmod = divmod(width, xsize) | |
offsets = product(range(0, width, xsize), range(0, height, ysize)) | |
sizes = product(chain([xsize]*ncols, [cmod]), chain([ysize]*nrows, [rmod])) | |
for (xoff, yoff), (xsize, ysize) in zip(offsets, sizes): | |
yield xoff, yoff, xsize, ysize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from osgeo import gdal | |
import joblib | |
from itertools import cycle, product, chain | |
from more_itertools import ichunked | |
import time | |
import os | |
SRC = 'RS2_OK76385_PK678064_DK606753_F2N_20080419_142127_HH_HV_SLC/RS2_OK76385_PK678064_DK606753_F2N_20080419_142127_HH_HV_SLC' | |
def block_windows(src, xsize, ysize): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from osgeo import gdal, osr | |
driver = gdal.GetDriverByName("GTiff") | |
src = driver.Create('/vsimem/test.tif', 32, 32, 1) | |
srs = osr.SpatialReference() | |
srs.ImportFromEPSG(4326) | |
src.SetGCPs((gdal.GCP(0, 0, 0, 0, 0),), srs) | |
dst = gdal.Translate('/vsimem/test.vrt', src) | |
print(dst.GetMetadata('xml:vrt')) |
OlderNewer