【问题标题】:Error - NetTopologySuite( When writing a SQL Server geography value, the shell of a polygon must be oriented counter-clockwise)错误 - NetTopologySuite(写入 SQL Server 地理值时,多边形的外壳必须逆时针方向)
【发布时间】:2022-01-18 15:11:11
【问题描述】:

所有,我正在为我的项目使用 NetTopologySuite/Entity Asp Core。我想为“searchArea”创建一个半径为 1000 米的半径,当我运行应用程序时,它给了我一个错误: System.ArgumentException:写入 SQL Server 地理值时,多边形的外壳必须逆时针方向。

     public IActionResult Structures()
        {
             var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);

             var searchAreCoordinate = new NetTopologySuite.Geometries.Coordinate(-1.3190967394026893, 51.748851810406954); // Not sure if long-lat or lat-long.
            var searchArea = geometryFactory.CreatePoint(searchAreCoordinate).Buffer(1000); // To me, this is 1000 meters because the SRID is WGS84.

           

var nearestStructures = _context.Structure
                    

                  .OrderBy(s=>s.Coordinates.Distance(searchArea))
                 // .Where (s=>s.Coordinates.Intersects(searchArea)) // This is why i want to buffer the searchArea to get the result from this intersetion
                  .Take(10).ToList();       
        
        return View(nearestStructures);


            // return View(_context.Structure.ToList());
        }

我的观点


@model IEnumerable<Structures>




    <table class="table"> 

<thead>

    <tr>
        <th>
                    @Html.DisplayNameFor(Model=>Model.Id)
        </th>
        <th>
                  @Html.DisplayNameFor(Model=>Model.gml_id)
        </th>
        <th>
                  @Html.DisplayNameFor(Model=>Model.structure)
        </th>
       
    </tr>
</thead>
<tbody>

    @foreach (var item in Model)
    {
         <tr>
        <td>
          
                    @Html.DisplayFor(Model=>item.Id)
        </td>
        <td>
                  @Html.DisplayFor(Model=>item.gml_id)
        </td>
        <td>
                  @Html.DisplayFor(Model=>item.structure)
        </td>
      
    </tr>
    }
</tbody>


    </table>

ps:我可以使用 SQL Spatial 实现此查询,如下所示:我知道不同的变量名称但相同的概念 p2:2 我的 SQL 表中的数据是地理

declare @meters int =   0.5/ 0.0006213712 select @meters as meters
declare @vehicle geography= geography::Point(51.748851810406954,-1.3190967394026893,4326).STBuffer(@meters) select @vehicle as Vehicle_Geo
select  Id,gml_id,Coordinates,Long,Lat,structure from [dbo].[Structure] where @vehicle.STIntersects(Coordinates) =1

【问题讨论】:

    标签: sql entity-framework asp.net-core geojson nettopologysuite


    【解决方案1】:

    var searchArea = geometryFactory.CreatePoint(searchAreCoordinate).Buffer(1000); // 对我来说,这是 1000 米,因为 SRID 是 WGS84。

    这是根本错误的。 NTS 不关心任何空间参考系统,它将每个坐标都视为平面坐标。

    如果您必须使用地理坐标并希望使用米进行缓冲/测量,则需要按照Srid ignored during client operations 中的说明进行操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 2014-05-23
      • 1970-01-01
      • 2012-10-29
      • 1970-01-01
      • 2018-07-22
      相关资源
      最近更新 更多