错误 - NetTopologySuite(写入 SQL 服务器地理值时,多边形的 shell 必须逆时针方向)
Error - NetTopologySuite( When writing a SQL Server geography value, the shell of a polygon must be oriented counter-clockwise)
全部,我正在为我的项目使用 NetTopologySuite/ Entity Asp Core。我想为 'searchArea ' 创建 1000 米的半径当我 运行 应用程序时,它给我一个错误:
System.ArgumentException: 写入SQL 服务器地理值时,多边形的shell 必须逆时针方向。
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 实现此查询,如下所示:我知道 varabiels 的不同名称但概念相同
p2:2 我 SQL table 中的数据是地理
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
var searchArea = geometryFactory.CreatePoint(searchAreCoordinate).Buffer(1000); // To me, this is 1000 meters because the SRID is WGS84.
这是根本错误的。 NTS 不关心任何空间参考系统,它将每个坐标都视为平面坐标。
如果您必须使用地理坐标并希望 buffer/measure 使用米,则需要按照 Srid ignored during client operations 中给出的说明进行操作。
全部,我正在为我的项目使用 NetTopologySuite/ Entity Asp Core。我想为 'searchArea ' 创建 1000 米的半径当我 运行 应用程序时,它给我一个错误: System.ArgumentException: 写入SQL 服务器地理值时,多边形的shell 必须逆时针方向。
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 实现此查询,如下所示:我知道 varabiels 的不同名称但概念相同 p2:2 我 SQL table 中的数据是地理
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
var searchArea = geometryFactory.CreatePoint(searchAreCoordinate).Buffer(1000); // To me, this is 1000 meters because the SRID is WGS84.
这是根本错误的。 NTS 不关心任何空间参考系统,它将每个坐标都视为平面坐标。
如果您必须使用地理坐标并希望 buffer/measure 使用米,则需要按照 Srid ignored during client operations 中给出的说明进行操作。