{"id":401,"date":"2008-01-22T17:32:40","date_gmt":"2008-01-22T16:32:40","guid":{"rendered":"http:\/\/soci.hu\/blog\/index.php\/2008\/01\/22\/sql-server-2008-ujdonsagok-15-terbeli-adattipusok-2\/"},"modified":"2008-01-25T10:25:28","modified_gmt":"2008-01-25T09:25:28","slug":"sql-server-2008-ujdonsagok-15-terbeli-adattipusok-2","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2008\/01\/22\/sql-server-2008-ujdonsagok-15-terbeli-adattipusok-2\/","title":{"rendered":"SQL Server 2008 \u00fajdons\u00e1gok 16. &#8211; t\u00e9rbeli adatt\u00edpusok 2."},"content":{"rendered":"<p>Az el\u0151z\u0151 r\u00e9sz v\u00e9g\u00e9n volt egy k\u00e9p, ami vizualiz\u00e1lta a geometriai alakzatokat. Ez a kis program a <a href=\"http:\/\/www.conceptdevelopment.net\/Database\/Geoquery\/\">GeoQuery 2008<\/a>, \u00e9s rendk\u00edv\u00fcl j\u00f3 szolg\u00e1latot tesz megn\u00e9zni, melyik f\u00fcggv\u00e9ny mire szolg\u00e1l.<\/p>\n<p>Ebben a r\u00e9szben bemutatok p\u00e1r geometry met\u00f3dust, szem\u00e9rmetlen\u00fcl ellopva a program be\u00e9p\u00edtett msdn p\u00e9ld\u00e1it (k\u00f6sz\u00f6net a szerz\u0151nek a feldolgoz\u00e1s\u00e9rt). P\u00e1rat az\u00e9rt \u00e9n is sz\u00fcltem. :)<\/p>\n<p>A p\u00e9ld\u00e1kban a Thickness \u00e9s a Color oszlopok csak a programnak sz\u00f3lnak, hogyan jelen\u00edtse meg az alakzatokat.<\/p>\n<p>Ter\u00fcletsz\u00e1m\u00edt\u00e1s, <strong>STArea<\/strong>:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nSET @g = geometry::STGeomFromText(&#039;POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))&#039;, 0);\r\nSELECT @g, @g.STArea() as &#x5B;AreaInUnits], 0.1 as &#x5B;Thickness];\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n8\r\n<\/pre>\n<p><a target='_blank' href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/starea.png' title='starea.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/starea.png' alt='starea.png' \/><\/a><\/p>\n<p>Azaz van egy 3&#215;3-as n\u00e9gyzet\u00fcnk, amiben van egy 1&#215;1-es luk. \u00cdgy a ter\u00fclete 8, nem meglep\u0151.<\/p>\n<p>Hat\u00e1rol\u00f3vonalak, <strong>STBoundary<\/strong>. Ez m\u00e1r nem teljesen trivi\u00e1lis, a BOL sem seg\u00edt egyel\u0151re, csak a <a href=\"http:\/\/portal.opengeospatial.org\/files\/?artifact_id=829\">szabv\u00e1ny<\/a>.<\/p>\n<p>&#8220;-Point and MultiPoint instances do not have a boundary.<br \/>\n-LineString and MultiLineString boundaries are formed by the start points and end points, removing those that occur an even number of times.&#8221;<br \/>\n-The boundary of a Polygon consists of a set of LinearRings that make up its exterior and interior boundaries.&#8221;<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nSET @g = geometry::STPolyFromText(&#039;POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))&#039;, 10);\r\nSELECT &#039;Red&#039; Color, 0.2 as &#x5B;Thickness], @g\r\nunion all\r\nselect &#039;Yellow&#039; Color, 0.1 as &#x5B;Thickness], @g.STBoundary()\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nPOLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))\r\nMULTILINESTRING((1 1, 1 2, 2 1, 1 1), (0 0, 3 0, 0 3, 0 0))\r\n<\/pre>\n<p><a target='_blank'  href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stboundary1.png' title='stboundary1.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stboundary1.png' alt='stboundary1.png' \/><\/a><\/p>\n<p>A piros az alakzat, a s\u00e1rga a hat\u00e1rol\u00f3vonala. A kett\u0151 egybeesik, csak az ir\u00e1nyuk m\u00e1s, ez a kimenetb\u0151l l\u00e1tszik, illetve az egyik soksz\u00f6g, a m\u00e1sik vonalak halmaza.<\/p>\n<p>Ugyanez vonalakkal:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nSET @g = geometry::STGeomFromText(&#039;LINESTRING(0 0, 2 2, 0 2, 2 0)&#039;, 0);\r\nSELECT @g, @g.STBoundary(), 0.1 as &#x5B;Thickness];\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nLINESTRING(0 0, 2 2, 0 2, 2 0)\r\nMULTIPOINT((2,0), (0,0))\r\n<\/pre>\n<p><a target='_blank'  href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stboundary.png' title='stboundary.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stboundary.png' alt='stboundary.png' \/><\/a><\/p>\n<p>L\u00e1tszik, hogy a szabv\u00e1nynak megfelel\u0151 a kimenet.<\/p>\n<p><strong>STBuffer<\/strong>. Azokat a pontokat adja vissza, amelyek egy alakzatt\u00f3l a megadott t\u00e1vols\u00e1gra, vagy ann\u00e1l k\u00f6zelebb fekszenek.<br \/>\nEgyszer\u0171 vonallal:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nSET @g = geometry::STGeomFromText(&#039;LINESTRING(0 0, 4 0)&#039;, 0);\r\nSELECT @g, @g.STBuffer(1), 0.1 as &#x5B;Thickness];\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nMarha sok pontb\u00f3l \u00e1ll\u00f3 POLYGON.\r\n<\/pre>\n<p><a target='_blank'  href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stbuffer1.png' title='stbuffer1.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stbuffer1.png' alt='stbuffer1.png' \/><\/a><\/p>\n<p>Bonyolultabb soksz\u00f6ggel:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nSET @g = geometry::STGeomFromText(&#039;POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))&#039;, 0);\r\nSELECT @g, 0.1 as &#x5B;Thickness], &#039;Red&#039; as Color\r\nunion all \r\nselect @g.STBuffer(1), 0.1 as &#x5B;Thickness], &#039;Yellow&#039; as Color;\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nMarha sok pontb\u00f3l \u00e1ll\u00f3 POLYGON.\r\n<\/pre>\n<p><a target='_blank'  href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stbuffer2.png' title='stbuffer2.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stbuffer2.png' alt='stbuffer2.png' \/><\/a><\/p>\n<p>A s\u00e1rga vonal a sz\u00e1m\u00edtott Buffer.<\/p>\n<p>K\u00f6z\u00e9ppont sz\u00e1m\u00edt\u00e1s, <strong>STCentroid<\/strong>. Matekosok ut\u00e1nakereshetnek, hogy sz\u00e1molj\u00e1k (\u00e9rdekelne a link).<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nSET @g = geometry::STGeomFromText(&#039;POLYGON((0 0, 3 0, 3 3, 0 3, 0 0),(2 2, 2 1, 1 1, 1 2, 2 2))&#039;, 0);\r\nSELECT @g, @g.STCentroid(), 0.1 as &#x5B;Thickness];\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nPOINT(1.5 1.5)\r\n<\/pre>\n<p><a target='_blank'  href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stcentroid1.png' title='stcentroid1.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stcentroid1.png' alt='stcentroid1.png' \/><\/a><\/p>\n<p>Ez k\u00f6nny\u0171 volt. Bonyolultabb alakzatra meg majd kisz\u00e1molja a g\u00e9p. :)<\/p>\n<p>Tartalmazza-e az egyik alakzat a m\u00e1sikat (teljesen), <strong>STContains<\/strong>:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nDECLARE @h geometry;\r\nSET @g = geometry::STGeomFromText(&#039;POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))&#039;, 0);\r\nSET @h = geometry::STGeomFromText(&#039;POINT(1 1)&#039;, 0);\r\nSELECT @g, @h, @g.STContains(@h), 0.1 as &#x5B;Thickness];\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n1\r\n<\/pre>\n<p>Azt mondja, benne van, meglep\u0151. K\u00e9pet most nem mell\u00e9kelek, l\u00e1ttunk m\u00e1r ilyen n\u00e9gyzetet.<\/p>\n<p>Konk\u00e1vb\u00f3l konvex, <strong>STConvexHull<\/strong>:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nSET @g = geometry::STGeomFromText(&#039;POLYGON((0 0, 0 2, 1 1, 2 2, 2 0, 0 0))&#039;, 0);\r\nSELECT @g, &#039;Original&#039; AS &#x5B;Display], &#039;Blue&#039; as &#x5B;Color], 0.2 as &#x5B;Thickness]\r\nUNION ALL\r\nSELECT @g.STConvexHull(), &#039;Hull&#039;, &#039;Green&#039; as &#x5B;Color], 0.1 as &#x5B;Thickness];\r\n<\/pre>\n<p><a target='_blank'  href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stconvexhull1.png' title='stconvexhull1.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stconvexhull1.png' alt='stconvexhull1.png' \/><\/a><\/p>\n<p>A k\u00e9k az eredeti, az z\u00f6ld a kiegyengetett, konvexes\u00edtett.<\/p>\n<p>Metszi-e egym\u00e1st k\u00e9t alakzat? <strong>STCrosses<\/strong>.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nDECLARE @h geometry;\r\nSET @g = geometry::STGeomFromText(&#039;LINESTRING(0 2, 2 0)&#039;, 0);\r\nSET @h = geometry::STGeomFromText(&#039;LINESTRING(0 0, 2 2)&#039;, 0);\r\nSELECT @g, @h, @g.STCrosses(@h), 0.1 as &#x5B;Thickness];\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n1\r\n<\/pre>\n<p>K\u00fcl\u00f6nbs\u00e9gk\u00e9pz\u00e9s, azok hat\u00e1rol\u00f3pontok \u00e1ltal beker\u00edtett ter\u00fclet az egyik alakzatb\u00f3l, amelyek nincsenek benne egy m\u00e1sikban: <strong>STDifference<\/strong>.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nDECLARE @g geometry;\r\nDECLARE @h geometry;\r\nSET @g = geometry::STGeomFromText(&#039;POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))&#039;, 0);\r\nSET @h = geometry::STGeomFromText(&#039;POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))&#039;, 0);\r\nSELECT &#039;Original Polygons&#039; as &#x5B;Display], @g, @h, &#039;Green&#039; as &#x5B;Color],  0.2 as &#x5B;Thickness]\r\nUNION ALL\r\nSELECT &#039;First minus second&#039;, null, @g.STDifference(@h), &#039;Blue&#039; as &#x5B;Color], 0.1 as &#x5B;Thickness]\r\nUNION ALL\r\nSELECT &#039;Second minus first&#039;, null, @h.STDifference(@g), &#039;Orange&#039; as &#x5B;Color], 0.05 as &#x5B;Thickness];\r\n<\/pre>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nOriginal Polygons  POLYGON ((0 0, 0 2, 2 2, 2 0, 0 0))      POLYGON ((1 1, 3 1, 3 3, 1 3, 1 1))      Green  0.20\r\nFirst minus second NULL                                     POLYGON ((0 0, 2 0, 2 1, 1 1, 1 2, 0 2,  Blue   0.10\r\nSecond minus first NULL                                     POLYGON ((2 1, 3 1, 3 3, 1 3, 1 2, 2 2,  Orange 0.05\r\n\r\n<\/pre>\n<p><a target='_blank'  href='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stdifference.png' title='stdifference.png'><img src='http:\/\/soci.hu\/blog\/wp-content\/uploads\/2008\/01\/stdifference.png' alt='stdifference.png' \/><\/a><\/p>\n<p>J\u00f3pofa. Az als\u00f3 z\u00f6ld n\u00e9gyzet az egyik alakzatunk, a fels\u0151 z\u00f6ld a m\u00e1sik. A k\u00e9k azt mutatja, ha az als\u00f3b\u00f3l kivonjuk a fels\u0151t, a s\u00e1rga, ha a fels\u0151b\u0151l az als\u00f3t.<\/p>\n<p>Folyt. k\u00f6v.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Az el\u0151z\u0151 r\u00e9sz v\u00e9g\u00e9n volt egy k\u00e9p, ami vizualiz\u00e1lta a geometriai alakzatokat. Ez a kis program a GeoQuery 2008, \u00e9s rendk\u00edv\u00fcl j\u00f3&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,4,58],"tags":[],"class_list":["post-401","post","type-post","status-publish","format-standard","hentry","category-adatbazisok","category-szakmai-elet","category-sql-server-2008"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=401"}],"version-history":[{"count":0,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}