SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Server Spatial Data - Working with Circles


SQL Server Spatial Data - Working with Circles

Author
Message
chris.king
chris.king
Say Hey Kid
Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)

Group: General Forum Members
Points: 679 Visits: 325
Hi there,

I am not very familiar with working with spatial data and I am currently trying to work out how to obtain some properties of a circle defined as a geometry data type.

Specifically, I need to determine x and y co-ordinates for the centre point and the diameter of the circle.

I have had a look at the MSDN reference for spatial data and done some general googling but I must admit I am struggling to find anything relevant.

Any advice or guidance would be greatly appreciated.

TIA,

Chris
Eirikur Eiriksson
Eirikur Eiriksson
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38412 Visits: 19424
Simplest method is to use STBuffer, the parameter passed is effectively the radius.
Cool

DECLARE @CIRCLE GEOMETRY = geometry:Tongueoint(1.00,1.00,0).STBuffer(1);
SELECT @CIRCLE


chris.king
chris.king
Say Hey Kid
Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)

Group: General Forum Members
Points: 679 Visits: 325
Hi,

Thanks for your reply.

If I understand correctly, I would need the centre point in order to use STBuffer().

I don't currently understand how to find the centre point from the existing shape stored as a CIRCULARSTRING. Here is some example data I am working with:

CIRCULARSTRING (52.6107417597068 -1.19053984363516, 52.6107417597068 -1.19185949047026, 52.6114844449159 -1.19185949047026, 52.6114844449159 -1.19053984363516, 52.6107417597068 -1.19053984363516)

CIRCULARSTRING (0 4, 4 0, 8 4, 4 8, 0 4)

Based on this, is there an easy way to find the centre point?

TIA,

Chris
Eirikur Eiriksson
Eirikur Eiriksson
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38412 Visits: 19424
This should get you started, find where lines drawn between every other point defining the circle crosses
Cool

USE tempdb;
GO

DECLARE @CIRCLE GEOMETRY = 'CIRCULARSTRING (52.6107417597068 -1.19053984363516, 52.6107417597068 -1.19185949047026, 52.6114844449159 -1.19185949047026, 52.6114844449159 -1.19053984363516, 52.6107417597068 -1.19053984363516)'

;WITH T(N) AS (SELECT X.N FROM (VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL)) AS X(N))
,NUMS(N) AS (SELECT TOP(@CIRCLE.STNumPoints() - 1 ) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS N FROM T T1,T,T T2,T T3,T T4)
,C_POINTS AS
(
SELECT
NM.N AS POINT_NO
,@CIRCLE.STPointN(N) /*.STBuffer(0.0001)*/ AS POINT_GEO
FROM NUMS NM
)

SELECT
C1.POINT_GEO.ShortestLineTo(C3.POINT_GEO).STIntersection(C2.POINT_GEO.ShortestLineTo(C4.POINT_GEO)).STBuffer(0.0001)
FROM C_POINTS C1
CROSS APPLY C_POINTS C2
CROSS APPLY C_POINTS C3
CROSS APPLY C_POINTS C4
WHERE C1.POINT_NO = 1
AND C2.POINT_NO = 2
AND C3.POINT_NO = 3
AND C4.POINT_NO = 4
UNION ALL
SELECT @CIRCLE








chris.king
chris.king
Say Hey Kid
Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)Say Hey Kid (679 reputation)

Group: General Forum Members
Points: 679 Visits: 325
Hi Thanks,

I'll have play around with the code supplied.

Thanks for the help ;-)

Chris
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search