SQL Geography Examples
IN THIS PAGE
Description
A simple portable SQL query using SQL::ResultSet::DataAsGeography, and an interactive session demonstrating DataAsGeography
Simple Portable SQL Query
Assuming that you are connected to the Airports SQL Server database, which has a Location field of type Geography:
SELECT id, Code, Name, City, County, State, GeogLatitude(Location) AS Lat, GeogLongitude(Location) AS Lon( Elevation FROM US_Airports
Use of SQL::ResultSet::DataAsGeography
dim Result as C
dim cn as sql::Connection
dim Geography as A ' Note that we've dimmed this as A to show the true type.
if cn.open(ConnectionString)
Result = Result + "Connection opened successfully." + crlf()
cn.portableSQLEnabled = .t.
if cn.execute("select GeogAsText(g.Location) from GeogTest g")
Result = Result + "Query executed successfully." + crlf()
ResultSet = cn.ResultSet
Geography = ResultSet.DataAsGeography(1, 4326)
Result = Result + "Geography object is of type: " + \
typeof(Geography) + crlf()
Result = Result + "Geography as XML: " + Geography.AsGML().Value + crlf()
Result = Result + "Geography object as Text: " + \
Geography.ToString() + crlf()
Result = Result + "Geography Longitude: " + Geography.Long.Value + crlf()
Result = Result + "Geography Latitude: " + Geography.Lat.Value + crlf(2)
else
Result = Result + "Error executing query: " + CurrentQuery + \
crlf() + "Result is: " + cn.callresult.text + crlf(2)
end if
else
Result = Result + "Error opening connection:: " \
+ ConnectionString + crlf() + "Result is: " + cn.callresult.text + crlf(2)
end if
showvar(Result)An interactive session demonstrating DataAsGeography
Assuming you have run a SQL query that returns location as a Geography object in result set rs:
dim Geography as P
Geography = rs.DataAsGeography("Result is: ", 4326)
?Geography.Long.value
= -84.11936
?Geography.Lat.value
= 33.811217More samples can be found on Common Geography Database Tasks and many of the other pages listed below.
See Also
- Geographic Databases
- Changes to SQL Objects for Geometry
- Portable SQL Functions for Geographies
- Common Geography Database Tasks
- Database-specific Geography Tasks
- DB2-specific Geography Tasks
- MySQL-specific Geography Tasks
- Oracle-specific Geography Tasks
- PostgreSQL-specific Geography Tasks
- SQL Server-specific Geography Tasks
- SQL Geography Examples