Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 User-defined Types

Author  Topic 

desi_nerd
Starting Member

2 Posts

Posted - 2005-09-08 : 11:00:18
Iam trying to create a geo-database.
For that i need to have a spatial data type called polygon which takes in values as int. so it can be declared as:
POLYGON(0 0, 100 0, 100 100, 0 100, 0 0)

How do i do that.
plz help.

---
Iam not real any more
Iam just an Illusion
---

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-08 : 11:49:34
I'm not one for ever using user defined data types, plus I don't think you can have one like that.

Look up sp_addtype in Books Online.



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

ryanston
Microsoft SQL Server Product Team

89 Posts

Posted - 2005-09-08 : 13:22:06
Not really doable in SQL 2000 without an add-on from a 3rd party company. In SQL Server 2005 you can create a user-defined type in a CLR language like C# and use it in the database.

Thanks,

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-08 : 13:24:45
OMG

There must be some slack time out in redmond...or is that redrum?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-09-08 : 14:25:41
>>...or is that redrum?

As a wacky workaround, until you upgrade to 2005, you could use a binary value (4 bytes per int, or 2 bytes for smallint, etc). Then use a function to convert your Polygon to the binary value and a view to get the parts back out.

ie here is a three part version (binary(12) - 4 byte ints as each part):

set nocount on
go
--function to convert multiple integers to a binary value
--each integer is assigned to a pre-designated position in
--the binary value
create function dbo.fnSetPolygon(@p1 int, @p2 int, @p3 int)
returns binary(12)
as
begin
declare @polygon binary(12)

select @polygon = convert(binary(12),
convert(varchar,convert(binary(4), @p1))
+ convert(varchar,convert(binary(4), @p2))
+ convert(varchar,convert(binary(4), @p3)))
return @polygon
end

go
create table Polygons_t
(polygonid int identity(1,1) primary key
,Polygon binary(12))
go

--a view extracts the individual parts of the binary value
create view dbo.Polygons_v
as
select Polygonid
,convert(int,substring(polygon,1,4)) p1
,convert(int,substring(polygon,5,4)) p2
,convert(int,substring(polygon,9,4)) p3
from Polygons_t
go


insert Polygons_t (polygon)
select dbo.fnSetPolygon(100,100,100) union all
select dbo.fnSetPolygon(200,200,200)

select * from Polygons_t
select * from Polygons_v

if object_id('dbo.fnSetPolygon') > 0
drop function dbo.fnSetPolygon
go
if object_id('dbo.Polygons_v') > 0
drop view dbo.Polygons_v
go
if object_id('dbo.Polygons_t') > 0
drop table Polygons_t
go


Be One with the Optimizer
TG
Go to Top of Page

ryanston
Microsoft SQL Server Product Team

89 Posts

Posted - 2005-09-08 : 15:26:55
quote:
Originally posted by X002548

OMG

There must be some slack time out in redmond...or is that redrum?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx




Slack time? What's that?

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-08 : 16:03:35
I assume you know Paul Randall as well?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-09-08 : 16:12:13
I had assumed Ryan was Paul's mild mannered alter ego.

Be One with the Optimizer
TG
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-09-08 : 16:26:25
Store each coordinate in one row.
Let the client format the information into the datatype representation it wants.

The database only stores the information, preferably in a normalized manner.
Since SQL Server 2K does not support "complex" datatypes you can break the data down into it's constituents.

/* Store these polygons */
POLYGON(0 0, 100 0, 100 100, 0 100, 0 0)
POLYGON(25 25,33 33,55 55)

/* In a table like this */
POLYGONS
(
PNBR INT
,XCOORD INT
,YCOORD INT
,PRIMARY KEY(PNBR,XCOORD,YCOORD)
)

/* Like this */
PNBR XCOORD YCOORD
1 0 0
1 100 0
1 100 100
1 0 100
2 25 25
2 33 33
2 55 55
Go to Top of Page

ryanston
Microsoft SQL Server Product Team

89 Posts

Posted - 2005-09-08 : 18:23:18
quote:
Originally posted by TG

I had assumed Ryan was Paul's mild mannered alter ego.

Be One with the Optimizer
TG



Yeah, Paul is my manager. Now that he's a big-time dev lead, he doesn't have a lot of time for DBCC, so I took it over from him. I'm not sure mild-mannered is exacly an apropo description, but I guess in comparison to Paul...

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

desi_nerd
Starting Member

2 Posts

Posted - 2005-09-09 : 13:50:07
Thanks for the help.
I have decided to use MySQL instead which has the inbuilt data types that i need.


---
Iam not real any more
Iam just an Illusion
---
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-09 : 13:56:44
now that's a solution....

Go with the flow & have fun! Else fight the flow
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-09 : 15:05:58
quote:
Originally posted by desi_nerd

Thanks for the help.
I have decided to use MySQL instead which has the inbuilt data types that i need.


---
Iam not real any more
Iam just an Illusion
---





Did they ever implement GROUP BY yet?

Good Luck

And remember, you get what you pay for.



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-09 : 15:09:11
quote:
Originally posted by ryanston

quote:
Originally posted by TG

I had assumed Ryan was Paul's mild mannered alter ego.

Be One with the Optimizer
TG



Yeah, Paul is my manager. Now that he's a big-time dev lead, he doesn't have a lot of time for DBCC, so I took it over from him. I'm not sure mild-mannered is exacly an apropo description, but I guess in comparison to Paul...

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)




My Dad lives just South of Daytona....And when I drive by their community college, I always wanted to stop and get a tee shirt

http://www.dbcc.cc.fl.us/01_about.htm



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-09-09 : 15:16:02


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-09-09 : 17:58:07
quote:
Originally posted by ryanston

quote:
Originally posted by TG

I had assumed Ryan was Paul's mild mannered alter ego.

Be One with the Optimizer
TG



Yeah, Paul is my manager. Now that he's a big-time dev lead, he doesn't have a lot of time for DBCC, so I took it over from him. I'm not sure mild-mannered is exacly an apropo description, but I guess in comparison to Paul...

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)




You're lucky we've just done your annual review

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-09-09 : 18:00:28
quote:
Originally posted by X002548



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx




Seen that before. I toyed with the idea of getting DBCC as a personalized plate 5 years ago but that would have made me seem uncharacteristically ego-centric so I stuck with the one I had.

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-09-09 : 19:10:55
quote:
uncharacteristically ego-centric so I stuck with the one I had.
MSSQLGOD?
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-09-09 : 19:22:10
quote:
Originally posted by robvolk

quote:
uncharacteristically ego-centric so I stuck with the one I had.
MSSQLGOD?




No, it was my old nickname 'chewie', as in Chewbacca.

Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-09 : 19:46:43
meaning you're 6 feet 5 inches with hair all over your body??

Go with the flow & have fun! Else fight the flow
Go to Top of Page

ryanston
Microsoft SQL Server Product Team

89 Posts

Posted - 2005-09-09 : 19:56:37
quote:
Originally posted by spirit1

meaning you're 6 feet 5 inches with hair all over your body??

Go with the flow & have fun! Else fight the flow



Please, let's stop this conversation before I get any more horrible images of Paul in my mind...

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page
    Next Page

- Advertisement -