Skip to content

Instantly share code, notes, and snippets.

@dvhthomas
dvhthomas / gist:201174
Created October 4, 2009 05:34
Building NTS geometries from ESRI JSON
/// <summary>
/// Create valid <see cref="IGeometry"/> list from the incoming
/// JSON.
/// </summary>
/// <param name="geometryType">Only a single type of geometry is supported in each
/// query result, so the <paramref name="json"/> value is limited to one of the
/// <see cref="EsriGeometryType"/>s.</param>
/// <param name="json">JSON query result from <see cref="DownloadResource"/> which
/// is the raw JSON string.</param>
/// <returns>A list of point, polyline, polygon geometries in the same order
@dvhthomas
dvhthomas / ReadLayerQuery.cs
Created October 4, 2009 05:43
esri json.cs
/// <summary>
/// Parses the results of a query operation against the layer
/// in to <see cref="Feature"/>s.
/// </summary>
/// <param name="dataSourceFields">List of valid fields</param>
/// <param name="geometryType"></param>
/// <param name="json"></param>
/// <returns></returns>
/// <remarks>Because the collection of fields can vary between each layer and even
/// between query results for each layer this actually has a two phased approach to loading
@dvhthomas
dvhthomas / NUnitException.cs
Created October 4, 2009 05:46
Expecting an exception in NUnit
[Test]
public void Throwing_an_exception_prevents_anything_from_being_saved()
{
Assert.Throws<Exception>(() =>
{
using (ISession session = NHibernateHelper.OpenSession())
{
Person person = ObjectMother.ValidPerson();
Person person2 = ObjectMother.ValidPersonTwo();
@dvhthomas
dvhthomas / oracle.py
Created October 4, 2009 05:48
Working with Oracle from Python
#!/usr/bin/env python
import csv
import time
import cx_Oracle
# Parses USPS addresses from voter addresses
# and inserts them into VR_LOCATION table ready
# for geocoding. Does batches by zipcode
def LoadZips():
zipcodes = []
@dvhthomas
dvhthomas / principal.cs
Created October 4, 2009 05:54
Getting username from Active Directory
using System;
using System.DirectoryServices;
using System.Security.Principal;
using System.Web.UI;
namespace BookWeb
{
public partial class Main : MasterPage
{
protected void Page_Load(object sender, EventArgs e)
@dvhthomas
dvhthomas / imagegenerator.cs
Created October 4, 2009 05:58
Create image dynamically for testing
public static MemoryStream CreateTempImage(int width, int height)
{
using (var image = new Bitmap(width, height, PixelFormat.Format32bppArgb))
{
string text = String.Format("{0:s}", DateTime.Now);
Graphics graphics = Graphics.FromImage(image);
var brush = new SolidBrush(Color.Red);
graphics.FillRectangle(brush, 0, 0, image.Width, image.Height);
var font = new Font("Arial", 18, FontStyle.Bold);
@dvhthomas
dvhthomas / IFileZipUtility.cs
Created October 4, 2009 06:03
7-zip compression
using System;
using System.IO;
namespace Woolpert.Compression
{
/// <summary>
/// Zips files up
/// </summary>
public interface IFileZipUtility
{
@dvhthomas
dvhthomas / Converters.cs
Created October 4, 2009 06:12
Converting ESRI geometries to NTS
using ESRI.ArcGIS.Geometry;
using GisSharpBlog.NetTopologySuite.IO;
namespace Spatial.Formats
{
/// <summary>
/// This class is used to convert a GeoAPI Geometry to ESRI and vice-versa.
/// It can also convert a ESRI Geometry to WKB/WKT and vice-versa.
/// </summary>
/// <remarks>Copied wholesale from this forum post, then converted to
@dvhthomas
dvhthomas / Program.cs
Created October 4, 2009 22:04
Starting a service in a console
internal class Program
{
private static void Main(string[] args)
{
ILogFactory factory = new NLogFactory();
Log.InitializeLogFactory(factory);
ContainerBootstrapper.BootstrapStructureMap();
if (Environment.CommandLine.ToLower().Contains("-console"))
{
@dvhthomas
dvhthomas / TopShelf.cs
Created October 5, 2009 01:31
TopShelf makes service creation a snap
using System;
using StructureMap;
using Topshelf;
using Topshelf.Configuration;
namespace GisQueryDirectHost
{
internal class Program
{
private static void Main(string[] args)