Skip to content

Instantly share code, notes, and snippets.

View palmerj's full-sized avatar

Jeremy Palmer palmerj

  • Toitū The Whenua Land Information New Zealand
  • Wellington, New Zealand
View GitHub Profile
@palmerj
palmerj / mvt_qgis.md
Last active February 20, 2018 02:03
View Vector Tiles in QGIS using GDAL/OGR 2.3

Create mapbox vectors using OGR

Get NZ parcels data over Auckland region in SHP: https://data.linz.govt.nz/x/CLzEZU

Generate vector tiles

ogr2ogr -f MBTILES parcels.mbtiles nz-primary-parcels.shp -dsco MAXZOOM=14
@palmerj
palmerj / parcels.vrt
Created February 18, 2018 23:35
GDAL mbtiles vector tile VRT
<OGRVRTDataSource>
<Metadata domain="IMAGE_STRUCTURE">
<MDI key="INTERLEAVE">PIXEL</MDI>
</Metadata>
<Metadata>
<MDI key="name">parcels</MDI>
<MDI key="format">pbf</MDI>
<MDI key="center">174.6325388,-36.9883061,0</MDI>
<MDI key="ZOOM_LEVEL">14</MDI>
<MDI key="bounds">174.1821636,-37.3637475,175.0829141,-36.6128647</MDI>
@palmerj
palmerj / TileMatrixSet.xml
Created February 5, 2018 00:08
Geoserver WMTS capabilities TileMatrix for NZTM2000
<TileMatrixSet>
<ows:Identifier>NZTM2000</ows:Identifier>
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::2193</ows:SupportedCRS>
<TileMatrix>
<ows:Identifier>0</ows:Identifier>
<ScaleDenominator>3.2000000000000004E7</ScaleDenominator>
<TopLeftCorner>-1000000.0 1.226204E7</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>2</MatrixWidth>
@palmerj
palmerj / gist:e293b443def642431f05775aa4d7f640
Last active March 11, 2025 09:44
One liner to get AWS S3 IP address ranges for ap-southeast-2 (Sydney)
curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes' | jq 'map(select(.region=="ap-southeast-2"))' | jq 'map(select(.service=="S3"))' | jq 'map(.ip_prefix)'
@palmerj
palmerj / histogram.sql
Created January 28, 2018 04:28
SQLite3 - Generate histogram using date ranges and ASCII bar
-- On MacOSX installed SQLite3 to get log function support
-- brew reinstall sqlite3 --with-functions
SELECT load_extension('/usr/local/opt/sqlite/lib/libsqlitefunctions');
SELECT
DR.start_datetime as date,
COUNT(*) AS total,
replace(substr(quote(zeroblob((log(COUNT(*)) + 1) / 2)), 3, log(COUNT(*))), '0', '*') AS bar
FROM
@palmerj
palmerj / date_ranges.sql
Last active January 28, 2018 00:32
SQLite3 - Generate date time ranges using SQL recursive query
DROP TABLE IF EXISTS date_ranges;
CREATE TEMP TABLE date_ranges (start_datetime DATETIME);
WITH RECURSIVE
date_ranges(start_datetime) AS (
VALUES('2011-05-01 00:00:00')
UNION ALL
SELECT datetime(start_datetime, '+1 month')
FROM date_ranges WHERE start_datetime < datetime('now', '-1 month')
)
@palmerj
palmerj / libecwj2-3.3.patch
Created January 21, 2018 23:23
Patch to support building the libecwj2 library on MacOSX based on https://trac.osgeo.org/gdal/attachment/wiki/ECW/libecwj2-3.3.patch
diff --git a/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp b/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp
index 12a0cce..8747b24 100644
--- a/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp
+++ b/Source/C/NCSEcw/NCSJP2/NCSJPCResolution.cpp
@@ -1773,10 +1773,10 @@ bool CNCSJPCResolution::SD_2D_OUTPUT4(ContextID nCtx,
//Step0-1 == 2State.
//
- UINT32 n = 0;
+ INT32 n = 0;
@palmerj
palmerj / gdal2_env.sh
Last active February 18, 2018 19:31
Python Environment setup for brew GDAL2 on MacOSX with GDAL framework installed as well (i.e no brew link)
export PATH="$(brew --prefix)/opt/python/libexec/bin:$(brew --prefix)/opt/gdal2/bin:$(brew --prefix)/opt/gdal2-python/bin:$PATH"
export PYTHONPATH=$(brew --prefix)/lib/python2.7/site-packages:$(brew --prefix)/opt/gdal2-python/lib/python2.7/site-packages/:$PYTHONPATH
@palmerj
palmerj / get_centroid.bash
Last active December 20, 2017 04:47
OGR Create JSON centroid for labelling
ogr2ogr -f GeoJSON labels.json WFS:"https://data.linz.govt.nz/services;key=$LDS_API_KEY/wfs/layer-51572" -dialect sqlite -sql 'SELECT id, lease_name AS name, ST_Centroid(geometry) from "data.linz.govt.nz:layer-51572"' -lco COORDINATE_PRECISION=4 -t_srs "EPSG:4326"
@palmerj
palmerj / error.log
Created November 5, 2017 02:46
error.log
[4464/4581] cd /tmp/qgis3-dev-20171105-58465-16mcu7o/build/python/plugins/db_manager/db_plugins/spatialite && /usr/local/bin/pyrcc5 -name /tmp/qgis3-dev-20171105-58465-16mcu7o/build/python/plugins/db_manager/db_plugins/spatialite/resources_rc.py -o /tmp/qgis3-dev-20171105-58465-16mcu7o/build/python/plugins/db_manager/db_plugins/spatialite/resources_rc.py /tmp/qgis3-dev-20171105-58465-16mcu7o/python/plugins/db_manager/db_plugins/spatialite/resources.qrc
FAILED: python/plugins/db_manager/db_plugins/spatialite/resources_rc.py
cd /tmp/qgis3-dev-20171105-58465-16mcu7o/build/python/plugins/db_manager/db_plugins/spatialite && /usr/local/bin/pyrcc5 -name /tmp/qgis3-dev-20171105-58465-16mcu7o/build/python/plugins/db_manager/db_plugins/spatialite/resources_rc.py -o /tmp/qgis3-dev-20171105-58465-16mcu7o/build/python/plugins/db_manager/db_plugins/spatialite/resources_rc.py /tmp/qgis3-dev-20171105-58465-16mcu7o/python/plugins/db_manager/db_plugins/spatialite/resources.qrc
PyQt5 resource compiler
pyrcc5: Unknown option: '-