テキストポリゴンを構築する方法[一応完]


text_polygons

昨日の続き、あとは地理座標に合わせて座標変換すればOKか。
左上原点になるので地点座標と幅高さを合わせれば投影可能か。

クエリ

DECLARE @geom GEOMETRY;

SET @geom = GEOMETRY::STGeomFromText('Polygon((12.76172 -4.681641,3.199219 -4.681641,3.199219 -3.867188,12.76172 -3.867188,12.76172 -4.681641),(8.876953 -8.279297,8.876953 -9.263672,8.713866 -10.06641,8.387695 -10.6875,8.061522 -11.30859,7.546875 -11.83496,6.84375 -12.2666,6.140625 -12.69824,5.242187 -13.02539,4.148438 -13.24805,3.832031 -12.42188,5.058593 -12.16016,6.03125 -11.72754,6.75 -11.12402,7.46875 -10.52051,7.828125 -9.644531,7.828125 -8.496094,7.828125 -7.886719,2.513672 -7.886719,2.513672 -7.03125,13.48242 -7.03125,13.48242 -7.886719,8.876953 -7.886719,8.876953 -8.279297),(26.0332 -12.62695,25.20117 -13.27148,24.13086 -12.16992,22.66797 -10.83789,20.8125 -9.275391,18.87109 -11.14258,16.93945 -12.45898,15.01758 -13.22461,14.57227 -12.48047,16.18164 -11.82422,17.78418 -10.78418,19.37988 -9.360352,20.97558 -7.936523,22.09375 -6.380859,22.73438 -4.693359,16.04883 -4.693359,16.04883 -3.878906,23.78906 -3.878906,24.0293 -4.095703,23.48242 -5.751954,22.60547 -7.263672,21.39844 -8.630859,22.59375 -9.564453,24.13867 -10.89648,26.0332 -12.62695,26.0332 -12.62695),(38.10352 -9.076172,37.48828 -9.890625,36.67578 -9.347656,35.70507 -8.814453,34.57617 -8.291016,33.44726 -7.767578,32.4414 -7.373047,31.55859 -7.107422,31.55859 -13.32422,30.51563 -13.32422,30.51563 -3.064453,31.57031 -3.064453,31.57031 -6.205078,33.88671 -6.900391,36.06445 -7.857422,38.10352 -9.076172,38.10352 -9.076172))',0);
SET @geom = @geom.MakeValid();

SELECT @geom;

コード (WKT構築用)

using (GraphicsPath drawPath = new System.Drawing.Drawing2D.GraphicsPath())
{
  drawPath.AddString("テスト", font, 0, 12f, pt, null);

  StringBuilder sb = new StringBuilder();
  int index = 0;
  byte[] types = drawPath.PathTypes;

  float x = float.NaN, y = float.NaN;

  bool isStart = true;
  foreach (var point in drawPath.PathPoints)
  {
    byte type = types[index];
    Debug.Print("{0}",type);
    if (type == 0)
    {
      if (!float.NaN.Equals(x) && !float.NaN.Equals(y))
        sb.AppendFormat(",{0} {1})", x, y);
      x = point.X;
      y = point.Y * -1;
      if (sb.Length > 0)
        sb.Append(",");

      sb.Append("(");
      isStart = true;
    }
    else
      isStart = false;

    if (isStart)
      sb.AppendFormat("{0} {1}", point.X, point.Y * -1);
    else
      sb.AppendFormat(",{0} {1}", point.X, point.Y * -1);

    index++;
  }
  if (!float.NaN.Equals(x) && !float.NaN.Equals(y))
    sb.AppendFormat(",{0} {1})", x, y);

  string wkt = string.Format("Polygon({0})", sb.ToString());

}//end path
カテゴリー: 開発 タグ: , パーマリンク