文字列ポリゴンを作る方法の検討


何かの役にたちそうな、たたなそうな。
StingPolygon

GraphicsPath クラス
http://msdn.microsoft.com/ja-jp/library/system.drawing.drawing2d.graphicspath(v=vs.110).aspx
PathTypes で判別かければポリゴン始終点が見える。
CAD用ポリゴン生成とか?

コードから作られた図形用クエリ

DECLARE @geom GEOMETRY;

SET @geom = GEOMETRY::STGeomFromText('Polygon((12.76172 4.681641,3.199219 4.681641,3.199219 3.867188,12.76172 3.867188,8.876953 8.279297,8.876953 9.264038,8.713989 10.06677,8.387695 10.68787,8.061768 11.30896,7.546875 11.83557,6.84375 12.26697,6.140625 12.69873,5.24231 13.02539,4.148438 13.24805,3.832031 12.42188,5.058838 12.1604,6.031494 11.72791,6.75 11.12439,7.468872 10.52087,7.828125 9.644897,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,26.0332 12.62695,25.20117 13.27148,24.1311 12.17029,22.66809 10.83838,20.8125 9.275391,18.87122 11.14307,16.93945 12.45923,15.01758 13.22461,14.57227 12.48047,16.18176 11.82458,17.7843 10.78455,19.37988 9.360718,20.97583 7.93689,22.09387 6.381226,22.73438 4.693359,16.04883 4.693359,16.04883 3.878906,23.78906 3.878906,24.0293 4.095703,23.48254 5.752441,22.60547 7.26416,21.39844 8.630859,22.59375 9.564697,24.13879 10.89697,26.0332 12.62695,38.10352 9.076172,37.48828 9.890625,36.67603 9.3479,35.7052 8.815063,34.57617 8.291382,33.44751 7.768066,32.44153 7.373291,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.88696 6.900879,36.06445 7.857788,38.10352 9.076172,12.76172 4.681641))',0);
SET @geom = @geom.MakeValid();

SELECT @geom;

コード適当

var font = new FontFamily("メイリオ");
var pt = new Point(0, 0);

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

  StringBuilder sb = new StringBuilder();

  foreach (var point in drawPath.PathPoints)
  {
    if (sb.Length < 1)
      sb.AppendFormat("{0} {1}", point.X, point.Y);
    else
      sb.AppendFormat(",{0} {1}", point.X, point.Y);
  }
  if (sb.Length > 0)
    sb.AppendFormat(",{0} {1}", drawPath.PathPoints[0].X, drawPath.PathPoints[0].Y);

  string wkt = string.Format("Polygon(({0}))", sb.ToString());
}//end path
カテゴリー: 開発 タグ: , パーマリンク