gpt4 book ai didi

sql-server - Entity Framework Core + 空间数据正在引发 SRID 无效错误

转载 作者:行者123 更新时间:2023-12-03 02:38:03 28 4
gpt4 key购买 nike

我收到以下错误:

ERROR: SqlException: .NET Framework error during routine execution or user-defined aggregate 'geography': System.ArgumentException: 24204: spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs shown in the sys.spatial_reference_systems catalog view.

当我尝试将这样创建的点保存到 SQL DB 时,会出现此错误

new Point(it.Lat, it.Lng)

之后我尝试使用像这样的GeometryFactory:

    public static class GeometryHelper
{
public static IGeometryFactory GeometryFactory { get; set; }
= NtsGeometryServices.Instance.CreateGeometryFactory();
}
...
geometryFactory.CreatePoint(new Coordinate(it.Lat, it.Lng))

什么也没有。

还尝试设置特定的 SRID:

    public static class GeometryHelper
{
public static IGeometryFactory GeometryFactory { get; set; }
= NtsGeometryServices.Instance.CreateGeometryFactory(4326);
}

但随后出现此错误:

SqlException: .NET Framework error during routine execution or user-defined aggregate 'geography': System.FormatException: One of the identified elements has an invalid format. System.FormatException:

最佳答案

发布问题后几分钟就解决了。关于第一个错误,解决它的正确方法是执行问题中的操作:创建几何工厂并使用 4326 作为 SRID。您必须检查您使用的 SRID 是否位于数据库表(sys.spatial_reference_systems 目录 View )中。显然 4326 是一个标准的,就像 Microsft 文档中一样。

    public static class GeometryHelper
{
public static IGeometryFactory GeometryFactory { get; set; }
= NtsGeometryServices.Instance.CreateGeometryFactory(4326);
}

第二个错误与点和经纬度对象之间的映射有关。

Longitude and Latitude Coordinates in NTS are in terms of X and Y values. To represent longitude and latitude, use X for longitude and Y for latitude. Note that this is backwards from the latitude, longitude format in which you typically see these values.

引用:Spatial in Ef Core

关于sql-server - Entity Framework Core + 空间数据正在引发 SRID 无效错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57209289/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com