tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 465 forks source link

convert parsed sql.Geometry back to buffer #1498

Closed zedpr0 closed 5 months ago

zedpr0 commented 1 year ago

Hi, Im really at a loss here. Im trying to join two tables and one of the columns is of type geometry so when I get the table I get a result like this:

{ srid: 4326, version: 2, points: [ Point { lat: 1, lng: 1, z: null, m: null }, Point { lat: 1, lng: 3, z: null, m: null }, Point { lat: 1, lng: 3, z: null, m: null }, Point { lat: 1, lng: 1, z: null, m: null } ], figures: [ { attribute: 1, pointOffset: 0 } ], shapes: [ { parentOffset: -1, figureOffset: 0, type: 3 } ], segments: [] }

which I now want to simply pass it back into a new table with the datatype sql.geometry. what do I do? any idea?

Ive tried to serialise it using Buffer.from() and using serialize() but keep getting buffer error. There has to be something im missing.

When viewing the table that is created using node, the data type of the column is varbinary(MAX) and not geometry.

Software versions

zedpr0 commented 1 year ago

how do I create a buffer so that I can pass in x, y and srid to get something that the library and sql server will accept as a valid geometry data type.

dhensby commented 1 year ago

~It looks like it's just a buffer with 32bit LE numbers~ edit: oh, you're actually looking at geography points. Here's the passing logic, so assumedly you can just perform the inverse operation (https://github.com/tediousjs/node-mssql/blob/7248e58ff223b2369cb1570005d54e9196c904bf/lib/udt.js#L207-310).