Using SQL-Geometry with SSIS Import/Export Tasks

March 6, 2009 by Bill Thorp

I know I shouldn’t be looking at these things before coffee.  Still, when a SQL Import task complained about my Geometry column type, I tried to fix this.

I editted my “C:\Program Files\Microsoft SQL Server\100\DTS\MappingFiles\MSSQLToSSIS10.XML” file, duplicating the entry for varbinary(max), but changing the data type name to “geometry.”

Bingo.  Everything now seems to copy fine.

Palm Springs Hotels?

February 18, 2009 by Bill Thorp

I’m attending the ESRI Developers Conference for the first time ever, and was hunting for hotel suggestions.  There are comments on James Fee’s blog from last year that recommend Zoso over the Wyndham.  TripAdvisor skews towards the tiny romatic places… any recommandations on a cheaper place for the barely-under 30 crowd?

Awesome Job in Fort Collins, CO

December 18, 2008 by Bill Thorp

Earn ~$70k, 5 weeks vacation, 3 weeks sick, with awesome people, for a good cause (the National Parks Service).  Take my old job.  Deadline is the 22nd.

http://www.cemml.colostate.edu/Jobs/351.pdf

Please forward / link this post!!

Google’s “Native Client” Browser Plugin

December 10, 2008 by Bill Thorp

The blogs are abuzz today with Google’s new cross-browser, cross-platform plugin that allows native x86 code to be run from a browser with minimal code tweaking.

Called Native Client, its complete with sandboxing, Javascript interop, a Quake demo and …  Yet Another Globe Application!!

naclapp

This really escalates the Javascript / Flash / Silverlight wars…. x86?!

Hello OpenGL, goodbye vector drawing performance woes.

Persisting Model State with JSON

December 8, 2008 by Bill Thorp

I’m departing from my normal show a lot of code methods here, to talk about an idea.

ASP.NET MVC denegrates ASP.NET Web Form’s old state-maintenance construct called Viewstate.  Without Viewstate, many developers are wondering how — more aptly where — to preserve the state of a web-application.  Here I will be explaining my favored answer — serializing your model to JSON — and showing why.

SOME HISTORY

In ASP.NET Web Forms, page state was stored within a highly compressed, encrypted hidden form field.  This allowed .NET web developers to persist the state of the GUI controls with little-to-no effort.  Unfortunately, AJAX came along.  AJAX developers found ASP.NET Web Forms didn’t play nicely at all; and that since Viewstate was encoded, AJAX developers couldn’t easily work-around ASP.NET Web Forms limitations.

ASP.NET MVC

The Model-View-Controller architectural pattern could easily be called the state/GUI/event-handler pattern.  Personally, I feel that most ASP.NET MVC examples nail showing off the Controller, and by proxy do a pretty alright job showing off the View.  But simple examples often have simple domain logic, and hence the Model and state-maintenance has been largely ignored.  This is important to note, because HTTP is a stateless protocol, yet the MVC pattern was designed for persistantly stated desktop applications.

“The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).” – Steve Burbeck, from the paper first describing MVC

STATE MAINTANENCE IN MVC

Given the statesless nature of HTTP, most ASP.NET MVC examples imply that the Model is little more than a “page model” with some supporting domain logic.  For the Model to act across multiple pages, we must persist that model between page requests… and we have options… databases, mutiple hidden form fields, sessions, cookies, etc..

The common denominator is that each page request must somehow reconnect to its Model.  In many cases, the Model — or at least the current pertinant chunk of the Model — is small enough to reasonably be persisted with each page, much as Viewstate was.   The huge advantage to custom Model persistance  comes in saving the Model to a hidden-form-field in the form of Javascript Object Notation, or JSON.  Using JSON means that not only will the Model be persisted, it will also be available for AJAX developers to update without full-page-postback.

ISN’T PUTTING THE MODEL IN THE VIEW BAD?

Considering the alternatives, no.  Sure, persisting the Model to a database would have some security benefits — at the expense of connection overhead.  Sessions or cookies work as well — with their own known limitations.  You could also — God forbid — break your model into little bits and persist each one as necessary.   Let me say this is the WORST possible thing you could do, because it requires the View to know the entire Model to do its job.  The code to serialize to JSON is the same for any object you throw at it, and changes to the Model won’t have to be duplicated in each View.

CONCLUSION

