タイルポリゴン作成


出来上がりタイル
TILE

Canvasでのxyz確認
TILE_WEB

タイルと同一のポリゴンを作成したいときのクエリ

メッシュデータ作成は一番簡単なデータ作成方法なので初心に帰れるかも。
GIS始める際には必ず作ってみるはず。。



DECLARE @envWidth float = 20037507.0671618 - -20037507.0671618;
DECLARE @envHeight float = 19971868.8804086 - -19971868.8804086;

DECLARE @orgX float = -20037508.342787,
        @orgY float = 20037508.342787;

--タイルレベル Z
DECLARE @level int = 5;

-- 0.0254=1インチ
-- 2.66666インチ = 96DPI 256px
-- 591657527.591555は最大縮尺
DECLARE @cellwidth float = 591657527.591555 / POWER(2, @level) * (0.0254 * 2.666666666666666)
DECLARE @cellheight float = @cellwidth;

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

---DECLARE @gridcells table (id int, geom geometry)
CREATE TABLE W_GRID_5 
(
  id int PRIMARY KEY,
  l_z int,
  r_x int,
  c_y int,
  geom geometry
);

--y row
DECLARE @row int = 0, @col int = 0;

WHILE @row < @numrows
BEGIN
  WHILE @col < @numcolumns
  BEGIN
   INSERT INTO W_GRID_5 VALUES(
     @row * @numcolumns + @col, -- id
	 @level,
	 @col,
	 @row,
    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)) + '))',
	  3857)
    );
SET @col = @col + 1;
  END
  SET @col = 0;
  SET @row = @row + 1;
END
カテゴリー: 開発 タグ: パーマリンク