Solved

Insert GEOM field converted to latitude and longitude into a table.

Posted on 2014-12-04
6
118 Views
Last Modified: 2014-12-29
I am running the following on a table to insert  a GEOM field:

--insert geometry into XX_XX_INFO table

ALTER TABLE XX_XX_INFO
ADD GEOM GEOMETRY

MERGE INTO XX_XX_INFO
USING XX1.DBO.EL_METER
ON Replace(LTrim(Replace(XX_XX_INFO.LOCATION,'0',' ')),' ','0') = EL_METER.LOCATION
WHEN MATCHED THEN
UPDATE SET GEOM = EL_METER.GEOM;

Which works great.  But now I need to split that GEOM field into Latitudes and Longitudes and update the table instead of putting the GEOM field into it.  I can query the GEOM field to get that info with this:

select
   Geom.Lat as [Latitude],
   Geom.Long as [Longitude]
from XX_XX_INFO

I just do not know how to get it put the lat longs into the table instead of the geometry.

Any help is appreciated.
0
Comment
Question by:PeelSeel2
  • 4
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
Zberteoc earned 500 total points
ID: 40482646
Do this:
select 
   Geom.STX as [Latitude],
   Geom.STY as [Longitude]
from XX_XX_INFO

Open in new window

Here is a list of spatial data functions:

http://msdn.microsoft.com/en-us/library/bb933960.aspx
0
 

Author Comment

by:PeelSeel2
ID: 40494444
Zberteoc,

That worked, but it is out putting as state plane coordinates x and y.  Is their a way to convert to standard lat longs?
0
 
LVL 26

Expert Comment

by:Zberteoc
ID: 40494572
What do you mean standard? That IS standard.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 26

Expert Comment

by:Zberteoc
ID: 40494603
Ig you want degrees, minutes and seconds then use this:
select 
	Geom.STX as [Latitude],
	Geom.STY as [Longitude],

	CASE WHEN Geom.STX < 0 then '-' ELSE '' END +
		CAST(FLOOR(ABS(Geom.STX)) as varchar) + ' ' +
			CAST(CAST(FLOOR(ABS(Geom.STX) * 60) AS INT) % 60 as varchar) + ''' ' +
				CAST(CAST(FLOOR(ABS(Geom.STX) * 3600) AS INT) % 60 AS VARCHAR) + '"' as Lat_Dgr,

	CASE WHEN Geom.STY < 0 then '-' ELSE '' END +
		CAST(FLOOR(ABS(Geom.STY)) as varchar) + ' ' +
			CAST(CAST(FLOOR(ABS(Geom.STY) * 60) AS INT) % 60 as varchar) + ''' ' +
				CAST(CAST(FLOOR(ABS(Geom.STY) * 3600) AS INT) % 60 AS VARCHAR) + '"' as Long_Dgr
from 
	XX_XX_INFO

Open in new window

0
 

Author Comment

by:PeelSeel2
ID: 40494810
I get the following error:

Msg 232, Level 16, State 3, Line 1
Arithmetic overflow error for type int, value = 9237998671.000000.
0
 
LVL 26

Expert Comment

by:Zberteoc
ID: 40496438
I changed INT with BIGINT:
select 
	Geom.STX as [Latitude],
	Geom.STY as [Longitude],

	CASE WHEN Geom.STX < 0 then '-' ELSE '' END +
		CAST(FLOOR(ABS(Geom.STX)) as varchar) + ' ' +
			CAST(CAST(FLOOR(ABS(Geom.STX) * 60) AS BIGINT) % 60 as varchar) + ''' ' +
				CAST(CAST(FLOOR(ABS(Geom.STX) * 3600) AS BIGINT) % 60 AS VARCHAR) + '"' as Lat_Dgr,

	CASE WHEN Geom.STY < 0 then '-' ELSE '' END +
		CAST(FLOOR(ABS(Geom.STY)) as varchar) + ' ' +
			CAST(CAST(FLOOR(ABS(Geom.STY) * 60) AS BIGINT) % 60 as varchar) + ''' ' +
				CAST(CAST(FLOOR(ABS(Geom.STY) * 3600) AS BIGINT) % 60 AS VARCHAR) + '"' as Long_Dgr
from 
	XX_XX_INFO

Open in new window

0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question