Skip to content

Instantly share code, notes, and snippets.

View nmpeterson's full-sized avatar

Noel Peterson nmpeterson

View GitHub Profile
@nmpeterson
nmpeterson / arcade_line_length_enforcer.js
Last active November 16, 2022 20:12
A function for ArcGIS Arcade to break a string into lines approximately matching a target length.
// Line-break enforcer, for instances where ArcGIS Pro won't automatically
// insert line breaks in long strings (e.g. in composite callouts).
// The targetWidth parameter is a character limit that the function will
// use to break the input str into multiple lines. Individual lines may
// be slightly longer or shorter than the targetWidth, depending on where
// space characters exist that can be replaced with line breaks.
function insertNewLines(str, targetWidth) {
var words = Split(str, " ")
var lines = []
var curLine = ""
@nmpeterson
nmpeterson / Census_Change2010-2020_byCCA.csv
Created August 13, 2021 17:19
A table containing 2010 & 2020 Decennial Census counts of population, households and housing units for each of the 77 Chicago Community Areas
CCA_Num CCA Pop2010 Pop2020 Pop_Change Pop_PctChange HH2010 HH2020 HH_Change HH_PctChange HU2010 HU2020 HU_Change HU_PctChange
14 Albany Park 51542 48396 -3146 -6.10 16322 17161 839 5.14 17982 18254 272 1.51
57 Archer Heights 13363 14196 833 6.23 3838 4163 325 8.47 4244 4405 161 3.79
34 Armour Square 13443 13890 447 3.33 5262 5648 386 7.34 5771 6078 307 5.32
70 Ashburn 41081 41098 17 0.04 12451 12909 458 3.68 13060 13387 327 2.50
71 Auburn Gresham 48743 44878 -3865 -7.93 17603 18071 468 2.66 20351 20664 313 1.54
25 Austin 98514 96557 -1957 -1.99 32792 35864 3072 9.37 38214 39477 1263 3.31
45 Avalon Park 10148 9458 -690 -6.80 3907 4145 238 6.09 4274 4569 295 6.90
21 Avondale 39262 36257 -3005 -7.65 13573 14578 1005 7.40 15339 15937 598 3.90
19 Belmont Cragin 78743 78116 -627 -0.80 21591 23450 1859 8.61 23634 24881 1247 5.28
@nmpeterson
nmpeterson / .gitignore
Last active July 2, 2020 18:15
Chicago 311 flooding data
.Rhistory
*.dbf
*.prj
*.shp*
*.shx
*.geojson
@nmpeterson
nmpeterson / python_toolbox_template.pyt
Last active January 9, 2018 22:05
ArcGIS Python Toolbox (.pyt) Template
#!/usr/bin/env python
'''
python_toolbox_name.pyt
Author: username
Revised: mm/dd/yyyy
---------------------------------------------------------------------------
Python toolbox (.pyt) description and special instructions.
'''
import os
@nmpeterson
nmpeterson / userDefineLang.xml
Created September 6, 2014 04:25
SAS & log syntax highlighting for Notepad++, courtesy of http://hafniumcity.com/notepad_color.php
<NotepadPlus>
<UserLang name="sas" ext="sas">
<Settings>
<Global caseIgnored="yes" />
<TreatAsSymbol comment="no" commentLine="yes" />
<Prefix words1="no" words2="no" words3="no" words4="yes" />
</Settings>
<KeywordLists>
<Keywords name="Delimiters">&quot;`0&quot;&apos;0</Keywords>
<Keywords name="Folder+">data proc %macro %macro proc if</Keywords>
@nmpeterson
nmpeterson / create_divvy_points_from_json.py
Last active January 3, 2020 18:19
An arcpy-based function for creating a point feature class of all Divvy bike share (https://divvybikes.com) stations from their current JSON data, for use within ArcMap/ArcGIS.
import arcpy
import json
import os
import sys
if ((3, 0) <= sys.version_info <= (3, 9)):
from urllib.request import urlopen # Python 3
elif ((2, 0) <= sys.version_info <= (2, 9)):
from urllib2 import urlopen # Python 2
@nmpeterson
nmpeterson / check_selection.py
Last active January 13, 2023 18:23
An arcpy-dependent function for checking whether any features are currently selected in the specified feature layer or table view.
#import arcpy
def check_selection(lyr):
"""Check whether specified feature layer has a selection."""
desc = arcpy.Describe(lyr)
selected = desc.FIDSet
return len(selected) > 0
@nmpeterson
nmpeterson / create_mean_centroid.py
Last active December 20, 2015 10:39
An arcpy-dependent function for ArcGIS 10.1+, which takes an input feature class (or layer) and the name of a weight field (e.g. population) from that feature class, and creates a new output feature class containing a single point feature at the average (weighted) coordinates of all of the input features.
def create_mean_centroid(in_layer, out_fc, weight_field):
'''
Calculate average coordinates from all input features' centroids,
weighted by values in weight_field.
Output is a new feature class containing a single mean centroid point.
It is *highly* recommended that a State Plane or UTM coordinate system
be used, as the calculations use Euclidean geometry.
'''
@nmpeterson
nmpeterson / titlecase.py
Last active December 18, 2015 18:09
Convert a string to Title Case. (No cleverness: 'iPhone' will become 'Iphone'.)
def titlecase(in_str):
''' Convert a string to Title Case. Not very intelligent:
all words capitalized, and "iPhone" becomes "Iphone". '''
words = in_str.split(' ')
for i in xrange(len(words)):
words[i] = words[i].capitalize()
title = ' '.join(words)
return title
# Example call:
@nmpeterson
nmpeterson / list_to_ranges.py
Last active December 18, 2015 18:09
A function to convert a list of integers into a string of ranges of consecutive values.
def list_to_ranges(in_list):
''' Convert a list of integers into a string of ranges of consecutive values. '''
l = in_list[:]
l.sort()
range_str = str(l[0])
for i in xrange(1,len(l)-1): # Handle first & last separately
if l[i] == l[i-1]+1 and l[i] == l[i+1]-1:
pass
elif l[i] != l[i-1]+1:
range_str += ', ' + str(l[i])