Of course, there are limitations to persisting your Model via JSON.  HTTP Get/Post have character limitations you must consider.  You will want to validate your model on each page post.  Overall, however, the benefit to AJAX developers outweighs the security awareness necessary to implement this state-management architecture, and prevents your ASP.MVC architectures from falling into the rut of “page-state”.

SwitchProxy Firefox Extension

December 2, 2008 by Bill Thorp

I’m not sure why its taken this long, but I finally looked for a Firefox extension that does proxy switching.  Its called SwitchProxy.  Now I can easily enable Fiddler or bypass the annoying DOI web filters preview my websites as an outside user would.  Check it out:

switchproxy

Fast unknown method invocation for loose coupling

November 26, 2008 by Bill Thorp

I was recently tasked to refactor a WinForms application. Now familiar with ASP.NET MVC, I wondered how easy it would be to apply existing ASP.NET MVC constructs to WinForms.  Implementing an IController is easy enough, but there’s still the matter of loose coupling within the IController’s execute method.

I’ve previously shown using reflection to allow loosely-coupled method invocation in ArcGIS Server Object Extensions, but reflection is wicked slow.  I knew that people were writing ORM binding using IL op-codes, and I figured that Microsoft had done something similar for ASP.NET MVC.

It turns out that LINQ expressions can be compiled into IL op-codes and that people are doing it to invoke unknown code quickly, without reflection.  No need to fire up Reflector to see Microsoft’s worth seeing LINQ implemenation, you can simply check CodePlex.

Fast SQL’08 Geometry Insertion

November 25, 2008 by Bill Thorp

If you’re inserting SQL’08 Native Spatial Datatypes into a brand new table, favor SqlBulkCopy over Insert. Its ridiculously faster. Below is some reduced code to show the basic idea:

// use minimal transaction logging during upload
new SqlCommand("alter database [" + dbName + "] SET RECOVERY BULK_LOGGED", connection).ExecuteNonQuery();

// create and a datatable of points
DataTable dt = new DataTable();
dt.Columns.Add("Shape", typeof(SqlGeometry));

// populate your SqlGeometry
dt = magicFunction_fillMyDataTableWithGeometry();

// copy data, use batches and tablelock to ensure small minimal transaction log sizes
using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString(dbName), SqlBulkCopyOptions.TableLock))
{
    sbc.DestinationTableName = tableName;
    sbc.BatchSize = 10000;
    sbs.ColumnMappings.Add("Shape", "Shape");
    sbc.WriteToServer(dt);
    sbc.Close();
}

// use normal transaction logging after upload
new SqlCommand("alter database [" + dbName + "] SET RECOVERY FULL", connection).ExecuteNonQuery();

Using ProjNET for point reprojection

November 21, 2008 by Bill Thorp

Are you – yes, you– firing up ArcObjects code just to do simple point reprojection?  Check out Proj.NET.  Grab the EPSG-code reader and point projection code from the very helpful FAQs and you’ll get something like this: [edit: fixed, thanks Morten ... definitely read the comments, this code was meant to show how easy things could be... its definitely not the ProjNet best practices]

public static double[] projectFromWgs84(double X, double Y, int destinationEpsgCode)
{
   double[] input = new double[] { X, Y };
   SC.ICoordinateSystem destProj = SridReader.GetCSbyID(destinationEpsgCode);
   SC.ICoordinateSystem sourceProj = SridReader.GetCSbyID(4236);
   SCT.CoordinateTransformationFactory ctf = new SCT.CoordinateTransformationFactory();
   SCT.IMathTransform xForm = ctf.CreateFromCoordinateSystems(sourceProj, destProj).MathTransform;
   return xForm.Transform(input);
}

AGS SOE’s without the SOAP

November 19, 2008 by Bill Thorp

Vish recently wrote about calling AGS SOEs via SOAP instead of DCOM.  He doesn’t mention that AGS doesn’t make you use SOAP, nor XML for that matter. This low-tech JSON-RPC invoker shows the proof-of-concept:

public string HandleStringRequest(string Capabilities, string request){
  MethodCall mc = JavaScriptConvert.DeserializeObject<MethodCall>(request);
  object result = this.GetType().GetMethod(mc.name).Invoke(this, mc.parameters);
  return JavaScriptConvert.SerializeObject(result);
}

public string test(string str1, string str2){
  return str1 + str2;
} 

class MethodCall{
  public string name;
  public object[] parameters;
}

 Here’s an action shot…

fiddler