本文介绍了DbGeography上的ordinateSystemId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Bing Map服务,EF 5和SQL Server 2008对大量地址进行地理编码。我正在使用SQL中的地理位置数据类型,该数据类型由EF转换为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.

当我创建DbGeography对象时,像这样

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);

第二个参数要求使用 coordinateSystemId。这到底是什么?我看到的许多示例都使用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.

推荐答案

有一个完整的StackExchange for GIS,如果像我一样,你很沮丧作为不了解GIS的编码人员,您可以乘车游览

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:

事实证明,映射中有一个称为EPSG的标准,人们似乎在使用 EPSG, EPSG SRID和 SRID在引用时可以互换。在大多数GPS坐标用法中,如果您谈论的是地球(包括从Google Maps获得的LatLng),则使用的是EPSG SRID 4326,如果您谈论的是平面2D地图(例如Google Custom Map) ,您正在谈论的是EPSG SRID 3857。

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.

对于WGS,还有一些恶意代码可以忽略。

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

.Net只在EPSG SRID中查找实际的数字ID。如果这些只是DbGeography上的常数,将非常有帮助,例如:

.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;

但是没有这种运气。

无论如何考虑在您的应用程序中使它们成为常量,而不是仅仅抛出未记录的幻数。我们的小助手类:

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);
    }
}

这篇关于DbGeography上的ordinateSystemId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-31 01:59