メッシュ的な何かを作る方法


とりあえずテンポラリで下記のような格子を作れる。
SQL Server 2012

Mesh

USE データベース名
GO

DECLARE @jpn geometry =  (SELECT
 geometry::UnionAggregate(shape) as Shape
FROM
 JPN71);

DECLARE @env geometry = @jpn.STEnvelope();

DECLARE @envWidth float = @env.STPointN(3).STX - @env.STPointN(1).STX;
DECLARE @envHeight float = @env.STPointN(3).STY - @env.STPointN(2).STY;

DECLARE @orgX float = @env.STPointN(1).STX,
        @orgY float = @env.STPointN(1).STY;

/*
DECLARE @numcolumns float = 100, @numrows float = 80;

DECLARE @cellwidth float = @envWidth / @numcolumns;
DECLARE @cellheight float = @envHeight / @numrows;
*/
DECLARE @cellwidth float = 1
DECLARE @cellheight float = 40.0 / 60.0

DECLARE @numcolumns float = floor(@envWidth / @cellwidth),
        @numrows float = floor(@envHeight / @cellheight);

DECLARE @gridcells table (id int, geom geometry)
--y row
DECLARE @row int = 0, @col int = 0;

WHILE @row < @numrows
BEGIN
  WHILE @col < @numcolumns
  BEGIN
   INSERT INTO @gridcells VALUES(
     @row * @numcolumns + @col,
    geometry::STPolyFromText(
	  'POLYGON((' + cast(@orgX + (@col * @cellwidth) AS varchar(32)) + ' ' + cast(@orgY + (@row * @cellheight) AS varchar(32)) + ','
      + cast(@orgX + ((@col + 1)  * @cellwidth) AS varchar(32)) + ' ' + cast(@orgY + (@row * @cellheight) AS varchar(32)) + ','
      + cast(@orgX + ((@col + 1)  * @cellwidth) AS varchar(32)) + ' ' + cast(@orgY + ((@row + 1) * @cellheight) AS varchar(32)) + ','
      + cast(@orgX + (@col * @cellwidth) AS varchar(32)) + ' ' + cast(@orgY + ((@row + 1) * @cellheight) AS varchar(32)) + ','
      + cast(@orgX + (@col * @cellwidth) AS varchar(32)) + ' ' + cast(@orgY + (@row * @cellheight) AS varchar(32)) + '))',
	  @jpn.STSrid)
    );

    SET @col = @col + 1;
  END
  SET @col = 0;
  SET @row = @row + 1;
END

--SELECT geom.STIntersection(@jpn) FROM @gridcells ORDER BY id;
SELECT * FROM @gridcells WHERE geom.STIntersects(@jpn) = 1 ORDER BY id;
カテゴリー: 開発, 設計 タグ: パーマリンク