Skip to content

Instantly share code, notes, and snippets.

View knu2xs's full-sized avatar

Joel McCune knu2xs

View GitHub Profile
@knu2xs
knu2xs / 01-original.py
Last active March 10, 2025 15:06
Toolbox in ArcGIS Python Add-In
import arcpy
import pythonaddins
class addDefinitionQueryLayers(object):
"""Implementation for arcpyMappingAddin_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
@knu2xs
knu2xs / get_centroid_feature_class.py
Last active August 29, 2015 14:02
Get centroid of an entire feature class
# import modules
import arcpy
# set variables to make life easier
fc = "Wilderness"
def get_centroid(feature_class):
# use describe to create an extent obejct to work with
extent = arcpy.Describe(feature_class).extent
@knu2xs
knu2xs / get_yyyymmdd.js
Created June 17, 2014 16:46
Date string formatted as yyyymmdd using javascript
Date.prototype.yyyymmdd = function() {
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
var dd = this.getDate().toString();
return yyyy + (mm[1]?mm:"0"+mm[0]) + (dd[1]?dd:"0"+dd[0]); // padding
};
d = new Date();
d.yyyymmdd();
@knu2xs
knu2xs / negativeToNull.py
Created June 27, 2014 18:26
Clear fields to null with negative number placeholders in ArcGIS
# import modules
import arcpy
# feature class or table to modify
table = r'path/to/featureClass/or/table'
# create update cursor to interate data
with arcpy.da.UpdateCursor(table, '*') as cursor:
# iterate the rows
@knu2xs
knu2xs / hydroOverlay.js
Last active August 29, 2015 14:04
Useful snippets for ArcGIS Javascript API demonstrations
require(
"esri/layers/ArcGISTiledMapServiceLayer",
)
function (
Tiled,
) {
var hydroOverlay = new Tiled("http://hydrology.esri.com/arcgis/rest/services/WorldHydroReferenceOverlay/MapServer");
map.addLayer(hydroOverlay);
@knu2xs
knu2xs / featureLayerSymbology.js
Created July 19, 2014 17:30
Use point symbology with a feature layer in Leaflet/Esri-Leaflet
var iconFs = L.icon({
iconUrl: 'http://services.arcgis.com/SgB3dZDkkUxpEHxu/ArcGIS/rest/services/huc17_accesses/FeatureServer/0/images/d66f4bf18356e409c6221a46633b935a',
iconSize: [14, 15],
iconAnchor: [0, 0]
});
var layer = L.esri.featureLayer('http://services.arcgis.com/SgB3dZDkkUxpEHxu/arcgis/rest/services/huc17_accesses/FeatureServer/0', {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, { icon: conFs} );
}
@knu2xs
knu2xs / gruntNodemon.js
Last active August 29, 2015 14:04
Simple grunt-nodemon Gruntfile
'use strict';
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-nodemon');
grunt.initConfig({
nodemon: {
dev: {
script: 'app/index.js',
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
express: {
options: {
// Override defaults here
},
web: {
@knu2xs
knu2xs / Gruntfile.js
Created August 10, 2014 18:44
Streamline the process of working through the Getting Started with Grunt book and constantly creating a new directory with a new Gruntfile in the directory for each exercise.
// purpose: Streamline the process of working through the Getting Started with Grunt book and constantly creating a
// new directory with a new Gruntfile in the directory for each exercise.
//
// use: First create a directory for working through the exercises. Next, get your dependencies all taken care of in
// this directory by using '$ npm init' to create a package.json file. Now, get grunt in this directory using
// '$ npm install --save-dev grunt'. Although you will need more dependencies through the course of the book,
// this is enough to get started. Now, getting started on a new exercise is as simple as using
// '$ grunt newEx:<chapter number>:<exercise number>'. For instance, if starting on chapter three, exercise
// four, just enter '$ grunt newEx:03:04'. This grunt will create ./04/0403/Gruntfile.js. Now start editing
// the Gruntfile to do the exercise.
@knu2xs
knu2xs / walk_demonstration.py
Created October 6, 2014 17:04
Demonstration script for arcpy.da.walk
# import modules
import os
import arcpy
# variables
gdb = r'C:\Student\PYTH_20141006\PYTH_dataStudent\IAGL_Lincoln\Lincoln.gdb'
# walk recursively from top level in geodatabase
for dir, dirs, files in arcpy.da.Walk(gdb):