sqlgeography

SQL Server geography latitude longitude error

百般思念 提交于 2019-12-11 15:44:04
问题 I'm using geography data type for calculating shortest distance. CREATE TABLE Landmark ( Id int, Latitude FLOAT, Longitude FLOAT ) INSERT Landmark VALUES (1, 49.242458, -123.153465), (2, 49.249381, -122.866683) WITH GeographyLandmark AS ( SELECT Id, geography::STPointFromText('POINT(' + CAST(Latitude AS VARCHAR(20)) + ' ' + CAST(Longitude AS VARCHAR(20)) + ')', 4326) Location FROM Landmark ) --this query calculates distance between point and localizations in meters SELECT Id, geography:

Datatable with SqlGeography column can't be serialized to xml correctly with loss of Lat,Long and other elements

霸气de小男生 提交于 2019-12-11 05:08:17
问题 I tried to serialize a DataTable object to xml. The DataTable has a column with type 'geography', which contains instances of type SqlGeography. The following code is used to serialize the datatable to xml: var writer = new StringWriter(); dt.WriteXmlSchema(writer); //get schema //serialize to xml dt.WriteXml(writer); Console.WriteLine(writer.ToString()); The generated xml string is not complete with the loss of all Geo elements Lat,Long,... It contains only STSrid element. The following is

finding sql geography point within rectangular (polygon)

为君一笑 提交于 2019-12-11 00:01:26
问题 I have an interesting/annoying issue with finding lat and long of land marks inside the rectangular boundary. I believe my two points are inside my rectangular boundary. but as you can test yourself the result of the the first select is false instead of true! DECLARE @boundingRect varchar(1000) DECLARE @maxLat VARCHAR(20) DECLARE @minLong VARCHAR(20) DECLARE @minLat VARCHAR(20) DECLARE @maxLong VARCHAR(20) set @maxLat ='-36.06631759541187' set @minLong ='125.23310677812492' set @minLat ='-44

Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query and without using SET FORCEPLAN

大兔子大兔子 提交于 2019-12-10 12:47:45
问题 I am running following: DECLARE @g geography; declare @point nvarchar(50) ='' declare @i int =0, @lat decimal(8,6) =0.0, @long decimal(8,6) =0.0, @start datetime = getdate() set @lat =(select (0.9 -Rand()*1.8)*100) set @long =(select (0.9 -Rand()*1.8)*100) set @point = (select 'POINT('+CONVERT(varchar(10), @lat)+ ' ' +CONVERT(varchar(10), @long)+')') SET @g = geography::STGeomFromText(@point, 4326); SELECT TOP 1000 @lat, @long, @g.STDistance(st.[coord]) AS [DistanceFromPoint (in meters)] , st

Update Geography column in table

随声附和 提交于 2019-12-10 11:28:58
问题 I have the following table As you can the Geo column (data type Geography) is null I currently have 11913 rows in this table what I'm trying to do is update the Geo column by using the following statement and populate the Geo column with the data that is provided by Geography::STGeomFromText DECLARE @Temp TABLE ( Id bigint, Latitude decimal(9,6), Longitude decimal(9,6) ) Insert Into @Temp (Id, Latitude, Longitude) Select id, Latitude, Longitude from Location.Cities where Active = 1 Update

Change projection in MSSQL for web mapping (Leaflet,Openlayer, OpenStreetMaps, GoogleAPI, …) to WSG48 or any other format

感情迁移 提交于 2019-12-10 08:12:34
问题 I have some WKT/WKB data in the MSSQL server like this and would like to show them on the map with the help of leaflet, Openlayer, OpenStreetMaps, or GoogleAPI. My data look likes this: POLYGON ((1736946.0983 5923253.9175, 1736895.6852 5923333.9451, 1736936.0082 5923356.6991, ......)) in this format EPSG:2193 as shown below and would like to convert them to WGS48 or EPSG:4326 I am trying to add them to leaflet, and seems that I need to convert this data to an appropriate format like this: [

SQL Geometry VS decimal(8,6) Lat, Long Performance

蓝咒 提交于 2019-12-07 07:11:33
问题 I was looking into performance of selecting closest points within certain proximity to given coordinate. Options are to ether use two decimal(8,6) - lat, long columns or single geography column and work with that. I am only interested which is faster? 回答1: TL;DR Geography is ~10 times faster. Ok so I have set up test: Couple of tables one with id,lat,long (int, decimal(8,6),decimal(8,6)) other with id,coord (int, geography) . Then insert 47k of random data. For indexing first table I used

Mapping SqlGeography with Dapper

眉间皱痕 提交于 2019-12-06 21:25:57
问题 I have entity "Point", that contains Id, Text and geography coordinates. CREATE TABLE [Point] ( [Id] INT IDENTITY CONSTRAINT [PK_Point_Id] PRIMARY KEY, [Coords] GEOGRAPHY NOT NULL, [Text] NVARCHAR(32) NOT NULL, [CreationDate] DATETIME NOT NULL, [IsDeleted] BIT NOT NULL DEFAULT(0) ) CREATE PROCEDURE [InsertPoint] @text NVARCHAR(MAX), @coords GEOGRAPHY AS BEGIN INSERT INTO [Point](Text, Coords, CreationDate) VALUES(@text, @coords, GETUTCDATE()) SELECT * FROM [Point] WHERE [Id] = SCOPE_IDENTITY(

SqlGeography.STIntersection() returns even when I know there is no intersection

戏子无情 提交于 2019-12-06 13:06:00
A little about the application; The application allows the user to draw and save polygons onto bing maps WPF api. The piece of code we are interested in is finding weather a point is whithin the polygon or not. The following function simply loops through the LocationCollection of the polygon on the bing map, and creates a SqlGeography object (OpenGisGeographyType.Polygon) which is an instance of a polygon. We then convert the mouse click into SqlGeography object (OpenGisGeographyType.Point) by latitude and longitude and use the SqlGeography.STIntersection to find if our point lies within the

SQL Geometry VS decimal(8,6) Lat, Long Performance

笑着哭i 提交于 2019-12-05 15:36:25
I was looking into performance of selecting closest points within certain proximity to given coordinate. Options are to ether use two decimal(8,6) - lat, long columns or single geography column and work with that. I am only interested which is faster? Matas Vaitkevicius TL;DR Geography is ~10 times faster. Ok so I have set up test: Couple of tables one with id,lat,long (int, decimal(8,6),decimal(8,6)) other with id,coord (int, geography) . Then insert 47k of random data. For indexing first table I used nonclustered Ascending index on lat,long with fill factor of 95. for second one GRIDS =