如何为地理数据类型列添加值?

时间:2014-07-30 08:31:49

标签: sql sql-server tsql sqlgeography

我正在尝试在t-sql中插入记录,如下所示。我很惊讶地在地理数据类型列中添加了一个值。

这是地理的价值:

data = 0xE6100000010C8FE4F21FD26F49406002B7EEE6A9E13F

请告诉我如何在t-sql声明中为地理价值增加价值。

插入声明

    GO

INSERT INTO [dbo].[GeographicLocation]
           ([RecordGUID]
           ,[Postcode]
           ,[Eastings]
           ,[Northings]
           ,[Longitude]
           ,[Latitude]
           ,[MilesFromWisley]
           ,[MilesFromRosemoor]
           ,[MilesFromHarlowCarr]
           ,[MilesFromHydeHall]
           ,[NearestRHSGardenId]
           ,[Geolocation]
           ,[CreatedBy]
           ,[CreatedOn]
           ,[UpdatedBy]
           ,[UpdatedOn])
     VALUES
           (newId()
           ,'A1 3cc'
           ,'579648'
           ,'111337'
           ,'0.55199'
           ,'0.55199'
           ,'0.55199'
           ,'0.55199'
           ,'0.55199'
           ,'0.55199'
           ,1
           ,<Geolocation, geography,> 
           ,'Admin'
           ,GETDATE()
           ,'Admin'
           ,GETDATE())
GO

    GO

/****** Object:  Table [dbo].[GeographicLocation]    Script Date: 29/07/2014 17:23:19 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[GeographicLocation](
    [Id] [int] IDENTITY(1,1) NOT NULL,  
    [Postcode] [nvarchar](10) NOT NULL,
    [Eastings] [varchar](6) NOT NULL,
    [Northings] [varchar](7) NOT NULL,
    [Longitude] [float] NOT NULL,
    [Latitude] [float] NOT NULL,
    [MilesFromWisley] [float] NOT NULL,
    [MilesFromRosemoor] [float] NOT NULL,
    [MilesFromHarlowCarr] [float] NOT NULL,
    [MilesFromHydeHall] [float] NOT NULL,
    [NearestRHSGardenId] [int] NOT NULL,
    [Geolocation] [geography] NOT NULL,
    [CreatedBy] [varchar](50) NOT NULL,
    [CreatedOn] [datetime] NOT NULL,
    [UpdatedBy] [varchar](50) NOT NULL,
    [UpdatedOn] [datetime] NOT NULL,
 CONSTRAINT [PK_GeographicLocation] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

请参阅下面以csv文件格式插入的数据:

    RecordGUID,Postcode,Eastings,Northings,Longitude,Latitude,MilesFromWisley,MilesFromRosemoor,MilesFromHarlowCarr,MilesFromHydeHall,NearestRHSGarden,Geolocation,CreatedBy,CreatedOn,UpdatedBy,UpdatedOn
3EA36A53-4A3B-423D-9EE8-00000D7D7D10,TN38 9DU,579648,111337,0.55199,50.8736,54.00910156,204.9701573,232.9195992,54.82085336,4,0xE6100000010C8FE4F21FD26F49406002B7EEE6A9E13F,Tun,29/07/2014 16:11,NULL,NULL
C913CE04-CE58-45D3-A50E-000011B6E7D5,OX20 1RF,444949,215133,-1.349094,51.83299,52.07852776,135.3794838,148.9129785,83.33775562,4,0xE6100000010C91F2936A9FEA49405CAD1397E395F5BF,Tun,29/07/2014 16:11,NULL,NULL

1 个答案:

答案 0 :(得分:1)

检查:X放置经度值,Y放纬度值,Z放高度值。

 INSERT INTO [dbo].[GeographicLocation]
               ([RecordGUID]
               ,[Postcode]
               ,[Eastings]
               ,[Northings]
               ,[Longitude]
               ,[Latitude]
               ,[MilesFromWisley]
               ,[MilesFromRosemoor]
               ,[MilesFromHarlowCarr]
               ,[MilesFromHydeHall]
               ,[NearestRHSGardenId]
               ,[Geolocation]
               ,[CreatedBy]
               ,[CreatedOn]
               ,[UpdatedBy]
               ,[UpdatedOn])
         VALUES
               (newId()
               ,'A1 3cc'
               ,'579648'
               ,'111337'
               ,'0.55199'
               ,'0.55199'
               ,'0.55199'
               ,'0.55199'
               ,'0.55199'
               ,'0.55199'
               ,1
               ,STGeomFromWKB(0xE6100000010C8FE4F21FD26F49406002B7EEE6A9E13F, 4326)
               ,'Admin'
               ,GETDATE()
               ,'Admin'
               ,GETDATE())
    GO