Solved

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

Posted on 2014-12-04
6
109 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
Comment Utility
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
Comment Utility
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
Comment Utility
What do you mean standard? That IS standard.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now