23. september 2012 08:21 by admin in
In a recent project we had to do some spatial search (finding nearest shops). With the new EntityFramework 5.0 in asp.net 4.5 this is finally possible. To get the nearest products (in a search) you write something like:
Now there can be some confusion about which type to use for location. There are two types to describe the 'location' of an object:
From MSDN:
DbGeography : Represents data in a geodetic (round earth) coordinate system.
DbGeometry : Provides a base class for objects that define geometric shapes.
Now here is a big difference. The first class being a point on earth and the second one a point (or shape). DbGeometry does not include anything about dimensions. This is clear when calculating the distance. When calculating distance for DbGeography the result is given in meters. For DbGeometry the result is still dimension less. A bit of code can say more than a thousand words...
So for real-world objects use DbGeography as location!