我在 sql2005 db 中有一个多边形结构,如下所述。
CREATE TABLE [dbo].[Polygons](
[PolygonID] [int] IDENTITY(1,1) NOT NULL,
[PolygonName] [varchar](255) NOT NULL,
[PolygonColor] [varchar](7) NOT NULL,
[PolygonRuleID] [int] NOT NULL)
CREATE TABLE [dbo].[Polylines](
[LineID] [int] IDENTITY(1,1) NOT NULL,
[LineX1] [float] NOT NULL,
[LineY1] [float] NOT NULL,
[LineX2] [float] NOT NULL,
[LineY2] [float] NOT NULL,
[PolygonID] [int] NOT NULL
)
现在我将整行检索到应用程序并全部用于命中测试功能。
public static bool PointInPolygon(float pointX, float pointY, PolylineCollection polygon)
{
int nvert = polygon.Count();
int i, j = 0;
bool c = false;
for (i = 0, j = nvert - 1; i < nvert; j = i++)
{
if (((polygon[i].LineY1 > pointY) != (polygon[j].LineY1 > pointY)) &&
(pointX < (polygon[j].LineX1 - polygon[i].LineX1) * (pointY - polygon[i].LineY1) / (polygon[j].LineY1 - polygon[i].LineY1) + polygon[i].LineX1))
c = !c;
}
return c;
}
但我需要将此功能移动到 sql server。但是 Sql 2005 没有本机空间功能,我不想使用任何额外的空间功能库。如何将此函数移植到 T-SQL?:) 或者任何人对 PointInPolygon 检查有不同的解决方案?
谢谢