Re: SQL Server 2008 - Spatial Data types
Can anyone give some guidance on using the new data type (geometry and geography). Are they of any practical use with the Recorder 6 database ? If so how might they be used ?
The technical forum of the NBN Trust for use by the Network. It includes discussions and announcements on the NBN Atlas, Recorder 6 and Indicia |
You are not logged in. Please login or register.
Forum → How Do I... & Other Questions → SQL Server 2008 - Spatial Data types
Can anyone give some guidance on using the new data type (geometry and geography). Are they of any practical use with the Recorder 6 database ? If so how might they be used ?
Dave
They certainly could be of use especially if you don't have access to a GIS system. They do of course only apply if you are running under SQL Server 2008 and Recorder 6 doesn't use them but you can add tables through Management studio , and populate these from the grid refs or lat/long. Then you can use these in a whole range of spatial queries without needing any GIS system . This is a big subject and so far I have only got as far as doing some basic things to see how it might work. However, to get you started, below is a UDF which converts a Spatial Reference to the Geometry data type (Easting and Northings). You could use this to populate a new table with say the Sample_Key and the Geometry. This function is taking the Grid Ref as a point, but it could be easily adapted to return a polygon based on the Grid Ref precision. Then you could do all sort of overlap queries. You could just specify boundaries by co-ordinates or it is fairly easy to import ESRI shape files directly into the tables, but you need some third party software to do this (various boundaries are available free, as is the software for importing them). The SQL Server 2008 help for Transact SQL contains a lot of information about the various functions available for spatial queries.
Although I can't actually test it I have seen that that ARC GIS can link directly to the spatial fields. Has any one tried this ?
Mike
USE [NBNData]
GO
/****** Object: UserDefinedFunction [dbo].[LCSpatial_OSGB_Geom] Script Date: 04/30/2011 19:52:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[LCSpatial_OSGB_Geom]
(@Spatial_Ref varchar(30), @SRS varchar(4), @Indicator int )
RETURNS Geometry
--
-- DESCRIPTION
-- Function to return a Geometry as a point from a Spatial Reference (OSBG only)
--
--
-- PARAMETERS
-- NAME DESCRIPTION
--
--
--
-- AUTHOR: Mike Weideli
-- CREATED: 28 April 2011
--
AS
BEGIN
--****************************************************************************************************
DECLARE @ReturnGeometry Geometry
DECLARE @WKTString varchar(100)
DECLARE @EastingStr varchar(20)
DECLARE @NorthingStr varchar(20)
If @SRS = 'OSGB'
BEGIN
Set @NorthingStr = dbo.LCReturnNorthingsV2(@spatial_ref,'OSGB',@Indicator)
Set @EastingStr = dbo.LCReturnEastingsV2(@spatial_ref,'OSGB',@Indicator)
SET @WKTString = 'POINT(' + @EastingStr + ' ' + @NorthingStr + ')'
Set @ReturnGeometry = geometry::STPointFromText(@WKTString,27700)
END
--****************************************************************************************************
RETURN @ReturnGeometry
END
.
Thanks Mike. I will explore further although it looks like of the features should already be available via polgons etc. in Recorder.
Dave
Dave
As I say, I haven't explored all the possibilities fully. What appeals to me is that I have more control over what is happening using SQL Server rather tha the built in maps. It also seems a more robust approach, with everything in the database rather than in external files which can't be accessed. You can also do much more with SQL Server than is possible with the built in system, for example modifying the spatial objects. I can't be sure yet, but you can add spatial indexes to SQL Server which may speed up queries and it might be that SQL Server can handle queries with large polygons, which the existing system struggles with.
I have read that that there is free GIS software available which will link directly to SQL Server 2008 and display the data for you, and these may be better than the built in system,
Mike
Forum → How Do I... & Other Questions → SQL Server 2008 - Spatial Data types
Powered by PunBB 1.4.6, supported by Informer Technologies, Inc.