【问题标题】:Convert Geometry to Geography将几何转换为地理
【发布时间】:2018-11-30 09:39:06
【问题描述】:

我想在 SQL Server 中将几何转换为地理;我关注了这篇文章:

https://blogs.msdn.microsoft.com/edkatibah/2008/08/19/working-with-invalid-data-and-the-sql-server-2008-geography-data-type-part-1b/

这是我的查询:

INSERT INTO gCOMMUNE         
SELECT 
      [dbo].[commune].[ogr_fid], 
      GEOGRAPHY::STGeomFromWKB(commune.ogr_geometry.STAsBinary(),4326)
FROM [IMMATS].[dbo].[commune]

但是当我运行转换命令时,我得到了这个错误:

Msg 213, Level 16, State 1, Line 26 提供的值的名称或列号与表的定义不匹配。

【问题讨论】:

  • 错误信息很清楚“提供的值的名称或列号与表的定义不匹配。” gCOMMUNE 表的列是什么?它们是否只有 2 个 - 第一个与 [dbo].[commune].[ogr_fid] 具有相同类型,第二个是 GEOGRAPHY?如果没有,您必须指定要插入数据的列名。

标签: sql-server sql-server-2012 sql-server-2016 spatial-data


【解决方案1】:

看起来gCOMMUNE 表的列数与选择要插入其中的数据的查询不同。您必须在INSERT INTO 语句中指定列名。假设有名为 idgeom 的列(根据您的说明,它们是 [ogr_fid] 和 [ogr_geog]),您的语句如下所示:

INSERT INTO gCOMMUNE([ogr_fid], [ogr_geog])
SELECT 
      [dbo].[commune].[ogr_fid], 
      GEOGRAPHY::STGeomFromWKB(commune.ogr_geometry.STAsBinary(),4326)
FROM [IMMATS].[dbo].[commune]

【讨论】:

  • 请看我下面的评论
  • 我更新了答案以反映真实的列名。
  • 我使用你给我的请求我得到这个错误是正确的
  • Msg 6522, Level 16, State 1, Line 26 执行用户定义的例程或聚合函数“geography”时出现.NET Framework错误:System.FormatException: 24201: Latitude values ​​​​必须在 -90 到 90 度之间。
  • System.FormatException: 在 Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint (Double x, Double y, Nullable1 z, Nullable1 m) 在 Microsoft.SqlServer.Types.Validator.BeginFigure (Double x, Double y, Nullable1 z, Nullable1 m) 在 Microsoft.SqlServer.Types.ForwardingGeoDataSink.BeginFigure (Double x, Double y, Nullable1 z, Nullable1 m) 在 Microsoft.SqlServer.Types.CoordinateReversingGeoDataSink.BeginFigure
猜你喜欢
  • 2011-10-04
  • 2013-04-18
  • 2021-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-18
  • 1970-01-01
  • 2020-10-01
相关资源
最近更新 更多