所有,我的项目使用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实现这个查询,如下所示:我知道varabiels的名称不同,但概念相同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
var searchArea=geometryFactory.CreatePoint(searchAreCoordinate(.Buffer(1000(;//对我来说,这是1000米,因为SRID是WGS84。
这是根本错误的。NTS不关心任何空间参考系,它将每个坐标视为平面坐标。
如果您必须使用地理坐标,并希望使用仪表进行缓冲/测量,则需要遵循Srid中给出的指示,在客户端操作过程中忽略这些指示。