Insert into Spatial table

  • Hi ,

    Am New using the spatial data type

    I have two columns Latitude and longitude in Table A.

    All i need is create a spatial column(Geometry POINT data type) next to these two columns

    Or

    Can i create a new table with only spatial column Inserted from Table A(Lat,Long)

    Instead of writing 1000s of Insert statements

    Any Ideas how to code

    Thanks

  • looks like this page has some examples of the conversion; i haven't tried this yet:

    http://www.sql-server-helper.com/sql-server-2008/convert-latitude-longitude-to-geography-point.aspx

    I'm going to have to throw some time into studying this a bit;

    create table x(

    myLat decimal(19,6),

    myLong decimal(19,6) )

    insert into x select 12.4567,34.5678

    select [GeoLocation] = geography::Point(myLat, myLong, 4326)

    from x

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell,

    Thanks for ur reply

    Instead of using Insert statements.

    I Need to insert the values from another Table

    Something like

    Declare @sql Varchar(max)

    Set @sql = 'INSERT INTO SpatialDemo (SpatialData)

    VALUES(''POINT('+Latitude+'+' '+'+Longitude+') From Bikes.bike.bike_location'

    -- Print @sql

    Exec(@sql)

    This is wrong but i need to generate proper dynamic statements

    Thanks and regards

  • can you confirm this actually returns something from your side: syntactically, it seems to work on my side:

    --INSERT INTO SpatialDemo (SpatialData)

    --test the select first:, then uncomment the INSERT INTO

    SELECT geography::Point(Latitude, Longitude, 4326) From Bikes.bike.bike_location

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks a lot Lowell

    Its working and Now i have something to play around

    Is there any way we can use Geometry instead of geography

    My work around is Planar and geography is more of vector

    Thanks and regards

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply