DbGeography 上的坐标系统 ID

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

问题描述

我需要使用 Bing 地图服务、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:

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

事实证明,地图(GIS")中有一个名为 EPSG 的标准,人们在提及它时似乎可以互换使用EPSG"、EPSG SRID"和SRID".在大多数 GPS 坐标使用中,如果您谈论的是地球(包括您从谷歌地图获得的纬度),那么您使用的是 EPSG SRID 4326,如果您谈论的是平面 2D 地图(如谷歌自定义地图),您说的是 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 上的坐标系统 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)