Skip to content

Instantly share code, notes, and snippets.

@JeffJacobson
JeffJacobson / Test_simpleGeometry.py
Created January 3, 2012 17:58
simplegeometry: A module for working with OGC Simple Geometry definitions. Designed for use with SQL Server 2008 WKT strings.
import simplegeometry
parsedG = simplegeometry.parseline("MULTILINESTRING ((1208120.9130000025 745513.05599999428 NULL 20, 1208147.5579999983 746483.423999995 NULL 20.182, 1208156.1369999945 746685.62999999523 NULL 20.22, 1208167.1659999937 746871.90399999917 NULL 20.255, 1208183.0980000049 747065.53200000525 NULL 20.292, 1208224.0849999934 747534.46500000358 NULL 20.38, 1208278.5320000052 748175.35199999809 NULL 20.503, 1208298.1400000006 748436.38099999726 NULL 20.553, 1208316.5219999999 748766.0380000025 NULL 20.616, 1208325.6720000058 748994.7880000025 NULL 20.66, 1208329.1790000051 749297.90999999642 NULL 20.719, 1208322.6490000039 749569.95900000632 NULL 20.772, 1208314.0709999949 749826.0869999975 NULL 20.822, 1208285.8959999979 750428.78900000453 NULL 20.94, 1208283.375 750469.80500000715 NULL 20.95, 1208271.1790000051 750746.43000000715 NULL 20.999, 1208265.050999999 751041.77300000191 NULL 21.05, 1208273.4159999937 751666.8180000037 NULL 21.16, 1208281.0789999962 752090.83499999344 NULL 21.242, 120
@JeffJacobson
JeffJacobson / exportlegend.py
Created January 3, 2012 19:07
Exports the legend from an ArcGIS Server map service as an HTML document.
"""Exports the legend from an ArcGIS Server map service as an HTML document.
Parameters:
0 ArcGIS Server map service legend URL
1 Inline Images (optional)
If this parameter is set to any value, the images will be included inline
in the CSS instead of being saved to separate image files. (Note that this
method is not supported by Internet Explorer 7.)
"""
import sys, re, base64, httplib, json
@JeffJacobson
JeffJacobson / CopyFilesForDate.py
Created January 4, 2012 22:12
Copies files and appends to the copies' filenames the date nearest the 15th or last day of the month, or nearest weekday.
"""Creates copies of the timesheet files for the current pay period.
Place this file in the same directory as your timesheet FileMaker Pro files.
When you run this script, it will make copies of the files and append the
date of the last day of the current pay period.
"""
import sys, os, shutil, datetime, calendar
# Get today's date.
today = datetime.date.today()
@JeffJacobson
JeffJacobson / removeExcludeExtension.py
Created February 1, 2012 23:45
Remove ".exclude" extension from all files in a directory without losing SVN history
"""Remove the ".exclude" extension from all files in this directory.
"""
import os, re, pysvn
# Get all of the files in the directory.
excludeFiles = os.listdir('.')
# Filter so only those ending with ".exclude" are in the list.
regex = re.compile('.+\.exclude$', re.IGNORECASE)
excludeFiles = filter(lambda f: regex.search(f), excludeFiles)
@JeffJacobson
JeffJacobson / ListFeatureClasses.sql
Last active September 30, 2015 04:18
Select Feature Class Metadata from ArcSDE
-- Selects the feature classes in a database. Returns names, geometry types, and title.
SELECT
i.[Name],
i.[Definition].value(N'(/DEFeatureClassInfo/ShapeType)[1]', N'varchar(30)') as GeometryType,
i.[Documentation].value(N'(/metadata/idinfo/citation/citeinfo/title)[1]', N'varchar(255)') as Title
FROM dbo.GDB_ITEMS AS i INNER JOIN
dbo.GDB_ITEMTYPES AS t ON i.Type = t.UUID
WHERE t.Name = 'Feature Class'
ORDER BY i.Name
@JeffJacobson
JeffJacobson / GetMetadataForLayersFromSoe.cs
Last active September 30, 2015 16:48
Get Metadata for layers in SOE
private List<string> GetMetadataForLayers()
{
var mapServer = (IMapServer3)_serverObjectHelper.ServerObject; // _serverObjectHelper is an IServerObjectHelper
string defaultMapName = mapServer.DefaultMapName;
var msDataAccess = (IMapServerDataAccess)_serverObjectHelper.ServerObject;
IMapServerInfo3 mapServerInfo = (IMapServerInfo3)mapServer.GetServerInfo(defaultMapName);
IMapLayerInfos layerInfos = mapServerInfo.MapLayerInfos;
List<string> xmlList = new List<string>(layerInfos.Count);
@JeffJacobson
JeffJacobson / FileSystemExtensions.cs
Created February 23, 2012 18:35
C# extension method for walking the file system.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace FileSystemHelper
{
public static class FileSystemExtensions
{
@JeffJacobson
JeffJacobson / SqlGeometryExtensions.cs
Created February 24, 2012 23:06
SqlGeometry <-> ESRI SOAP Geometry conversion extensions for .NET
namespace Wsdot.GIS.Geometry.Conversion
{
using System;
using System.Collections.Generic;
using ESRI.ArcGIS.SOAP;
using Microsoft.SqlServer.Types;
public static class SqlGeoemtryExtensions
{
/// <summary>
@JeffJacobson
JeffJacobson / ArcObjectsLinqExtensions.cs
Created March 6, 2012 22:32
Defines extension methods that allows LINQ to be used with ArcObjects "IEnum..." types.
using System;
using System.Collections.Generic;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Server;
namespace Wsdot.ArcObjects.Extensions
{
public static class ArcObjectsLinqExtensions
@JeffJacobson
JeffJacobson / waroute.js
Last active October 2, 2015 12:28
Regular expression that matches a WA state route ID
// This RegEx should match any valid state route identifier.
var _SR_REGEX = /^(\d{3})(?:((?:AR)|(?:C[DI])|(?:C[O])|(?:F[DI])|(?:LX)|(?:[PQRS][\dU])|(?:RL)|(?:SP)|(?:TB)|(?:TR)|(?:PR)|(?:F[ST])|(?:ML))([A-Z0-9]{0,6}))?$/i;
/*
==RRTs (Related Roadway Type)==
AR Alternate Route
CD Collector Distributor (Dec)
CI Collector Distributor (Inc)
CO Couplet
FI Frontage Road (Inc)