Skip to content

Instantly share code, notes, and snippets.

@scw
scw / example-toolbox.py
Created June 11, 2013 00:31
Example showing how to create categories within a Python toolbox.
import arcpy
class Toolbox(object):
def __init__(self):
self.label = u'Example_Toolbox'
self.alias = ''
self.tools = [FirstTool, SecondTool, ThirdTool]
class FirstTool(object):
@scw
scw / generate_prj_files.py
Last active March 12, 2018 04:28
Generate projection files (.prj) from ArcGIS defaults.
import arcpy
import os
def create_path(path):
if not os.path.exists(path):
print "Creating directory {}".format(path)
os.makedirs(path)
# default application data dir; e.g. c:\Users\scw\AppData\Roaming
@scw
scw / binsize.py
Last active December 17, 2015 23:19
example histogram bin size calculation.
import arcpy
arcpy.CheckOutExtension("spatial")
raster = arcpy.Raster("c:\\workspace\\input_raster")
range = raster.maximum - raster.minimum
bins = 256
bin_size = (range) / bins
# now we know the bin width, can multiply that by the OBJECTID for the lower bound of each
lower_bin_value = [bin_size * i for i in range(bins)]
@scw
scw / gist:5572427
Created May 13, 2013 23:34
Open source components listed in ArcGIS Server 10.1
Pulled from http://resources.arcgis.com/en/help/main/10.1/00qn/pdf/ArcGIS10_Acknowledgements.pdf
7-Zip 9.2
ASP.NET AJAX Control Toolkit 1.0.10920.0
ASP.NET AJAX JavaScript library 1.0
ASP.NET MVC 2
Alphaworks ICU 2.2
Ant 1.6.5
Apache log4cxx
Apache AXIS 1.3
@scw
scw / gist:5470823
Created April 26, 2013 22:16
BTM updateParameters example
def updateParameters(self, parameters):
validator = getattr(self, 'ToolValidator', None)
# parameter names
cols = ['bathy', 'inner', 'outer', 'scale_factor', 'output']
outer_radius = parameters[cols.index('outer')].valueAsText
bathy = parameters[cols.index('bathy')].valueAsText
if outer_radius is not None and bathy is not None:
raster_desc = arcpy.Describe(bathy)
# get the cellsize of the input raster; assume same in X & Y
@scw
scw / gis-se-by-latitude.txt
Created April 17, 2013 20:27
GIS.SE users identified in California, sorted by latitude.
Anderson:
http://gis.stackexchange.com/users/5330/awesomo
Chico:
http://gis.stackexchange.com/users/2749/boyle300
Nevada City:
http://gis.stackexchange.com/users/357/brianpeasley
Sacramento:
@scw
scw / gist:3231008
Created August 1, 2012 21:42
compare BTM broad & fine scale code
# fine scale inner block
outFocalStatistics = FocalStatistics(Bathy, NbrAnnulus(FineInnerRadius, FineOuterRadius, "CELL"), "MEAN")
outRaster = Int(Plus(Minus(Bathy, outFocalStatistics), 0.5))
# broad scale inner block
outFocalStatistics = FocalStatistics(Bathy, NbrAnnulus(BroadInnerRadius, BroadOuterRadius, "CELL"), "MEAN")
outRaster = Int(Plus(Minus(Bathy, outFocalStatistics), 0.5))
@scw
scw / true-distance-to-shore.py
Created May 30, 2012 20:03
Example using OGR and Shapely to compute true distances between geometries and points.
#!/usr/bin/env python
# distance_from_shore.py: compute true distance between points
# and closest geometry.
# shaun walbridge, 2012.05.15
# TODO: no indexing used currently, could stand if performance needs
# improving (currently runs in ~1.5hr for 13k points)
from geopy import distance
@scw
scw / test-behr.R
Created April 24, 2012 23:55
Behrmann projection test for R
library(rgdal)
behrmann.crs <- CRS('+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +ellps=WGS84 +units=m +no_defs')
# define a known point in Behrmann projection
point <- SpatialPoints(cbind(0, 7284713.234), behrmann.crs)
# try reprojecting point back to WGS84
spTransform(point, CRS('+init=epsg:4326'))
@scw
scw / gist:2374373
Created April 13, 2012 06:27
Check raster dimensions match expectation
checkRaster <- function(raster) {
if (raster@nrows * raster@ncols == 220106) {
message <- paste("Raster size checks out for layer:", raster@layernames, sep="")
}
else {
message <- paste( "invalid raster dimensions; nrows:", raster@nrows, " ncols:", raster@ncols, sep="")
}
print(message)
}