Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-12-04
6
126 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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.
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…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

839 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