Skip to content

Instantly share code, notes, and snippets.

@maphew
maphew / arcpy_parse_path.py
Created January 17, 2018 21:29
partial helper for reliably deriving workspace path from input Feature Class path
def parse_path(fc_path):
'''Derive workspace from Feature Class's location
Adapted from http://pro.arcgis.com/en/pro-app/tool-reference/modelbuilder-toolbox/parse-path.htm'''
fc = os.path.basename(fc_path)
dir = os.path.dirname(fc_path)
name = os.path.basename(fc_path).rstrip(os.path.splitext(fc_path)[1])
ext = os.path.splitext(fc_path)[1].lstrip(".")
if ext.lower() == 'gdb':
@maphew
maphew / classify-ground-export-aboveground.json
Last active January 11, 2020 22:11
A PDAL pipeline that a) classifies into ground/not-ground, b) adds "Height Above Ground" attribute, and c) exports only above ground points. Adapted from https://lists.osgeo.org/pipermail/pdal/2017-July/001367.html
{
"pipeline": [
"Carmacks_01.laz",
{
"type": "filters.assign",
"assignment": "Classification[:]=0"
},
{
"type": "filters.smrf"
},
# REFERENCES
Bolstad, P.V. and Stowe, T. 1994. An evaluation of DEM accuracy: elevation, slope and aspect.
Photogrammetric Engineering and Remote Sensing 60: 1327-1332.
Garbrecht, J. and Starks, P. 1995. Note on the use of USGS level 1 7.5-minute DEM coverages for landscape drainage analyses.
Photogrammetric Engineering and Remote Sensing 61: 519-522.
Giles, P.T. and Franklin, S.E. 1996. Comparison of derivative topographic surfaces of a DEM generated from stereographic SPOT images with field measurements.
Photogrammetric Engineering and Remote Sensing 62: 1165-1171.
@maphew
maphew / fetch-renderer.py
Last active October 26, 2017 22:33
How to change or assign ArcMap layer symbology type from python?
#Interactive Python window in ArcMap
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "*", df)[0]
renderer = lyr._arc_object.renderer
>>> renderer
u"<Renderer xsi:type='typens:RasterClassifyRenderer' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
...snip...
@maphew
maphew / asc2json.ps1
Last active October 18, 2017 20:41
Convert Arcinfo Ascii Grid file to JSON
# asc2json
# Convert Arcinfo Ascii Grid file to JSON
# RegEx replace:
# - strip leading whitespace
# - strip line not beginning with a number
# - add opening `[` to beginning of line
# - space to comma
# - end of line to `],`
# - strip empty list `[],`
@echo off
echo.
echo. Manually registering custom ArcGIS COM tools in the current folder...
echo.
setlocal
set PATH=%PATH%;C:\Program Files (x86)\Common Files\ArcGIS\bin;C:\Program Files\Common Files\ArcGIS\bin
for %%a in (*.dll) do ESRIRegAsm.exe "%%~dpna"
endlocal
@maphew
maphew / points-with-names.geojson
Created June 27, 2017 20:46
A few geojson points with a 'Name' attribute to use for labelling
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maphew
maphew / qgis-vector-polygonize-output.geojson
Last active June 27, 2017 19:18
How to create polygons from this geojson grid, using pure javascript or tools available to Node.js? From https://gis.stackexchange.com/questions/245277/how-to-create-geojson-polygons-from-lines
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maphew
maphew / yt-meteo.html
Created December 7, 2016 02:56
Meteo Earth, centred over the Yukon Territory
<script type='text/javascript' src='http://www.meteoearth.com/service/me.js'></script>
<div id='meDiv' style='width:420px;height:420px;background:#000;position:relative'></div>
<script type='text/javascript'>var meConfig={div:document.getElementById('meDiv'),viewSettings:{longitude: -132.8662,latitude: 65.7642,zoom:8.3868,is3DEnabled:true,isLightingEnabled:true, isPrecipitationEnabled:true, isWindEnabled:true}};me_createView(meConfig);</script>