Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geography and Geometry. Putting the Genie Back in the Bottle... #764

Open
markddrake opened this issue Dec 10, 2018 · 6 comments
Open

Geography and Geometry. Putting the Genie Back in the Bottle... #764

markddrake opened this issue Dec 10, 2018 · 6 comments

Comments

@markddrake
Copy link

If I select a Georgraphy column, such as SpatialLocation in AdventureWorks.HumanResources.Address I get a nicely formatted JSON representation of the data in the column in SRID 4326 format.

Unfortunately If I attempt to insert that format back to the a geography column using a prepared statement I get a System.FormatException. I am currently forced to define the input as NVarChar(4000) since binding a Geometry doesn't appear to work. (#743).

I suspect that I am going to covert the JSON representation into some other format in order for the database to be able to consume it. Does anyone have any suggestions on a javascript library or SQL operator that can be used to perform the required conversion

@sainsb
Copy link

sainsb commented Dec 14, 2018

Don't know if this will be helpful to you or not but I recently came up against the same challenge of inserting Geog/Geom into the DB -- specifically in the context of bulk loading...
The workflow I came up with is to convert the json (geojson) to WKT, insert it as a string into a temp table, -- once the insert is complete I issue a secondary statement that moves the data from the temp table into the target table and converts the WKT (string) to SQL Server Geom/Geog using this: geometry::STGeomFromText(insertedWKT)

@dhensby
Copy link
Collaborator

dhensby commented Mar 8, 2019

It sounds like there's a lot of work to be done around geometry/geography with this library. It's not something I have the knowledge or time to deal with, tbh. So this is going to remain a problem until someone who wants it has the time/inclination to fix it.

@s4p0
Copy link

s4p0 commented May 10, 2019

Why don't you use a computed column for that?

CREATE TABLE [geoms](
[id] [int] NOT NULL,
[geotext] varchar NULL,
[srid] [int] NULL CONSTRAINT [DF_geoms_srid] DEFAULT ((0)),
[geom] AS ([geometry]::STGeomFromText([geotext],[srid])) PERSISTED,
)

@samlof
Copy link

samlof commented Aug 15, 2022

I have a similar problem. I select from one table, use toTable on it to get sql.Table object and try to bulk load that into another db. The geometry field wants it as varbinary. Checking github it's replaced at

col.value = valueCorrection(col.value, col.metadata)
from binary buffer into the parsed representation, with no way to skip it or get the original buffer.
Would be nice if a way to get the original binary for these insert and bulk purposes

@dhensby
Copy link
Collaborator

dhensby commented Aug 15, 2022

Would be nice if a way to get the original binary for these insert and bulk purposes

You can supply your own value handlers to avoid the built in geometry parsing if you want to keep the raw buffer. you can then parse it on demand if you need to.

@samlof
Copy link

samlof commented Aug 16, 2022

Thanks! Didn't see that.

Then get a bcp issue about wrong type when using the buffer. However I think that's a tedious issue and not mssql. tediousjs/tedious#487

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants