沒有長進

二十幾年前,初次學寫程式時,就嘗試畫多邊形,二十多年後,沒想到還在學用 T-SQL 畫多邊形…

–Geometry 沒有方向性
SELECT *,Geom.STArea(),Geom.ToString() FROM (
SELECT ‘內圈(逆時針方向)’  AS Label,
geometry::STPolyFromText(
‘POLYGON ( (10 10, 30 10, 30 30, 10 30, 10 10))’,4326) AS Geom
UNION ALL
SELECT REPLICATE(CHAR(13)+CHAR(10),12)+ ‘方圈(內圈順時針,外圈逆時針)’  AS Label,
geometry::STPolyFromText(
‘POLYGON ((0 0, 40 0, 40 40, 0 40, 0 0),(10 10, 10 30, 30 30, 30 10, 10 10))’,4326)
UNION ALL
SELECT REPLICATE(CHAR(13)+CHAR(10),20)+’外圈’  AS Label,
geometry::STPolyFromText(
‘POLYGON ( (-10 -10, 50 -10,50 50,-10 50, -10 -10),(0 0, 0 40, 40 40, 40 0, 0 0) )’,4326).MakeValid()  — Geometry 外圍的要在外圈
) T

image

 

Geography 則 Ring 有方向性

–Geography 有方向性
SELECT *,Geom.STArea(),Geom.ToString() FROM (
SELECT ‘內圈(逆時針方向)’  AS Label,
geography::STPolyFromText(
‘POLYGON ( (10 10, 30 10, 30 30, 10 30, 10 10))’,4326) AS Geom
UNION ALL
SELECT REPLICATE(CHAR(13)+CHAR(10),12)+ ‘方圈(內圈順時針,外圈逆時針)’  AS Label,
geography::STPolyFromText(
‘POLYGON ((10 10, 10 30, 30 30, 30 10, 10 10),(0 0, 40 0, 40 40, 0 40, 0 0))’,4326)
UNION ALL
SELECT REPLICATE(CHAR(13)+CHAR(10),20)+’外圈’  AS Label,
geography::STPolyFromText(
‘POLYGON ( (0 0, 0 40, 40 40, 40 0, 0 0),(-10 -10, 50 -10,50 50,-10 50, -10 -10) )’,4326)
) T

image

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: