Project Description
This project allows you to easily convert some Well Known Binary or Well Known Text into a custom object for JSON ... to be shown on maps like Google Maps.

Here's some sample code.

[Test]
// ReSharper disable InconsistentNaming
public void GivenSomeBinaryData_GeoParse_ReturnsAValidSpatialGeographySet()
// ReSharper restore InconsistentNaming
{
    // Arrange.
    byte[] boundary = File.ReadAllBytes("LA Boundary - Reduced to a Medium Zoom Level.bin");
    IGeoParse geoParse = new GeoParse();

    // Act.
    SpatialGeographySet result = geoParse.Parse(boundary);

    // Assert.
    Assert.IsNotNull(result);
    Assert.IsNotNull(result.SpatialGeographys);
    Assert.AreEqual(1, result.SpatialGeographys);
}

[Test]
// ReSharper disable InconsistentNaming
public void GivenSomeWellKnownTextData_GeoParse_ReturnsAValidSpatialGeographySet()
// ReSharper restore InconsistentNaming
{
    // Arrange.
    string boundary = File.ReadAllText("LA Boundary - Reduced to a Medium Zoom Level.txt");
    IGeoParse geoParse = new GeoParse();

    // Act.
    SpatialGeographySet result = geoParse.Parse(boundary);

    // Assert.
    Assert.IsNotNull(result);
    Assert.IsNotNull(result.SpatialGeographys);
    Assert.AreEqual(1, result.SpatialGeographys);
}


And if this was in some ASP.NET MVC Controller ....
public JsonResult Foo()
{
    // Grab Well Known Text / Well Known Binary from the database or wherever.
    byte[] boundary = mySqlConnection
                                   .Query<byte[]>("SELECT Boundary FROM SomeGeographyTable WHERE Id = 1")
                                   .SingleOrDefault();

    // Parse the data.
    IGeoParse geoParse = new GeoParse();
    var result = geoParse(boundary);

    // Lets return the poly as JSON.
   return Json(new Feature
                            {
                                SpatialGeographySet = result,
                                Properties = null
                            }, JsonRequestBehavior.AllowGet);
}

Last edited Nov 10, 2011 at 7:18 AM by purekrome, version 3