Problem reading STGeomCollFromWKB from varbinary (max)

I imported a csv file containing spatial domain information in varchar, and then converted the varchar (max) values ​​to varbinary (max), adding the β€œ0x” values ​​to varchar (max) before the conversion. By then, besides the β€œ0x” at the beginning, the data in the varbinary (max) column looks exactly like varchar (max) converted to text.

Now I run the following script:

select geometry::STGeomCollFromWKB(wkb, 4326) from dbo.MyTable

where WKB is a varbinary (max) column. Executing the above script causes this error: "Significant binary (WKB) input is invalid"

The data source is the Open Street Map, so no doubt they are the correct area data. Therefore, I assume that there should be something wrong with what I am doing, or I am missing a point for converting WKB to a geometry data type.

Can anyone help?

+3
source share
1 answer

I suppose the problem is that when converting varchar data to varbinary, you are converting the actual representation of the characters of the binary data, and not just changing the type to binary.

For example, if you have 0xDEADBEEF data in a varchar column, convert (varbinary (max), 'DEADBEEF') converts the ascii character representations to binary.

, .

SELECT convert (varbinary (max), 'DEADBEEF', 2)

, varkar wkb .

+1

All Articles