Hi Harris, I've tried to export the table but it doesn't seem possible to export geometry
types to text .. however it wasn't that hard to do anyway.. You need to google the shapefile Manifold produced a few years ago which maps all the contries in the world and their timezones.. Then you need to export that data to SQL Server 2008 using some program.. I used Manifold (remember to use Enterprise Edition or above).. Then I query the data using the following stored procedure:
USE [MyDb]
GO
/****** Object: StoredProcedure [dbo].[GetTimeZone] Script Date: 11/18/2009 21:23:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetTimeZone]
@Latitude float,
@Longitude float
AS
/* SET NOCOUNT ON */
DECLARE @g geometry
/* Validation */
IF @Latitude > 90 OR @Latitude < -90 OR @Longitude > 180 OR @Longitude < -180
RAISERROR('Latitude or longitude out of range', 16, 1)
IF @Latitude IS NULL OR @Longitude IS NULL
RAISERROR('Latitude or longitude cannot be null', 16, 1)
SET @g = geometry::Point(@Longitude, @Latitude, 4326);
IF EXISTS(SELECT * From TimeZones WHERE Shape.STContains(@g) = 1)
/* Point exists on map, get the info */
SELECT Name, LocalSumme, Offset, AreaI FROM TimeZones WHERE Shape.STContains(@g) = 1
ELSE
/* Point is an international water */
IF(@Longitude >= 0)
SELECT NULL AS Name, NULL AS LocalSumme, FLOOR((@Longitude + 7.5) / 15) AS Offset, NULL AS AreaI
ELSE
SELECT NULL AS Name, NULL AS LocalSumme, -FLOOR((-@Longitude + 7.5) / 15) AS Offset, NULL AS AreaI
There's a problem in the shapefile because national waters isn't mapped. I though of maybe using @g.STBuffer() to address this problem..