SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Training
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Working with Windows Communication Foundation (WCF)
Transfer Logins Task and Transfer Database Task in SSIS
Practical Database Change Management (Part 2)
Practical Database Change Management (Part 1)

More     
 
Latest FAQ's

ALTER TABLE SWITCH statement failed because column '%.*ls' has data type ...
ALTER TABLE SWITCH statement failed because column '%.*ls' has data type ...
ALTER TABLE SWITCH statement failed. There is no identical index in ...
'%ls' statement failed because the expression identifying partition number for the ...

More     
   
Latest Software Reviews

Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008
ApexSQL Enforce

More     

articles >> developer >> New Data Types in SQL Server 2008 ...

New Data Types in SQL Server 2008 Part 3

By : Dinesh Asanka
Feb 01, 2008

Introduction
This is the third article of the new data types in SQL Server 2008 series. We have already discussed the new date time data types in the first article and HierarchyID in second article. In this article, we are going to discuss spatial data types.

Spatial data represents information about the physical location and shape of geometric objects. These objects can be point locations or more complex objects such as countries, roads, or lakes.

SQL Server supports two spatial data types: the Geometry data type and the Geography data type. Both data types are implemented as .NET Common Language Runtime (CLR) data types in SQL Server.

Geometry Data
The Geometry data type (planar) supported by SQL Server conforms to the Open Geospatial Consortium (OGC) Simple Features for SQL Specification version 1.1.0.

First of all lets look at the available shapes in SQL Server 2008 for geometry. The following image illustrates the shapes that are available.

 

 

Source : Books On line, SQL Server 2008

Point
In SQL Server spatial data, a Point is a 0-dimensional object representing a single location and may contain Z (elevation) and M (measure) values.

The following example defines a point with coordinates of (2, 5):

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POINT (2 5)', 0);

In the point, only X and Y coordinates are defined. The STGeomFromText function converts geometry tagged coordinates to the Geometry data type.  The second parameter which is 0 in the above example is the Spatial Reference Identifier (SRID). Details of SRID will be discussed later in this article.

The following example will define a point with coordinates of (2, 5, 9) and with a measure of 8.  You may notice that we have used new function named Parse. Parse is same as STGeomFromText but in the Parse function SRID is 0.

DECLARE @g geometry;
SET @g = geometry::Parse('POINT(2 5 9 8)');

In a Point geometry you have four functions. They are STX, STY, Z and M which will return X, Y, Z coordinates and measure.

DECLARE @g geometry;
SET @g = geometry::Parse('POINT(2 5 9 8)');
SELECT @g.STX; -- Return 2
SELECT @g.STY; -- Return 5
SELECT @g.Z; -- Return 9
SELECT @g.M; -- Return 8

LineString
A LineString is a one-dimensional object representing a sequence of points and the line segments connecting them. A LineString instance must be formed with at least two distinct points, and can also be empty.

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('LINESTRING(1 1, 4 5, 10 13,19 25)', 0);

The example above will create a shape which has joined points (1, 1), (4, 5), (10, 13) and (19, 25). Even though I have specified only X and Y coordinates, you have the option of providing Z and M parameters as well.

There are several valuable methods which you can use with the LineString shape.

Method

Usage

Syntax

Result for Above Sample

STLength()

Total length

Select @g.STLength()

30

STStartPoint()

Start point of the LineString

Select @g.STStartPoint().ToString();

POINT (1, 1)

STEndPoint()

End point of the LineString

Select @g.STEndPoint().ToString();

POINT( 19, 25)

STPointN()

Point of the given number of the LineString object.

Select @g.STPointN(2).ToString();

POINT (4, 5)

STNumPoints()

Number of points

Select @g.STNumPoints();

4

STIsSimple()

If shape does not intersect itself then it is 1

Select @g.STIsSimple();

1

STIsClosed()

If shape is closed then it is 1

Select @g.STIsClosed();

0

STIsRing()

If it simple and closed

Select @g.STIsRing();

0

Select @g.STLength()
Select @g.STStartPoint().ToString();
Select @g.STEndPoint().ToString();
Select @g.STPointN(2).ToString();
Select @g.STNumPoints();
Select @g.STIsSimple();
Select @g.STIsClosed()
Select @g.STIsRing();
  

In my testing I have found that there are some errors when the LineString shape is closed. These issues should be fixed in a coming release.

 


    Next Page>>    








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved