sql 服务器中的空间索引

Spatial Indexing in sql server

我正在尝试从 postgres 迁移到 sql-server(windows)。但我不知道 ms-sql 语法和文档也对我没有好处。 我有一个 table 'geocodes' 以十进制格式存储纬度和经度数据。 我有一个使用 postgis

索引经纬度数据的迁移
create index index_on_geocodes_location ON geocodes using gist (st_geographyfromtext(((('POINT('::text || longitude) || ' '::text) || latitude) || ')'::text))

我很难为 sql-server 生成等效的查询。 根据文档,如果列数据类型是地理,这很容易,但由于我已经有一个具有十进制数据类型的现有数据库,这不会有帮助。

PS:我正在使用 rails 迁移来执行查询

假设你的用例正在执行空间查询,否则没有必要制作空间索引。 SQL 服务器中的空间索引可以在空间数据类型的列之上创建 - 几何(平面)或地理(弯曲)。您可以创建持久计算列并在其上创建索引,如下所示(假设地理数据类型和 SRID 4326):

create table Geocodes(
id int identity primary key,
long decimal,
lat decimal,
point as geography::Point(long, lat, 4326) persisted
)

create spatial index SPIX_Geocodes_Point on Geocodes(point) using geography_auto_grid