简体   繁体   English

SQL Server 2008 R2:将数据类型varchar转换为几何

[英]SQL Server 2008 R2: Converting data type varchar to geometry

I am updating table with some values with Geometry Path Condition. 我正在使用“几何路径条件”用一些值更新表。

Here in the following example: I am passing table name as @Table , @ColumnA (for setting new values), @GeoPath (to check in the condition) for the dynamic scipt as shown below: 在这里,在下面的例子:我传递表的名称作为@Table@ColumnA (用于设置新的值), @GeoPath (在状态检查),用于动态素文字,如下所示:

@Table = 'Table1'

@ColumnA = 'A'

@GeoPath = 0xE610000001040500000061574D5E31433140000000003EAF52405E3B0D825B92314000000000AACA52407BEECBC0FB263140000000001

SET @query =    'Update ['+@Table+']
                 SET ColumnA = '''+@ColumnA+'''
                 WHERE CONVERT(Geometry,'+CAST(@GeoPath AS varchar(MAX))+').STIntersects(geometry::Point(Latitude,Longitude, 4326))= 1';
PRINT(@query);

EXECUTE(@query);

But getting the error: 但是得到错误:

Error converting data type varchar to geometry. 将数据类型varchar转换为几何体时出错。

When working with GEOGRAPHY or GEOMETRY you need to specify more information instead of just converting from one type to another. 在使用GEOGRAPHYGEOMETRY您需要指定更多信息,而不仅仅是从一种类型转换为另一种类型。

For example this is conversion of polygon binary data back into geography type. 例如,这是将多边形二进制数据转换回地理类型。

DECLARE @g geography; 
SET @g = geography::STPolyFromWKB(0x01030000000100000005000000F4FDD478E9965EC0DD24068195D3474083C0CAA145965EC0508D976E12D3474083C0CAA145965EC04E62105839D44740F4FDD478E9965EC04E62105839D44740F4FDD478E9965EC0DD24068195D34740, 4326);
SELECT @g

here is same example but this time from text 这是相同的例子,但这一次来自文字

DECLARE @g_text geography; 
SET @g_text = geography::STPolyFromText('POLYGON ((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SELECT @g_text

I'm not sure what type of binary data you have in order to convert it. 我不确定要转换哪种二进制数据类型。 Just make sure that you are using correct conversion method. 只要确保您使用的转换方法正确即可。

Read more on geography::STPolyFromText 了解更多有关geography::STPolyFromText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM