Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Inserting polygons into geography column

Author  Topic 

mtcoder
Starting Member

19 Posts

Posted - 2011-09-07 : 11:52:04
I have a basic table,
ticket #, completed, address, polygon

polygon column is of geometry type.
I run a select statement from my ticket_order tables that includes 4 separate coordinates basically a 4 sided polygon. Data looks like
Ticket # completed address tlVert trVert, blVert, brVert
A999 9/5/11 11 main -79,33 -79.1,33 -79,32 -79.1, 32

I am trying to figure out how to do the sql for inserting the 4 coordinate columns into the polygon (geography) column. I have read some and it appears the common thing is to use a sqlparameter, but how would I feed it all the records, need to on request send numerous record for storage into my table.
Thanks

Sachin.Nand

2937 Posts

Posted - 2011-09-08 : 06:14:16
Are you using .Net to insert the values ?

PBUH

Go to Top of Page

mtcoder
Starting Member

19 Posts

Posted - 2011-09-08 : 07:24:39
Need to do it in sql, could do it in Tsql or the .net that is with sql, I don't care which if one is much easier than the other. The general process is customer via asp.net web page has their gps location pulled from their computer / phone, that triggers the database to run a procedure to pull data from a sql 2005 database and load it into sql 2008 datatable with geography column. Then I run a function to determine which polygons intersect. I then return that set of records to the end user, who can select the record and get a map with the polygon on it.
So I am basically needing to bulk insert records from one table that is not geography, and put them into a table with a geography column.
Go to Top of Page

mtcoder
Starting Member

19 Posts

Posted - 2011-09-08 : 09:08:08
ok figured it out.

geography::STGeomFromText('Polygon((' +
CAST(extent_top as varchar(20)) + ' ' + CAST(extent_left as varchar(20)) + ', ' + CAST(extent_top as varchar(20)) + ' ' + CAST(extent_right as varchar(20)) + ', ' + CAST(extent_bottom as varchar(20)) + ' ' + CAST(extent_right as varchar(20)) + ', ' + Cast(extent_bottom as varchar(20)) + ' ' + Cast(extent_left as varchar(20)) +', ' + CAST(extent_top as varchar(20)) + ' ' + CAST(extent_left as varchar(20)) + '))', 4326)
as polgyon

that provides the column data from there its just a matter of just doing a normal insert.
Go to Top of Page
   

- Advertisement -