Solved

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

Posted on 2014-12-04
6
135 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
[X]
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
  • 4
  • 2
6 Comments
 
LVL 27

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 27

Expert Comment

by:Zberteoc
ID: 40494572
What do you mean standard? That IS standard.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 27

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 27

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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…

751 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