Skip to content

Instantly share code, notes, and snippets.

@scw
scw / handle_datetime.R
Last active October 21, 2015 18:54
Convert an FGDB sourced datetime column to a POSIXct type in R
library('arcgisbinding')
arc.check_product()
# a FGDB source with a column 'datetime' containing our datetime field
d <- arc.open('a/fgdb/source')
df <- arc.select(d, 'datetime')
# convert from 1899-12-30 00:00 to UNIX Epoch, in seconds
as.unix.epoch <- (df$datetime[1]-25569)*86400
@scw
scw / package-commands.md
Last active September 15, 2015 01:32
Comparison of package commands
brew install
brew uninstall

apt-get install
apt-get remove

pkg install
pkg delete
@scw
scw / example-spagedi-result.txt
Created June 16, 2014 20:22
An example SPAGeDi result file
SPAGeDi 1.4c (build 17-07-2013) - a program for Spatial Pattern Analysis of Genetic Diversity
Written by Olivier Hardy & Xavier Vekemans
Contributions by Reed Cartwright
Input file : "C:\Users\shau7031\AppData\Roaming\geneGIS\spagedi_data.txt"
Results file : "Z:\data\arcgis\addins\genegis\tests\data\tmxr.txt"
1318 individuals
2 categories: CA-OR, Cent_Am
Latitude-longitude coordinates (assumed to be in degrees; used to compute distances in km), Latitude, Longitude
@scw
scw / vessel-scoring-logic.py
Created May 23, 2014 03:20
Logic for vessel validation scores
def jaro_cost(inputs, weight=1):
min_score = 1.0
for a,b in list(itertools.combinations(inputs, 2)):
jaro_score = jellyfish.jaro_distance(a, b)
if jaro_score < min_score:
min_score = jaro_score
return (1 - min_score)*weight
def attr_score(attribute):
@scw
scw / break-out-table.py
Created May 22, 2014 19:54
break out times into a large time table
def time_in_min(time_string):
# assumes 24h times
(hour, minutes) = [int(t) for t in time_string.split(":")]
return hour * 60 + minutes
def min_to_time(time_min):
minutes = time_min % 60
hours = (time_min - minutes) / 60
# return hour:minutes with leading zero
return "{0}:{1:02d}".format(hours,minutes)
@scw
scw / pipx.sh
Last active August 29, 2015 13:58
wrap calls to pip to force usage of the GCC environment over Clang
# I've added this to my ~/.bash_profile to use it, you could also create a stand-alone shell script.
# Usage: pipx install cython
function pipx() {
# Many Python packages don't install correctly with clang, as mentioned here:
# https://gist.github.com/goldsmith/7262122
# This wrapper forces gcc for pip installations:
export CFLAGS="-arch i386 -arch x86_64"
export FFLAGS="-m32 -m64"

Keybase proof

I hereby claim:

  • I am scw on github.
  • I am scw (https://keybase.io/scw) on keybase.
  • I have a public key whose fingerprint is DC95 4D84 4B97 617D 62FC 4498 F3E7 6E7C 03E8 FB6A

To claim this, I am signing this object:

@scw
scw / compare-projection.py
Created August 26, 2013 16:34
Compare between ArcGIS and Proj.4 when converting between WGS84 and Mass State Plane.
import pyproj
import arcpy
# ArcMap result (meters):
# 306,414.514 854,124.573
x = -70.216908
y = 41.930268
# perform projection using pyproj (PROJ.4)
# this test should be run after a fresh run of makeaddin to rebuild the .esriaddin file.
class TestAddin(unittest.TestCase):
def setUp(self):
self.addin_path = os.sep.join([local_path, '..', '..', 'btm.esriaddin'])
self.addin_zip = zipfile.ZipFile(self.addin_path, 'r')
def testToolboxIsPresent(self):
toolbox_path = 'Install/toolbox/btm.pyt'
self.assertTrue(toolbox_path in self.addin_zip.namelist())
import arcpy
import binascii
line = arcpy.FromWKT('LINESTRING (30 10, 10 30, 40 40)')
print binascii.hexlify(line.WKB)
# produces:
# 0102000000030000000000000000003e40000000000000244000000000000024400000000000003e4000000000000044400000000000004440