Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coordinateSystemId on DbGeography

I need to geocode a large number of addresses, using the Bing Map service, EF 5 and SQL Server 2008. I'm using the geography data type in SQL, which translates to a DbGeography type by the EF.

When I create a DbGeography object, like this

string point = string.Format("POINT({0} {1})",address.Longitude,address.Latitude);
address.Location = System.Data.Spatial.DbGeography.PointFromText(point, 4326);

The second parameter calls for a "coordinateSystemId". What exactly is this? A lot of the examples I see use 4326. I am new to spatial data, but I'm guessing there is a set of well defined coordinate systems? I can't seem to find a definition.

like image 252
denvercoder9 Avatar asked Apr 02 '13 23:04

denvercoder9


2 Answers

There's a whole StackExchange for GIS, and if you, like me, bumble in there as a coder not knowing GIS, you are in for a ride:

https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet

It turns out there's a standard in mapping ("GIS") called EPSG, and people seem to use "EPSG," "EPSG SRID," and "SRID" interchangeably when referring to it. In most GPS coords usage, if you're talking about the Earth (including LatLngs you get from Google Maps), you're using EPSG SRID 4326, and if you're talking about a flat 2D map (like a Google Custom Map), you're talking about EPSG SRID 3857.

There's also some malarkey about WGS you can ignore.

.Net is only looking for the actual numeric ID in the EPSG SRID. It would be super helpful if these were just constants on DbGeography like:

public class DbGeography
{    
    public const int SridGps = 4326;
    public const int Srid2dPlane = 3857;

But no such luck.

Anyway consider making them constants in your application rather than just throwing around an undocumented magic number. Our little helper class:

public class GeoHelper
{
    public const int SridGoogleMaps = 4326;
    public const int SridCustomMap = 3857;



    public static DbGeography FromLatLng(double lat, double lng)
    {
        // http://codepaste.net/73hssg
        return DbGeography.PointFromText(
            "POINT("
            + lng.ToString() + " "
            + lat.ToString() + ")",
            SridGoogleMaps);
    }
}
like image 175
Chris Moschini Avatar answered Nov 14 '22 03:11

Chris Moschini


It is a well defined spatial reference identifier - a number that uniquely identifies a certain configuration of various spatial projections, datum, units, facing, etc.

like image 4
Jake H Avatar answered Nov 14 '22 05:11

Jake H