SQL 2008地理与地理几何 - 使用哪个?

发布于 2024-08-14 04:07:12 字数 204 浏览 15 评论 0原文

我正在创建一个 Google 地图混搭并使用 SQL 2008。

我将在地球上拥有大量点,并且希望在 SQL 中对它们执行各种计算 - 例如选择特定多边形内包含的所有点,或选择XY 10 公里以内的所有点。

我以前从未使用过 SQL 空间功能。我应该使用 geography 还是 geometry 数据类型?

I'm creating a Google map mashup and am using SQL 2008.

I will have a large number of points on the earth and will want to perform various calculations on them in SQL - such as selecting all points contained within a particular polygone, or select all points within 10km of XY.

I have never used and SQL spatial features before. Should I use the geography or the geometry datatype for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

关于从前 2024-08-21 04:07:12

地理是用于在地球上绘制点的类型。

如果您有一个存储 Google 地图点的表,如下所示:

CREATE TABLE geo_locations (
    location_id       uniqueidentifier  NOT NULL,
    position_point    geography         NOT NULL
);

那么您可以使用以下存储过程在其中填充点:

CREATE PROCEDURE proc_AddPoint
    @latitude     decimal(9,6),
    @longitude    decimal(9,6),
    @altitude     smallInt
AS

DECLARE @point     geography = NULL;

BEGIN

    SET NOCOUNT ON;

    SET @point = geography::STPointFromText('POINT(' + CONVERT(varchar(15), @longitude) + ' ' + 
                                                       CONVERT(varchar(15), @latitude) + ' ' + 
                                                       CONVERT(varchar(10), @altitude) + ')', 4326)

    INSERT INTO geo_locations
    (
        location_id, 
        position_point
    )
    VALUES 
    (
        NEWID(),
        @point
    );

END

然后,如果您想查询纬度、经度和海拔高度,只需使用以下查询格式:

SELECT
    geo_locations.position_point.Lat  AS latitude,
    geo_locations.position_point.Long AS longitude,
    geo_locations.position_point.Z    AS altitude
FROM
    geo_locations;

Geography is the type that is intended for plotting points on the earth.

If you have a table that stores Google Maps points like this:

CREATE TABLE geo_locations (
    location_id       uniqueidentifier  NOT NULL,
    position_point    geography         NOT NULL
);

then you could fill points in it with this stored procedure:

CREATE PROCEDURE proc_AddPoint
    @latitude     decimal(9,6),
    @longitude    decimal(9,6),
    @altitude     smallInt
AS

DECLARE @point     geography = NULL;

BEGIN

    SET NOCOUNT ON;

    SET @point = geography::STPointFromText('POINT(' + CONVERT(varchar(15), @longitude) + ' ' + 
                                                       CONVERT(varchar(15), @latitude) + ' ' + 
                                                       CONVERT(varchar(10), @altitude) + ')', 4326)

    INSERT INTO geo_locations
    (
        location_id, 
        position_point
    )
    VALUES 
    (
        NEWID(),
        @point
    );

END

Then if you want to query for the latitude, longitude and altitude, simply use the following query format:

SELECT
    geo_locations.position_point.Lat  AS latitude,
    geo_locations.position_point.Long AS longitude,
    geo_locations.position_point.Z    AS altitude
FROM
    geo_locations;
当爱已成负担 2024-08-21 04:07:12

中给出的答案

您可以按照 PostGIS FAQ 我很困惑。我应该使用几何或地理哪个数据存储?

简短回答:地理是一种新数据
支持远距离类型
距离测量。如果你使用
地理——你不需要学习
关于平面坐标系的更多信息。
如果你都的话,地理通常是最好的
关心的是测量距离和
长度并且你有来自所有的数据
世界各地。几何数据类型是
具有许多的旧数据类型
支持它的功能并享受
第三方工具的大力支持。
如果你很舒服的话那就最好了
使用空间参考系统或您
正在处理本地化数据,其中
您的所有数据都适合一个空间
参考系统(SRID),或者您需要
进行大量的空间处理。
请参阅第 8.8 节“PostGIS
功能支持矩阵”看看有什么
目前支持什么
不是。

PostGIS 和 SQL Server 这两个数据库中的几何和地理类型遵循相同的概念,因此 PostGIS FAQ 中给出的答案适用于您的问题。

You can follow the answer given in PostGIS FAQ

I'm all confused. Which data store should I use geometry or geography?

Short Answer: geography is a new data
type that supports long range
distances measurements. If you use
geography -- you don't need to learn
much about planar coordinate systems.
Geography is generally best if all you
care about is measuring distances and
lengths and you have data from all
over the world. Geometry datatype is
an older data type that has many
functions supporting it and enjoys
great support from third party tools.
Its best if you are pretty comfortable
with spatial reference systems or you
are dealing with localized data where
all your data fits in a single spatial
reference system (SRID), or you need
to do a lot of spatial processing.
Refer to Section 8.8, “PostGIS
Function Support Matrix” to see what
is currently supported and what is
not.

The geometry and geography types in both databases, PostGIS and SQL Server, follow the same concept, so the answer given in the PostGIS FAQ is applicable to your problem.

躲猫猫 2024-08-21 04:07:12

您很可能需要地理类型,因为它考虑了地球的曲率。几何更多地是为了“平面”地看待事物。查看这篇文章以获取更多信息
http://www.mssqltips.com/tip.asp?tip=1847

Most likely you want the geography type since it accounts for the curvature of the earth. Geometry is more for a "flat" view of things. Check out this article for more info
http://www.mssqltips.com/tip.asp?tip=1847

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文