Giter Club home page Giter Club logo

sqlserverspatial.toolkit's Introduction

NuGet Version Build status

SqlServerSpatial.Toolkit

Geometry trace for Sql Spatial data + debugger visualizer for SQL Server data types in Visual Studio

Viewer

  • Debugger visualizer for SqlGeometry and SqlGeography types
  • Extensions methods
  • Custom trace writer with colorful syntax
  • Trace viewer

Install

Via NuGet: Install-Package SqlServerSpatial.Toolkit

Using the toolkit

Spatial Trace

Very useful when processing geometries. SpatialTrace lets you track what is going on along the way.

Important: Trace will actually write only if a debugger is attached. This is by design, to avoid tracing in a production environment.

using SqlServerSpatial.Toolkit;

// Enable tracing
SpatialTrace.Enable(); 
// Trace sample geometry instance. 
// Works with SqlGeometry, SqlGeography and IEnumerable<> of those
SpatialTrace.TraceGeometry(geometry, "Sample geometry with default style");

// Change styling
SpatialTrace.SetLineWidth(3); // Current stroke style is 3px wide
SpatialTrace.SetFillColor(Color.FromArgb(128, 255, 0, 0)); // Fills with red

// Style is applied to subsequent traces 
SpatialTrace.TraceGeometry(geometry, "Some text");

// Reset style
SpatialTrace.ResetStyle();

This will generate a SpatialTrace.txt file in running assembly directory. You can directly view this trace by calling

SpatialTrace.ShowDialog();

Trace Viewer

Open the viewer. Drag the file on it like a ninja and drop it like a samuraï, and the trace viewer will show what you haved logged through the SpatialTrace.Trace...

Debugger Visualizer

Installation

  • Copy the following files
    • SqlServerSpatial.Toolkit.dll
    • SqlServerSpatial.Toolkit.DebuggerVisualizer.VS2013.dll
    • Microsoft.SqlServer.Types.dll and the SqlServerTypes directory
  • in Binaries\Release to either of the following locations:
    • VisualStudioInstallPath\Common7\Packages\Debugger\Visualizers
    • My Documents\VisualStudioVersion\Visualizers
  • Restart your debugging session
  • More information here on MSDN.

Usage

Hover any SqlGeometry or SqlGeography variable and click on the lens icon. The visualizer will popup and display your geometry. Use mouse to pan and zoom.

Screen capture

Extension methods

1. Point enumerator

Enumerate points in a more natural manner. Here's a look of how it is without the toolkit:

for (int i = 1; i<=geom.STNumPoints(); i++)
{
	SqlGeometry point = geom.STPointN(i);
	// ... do something with point
}

Now, with the toolkit, you can iterate point with a foreach syntax:

foreach(SqlGeometry point in geom.Points())
{
	// ... do something with point
}

2. Geometry parts enumerator

Enumerate parts of a geometry. Here's a look of how it is without the toolkit:

for (int i = 1; i <= geom.STNumGeometries(); i++)
{
	SqlGeometry geometryPart = geom.STGeometryN(i);
	// ... do something with geometryPart
}

Now, with the toolkit:

foreach (SqlGeometry geometryPart in geom.Geometries())
{
	// ... do something with geometryPart
}

3. Polygon helpers

You can handle polygon interior rings easily:

bool hasInteriorRings = polygon.HasInteriorRings();
foreach(SqlGeometry ring in geom.InteriorRings())
{
	// ... do something with ring
}

4. MakeValidIfInvalid() helper

MakeValid() can create strange artefacts and awkward geometries. The MakeValidIfInvalid() method will help you. It takes two parameters:

  • retainDimension : guarantees that every geometry returned will be at least of the specified dimension. For example, MakeValid() or Reduce() sometimes returns a geometry collection object with lines, points and polygons. Calling MakeValidIfInvalid(2) will guarantee that lines and points are removed.
  • minimumRatio : guarantees that every geometry under this ratio will not be returned. For example, if you have a geometry collection with a 10000m² polygon and 0.5m² negligible polygon, you can call MakeValidIfInvalid(2, 0.00001) and this polygon will be removed.

5. Serialization helpers

You can save and load SqlGeometry from disk:

// Loads SqlGeometry from disk
SqlGeometry geom = SqlTypesExtensions.Read("file.bin");

// Save SqlGeometry to disk
geom.Save("file.bin");

// Loads a list of SqlGeometry from disk
List<SqlGeometry> geometries = SqlTypesExtensions.ReadList("file.bin");

// Saves a list of SqlGeometry to disk
geometries.Save("file.bin");

How to build the toolkit from source

  • Grab the repo
  • Choose the solution matching your Visual Studio version (VS2013 or VS2015)
  • Restore NuGet packages (Microsoft.SqlServer.Types and DotSpatial.Projections)
  • Build. Binaries are generated in Binaries directory

sqlserverspatial.toolkit's People

Contributors

xfischer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

zengkefu hnjm

sqlserverspatial.toolkit's Issues

Cleanup code

Cleanup toolkit externals => make it plain nice and pleasing to see.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.