Tuesday, February 19, 2013

GetCenterPtFromLn

private SqlGeometry GetCenterPtFromLn(SqlGeometry rd)
        {
            int n = rd.STNumPoints().Value;
            Vector centpt;
            if (n % 2 == 0)
            {
                Vector pt1 = new Vector(rd.STPointN(n / 2).STX.Value, rd.STPointN(n / 2).STY.Value),
                    pt2 = new Vector(rd.STPointN(n / 2 + 1).STX.Value, rd.STPointN(n / 2 + 1).STY.Value);
                centpt = (pt1 + pt2) / 2;
            }
            else
                centpt = new Vector(rd.STPointN((n + 1) / 2).STX.Value, rd.STPointN((n + 1) / 2).STY.Value);
            return Point2PointGeometry(centpt);
        }

No comments:

Post a Comment