The MS SQL Server SqlGeography type represents data in a geodetic (round earth) coordinate system.
Questions tagged [sqlgeography]
264 questions
25
votes
2 answers
EntityType 'DbGeography' has no key defined
Long time listener, first time caller (finally made an account here!)...
I am using Visual Studio 2013 with .NET 4.5.1 and Entity Framework 6 (final releases, not RC or beta).
When trying to add a DbGeography property to my entity, I get this error…

Jeff Guillaume
- 1,661
- 3
- 17
- 29
18
votes
3 answers
How to find intersecting geographies between two tables recursively
I'm running Postgres 9.6.1 and PostGIS 2.3.0 r15146 and have two tables.
geographies may have 150,000,000 rows, paths may have 10,000,000 rows:
CREATE TABLE paths (id uuid NOT NULL, path path NOT NULL, PRIMARY KEY (id))
CREATE TABLE geographies (id…

David Murdoch
- 87,823
- 39
- 148
- 191
16
votes
3 answers
Google Maps and SQL Server LINESTRING length inconsistent
Google Maps and MSSQL seem to disagree on how to calculate the distance/length of a polyline/linestring using SRID 4326.
MSSQL:
SELECT geography::STGeomFromText('LINESTRING(-98.78 39.63,2.98 27.52)', 4326).STLength()
Result: 9030715.95721209
Then…

ParoX
- 5,685
- 23
- 81
- 152
16
votes
1 answer
Convert SQL geography to C#
What is the C# equivalent of this geospatial T-SQL code?
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SET @h =…

Unforgiven
- 1,999
- 5
- 19
- 18
15
votes
2 answers
How do I select Lat & Long coordinates back out of SQL Server Geography data type field
Considering the SQL Server 'geography' data type...
I can enter an array of latitude and longitude (btw is that the correct order to do so or should it be longitude latitude?) points into the field as follows:
INSERT INTO SpatialZonePolygons…

ChrisCurrie
- 1,589
- 6
- 15
- 36
14
votes
2 answers
Enter data in geography column in SQL Server management studio
I've created a new table in SQL Server Management Studio, which includes a Geography column.
Now, I'm trying to enter data in this column using the SSMS UI, but I just can't find the right way of doing it.
So, how can that be done?

ml123
- 1,059
- 2
- 12
- 27
12
votes
1 answer
Microsoft.SqlServer.Types incompatible with .NET Standard
I'm attempting to convert all of our C# class libraries from .NET Framework to .NET Standard projects, as we are starting to leverage .NET Core so need these to be consumable by both .NET Core and .NET Framework apps (with the latter being ported…

Justin
- 17,670
- 38
- 132
- 201
12
votes
1 answer
Why does SQL Server GEOGRAPHY allow longitudes between -15069° and +15069°? Why ±15069°?
I am using the Microsoft.SqlServer.Types DLL in my projects for validating Latitudes and Longitudes.
The Library validates longitude values between -15069 and 15069 degrees instead from -180 to 180.
Can anybody explain what is the significance or…

Rohit Surve
- 121
- 4
12
votes
1 answer
Create a SqlGeography polygon-circle from a center and radius
I would like to save a circle in a sql-server 2008 geography field, using c#.
In c# I have a latitude, a longitude and a radius but I just can't find a way to calculate the polygon that would represent the circle and create a SqlGeography from it.
I…

Johann
- 12,158
- 11
- 62
- 89
11
votes
3 answers
Mapping SqlGeography with Dapper
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]…

lenden
- 800
- 2
- 14
- 38
10
votes
6 answers
Reformat SQLGeography polygons to JSON
I am building a web service that serves geographic boundary data in JSON format.
The geographic data is stored in an SQL Server 2008 R2 database using the geography type in a table. I use [ColumnName].ToString() method to return the polygon data as…

James
- 917
- 3
- 9
- 25
10
votes
3 answers
Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query and without using SET FORCEPLAN
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…

Matas Vaitkevicius
- 58,075
- 31
- 238
- 265
10
votes
2 answers
Is it possible to use SqlGeography with Linq to Sql?
I've been having quite a few problems trying to use Microsoft.SqlServer.Types.SqlGeography. I know full well that support for this in Linq to Sql is not great. I've tried numerous ways, beginning with what would the expected way (Database type of…

cofiem
- 1,384
- 1
- 17
- 29
10
votes
2 answers
What is the right way to insert DBGeography type via ado.net
I am trying to insert DBGeography type via ado.net but no luck.
This is the errors that I am getting:
No mapping exists from object type
System.Data.Entity.Spatial.DbGeography to a known managed provider
native type.
or:
Specified type is not…

1110
- 7,829
- 55
- 176
- 334
9
votes
1 answer
Is there a way to declare a Spatial Index with EntityFrameworkCore 2.2?
I am using Entity Framework Core 2.2 with NetTopologySuite 1.15.1 and SQL Server 2016. Having a column of type IPoint works great to the point I want to create an index on it.
I have this table
public class Location
{
public int Id { get; set;…

Imantas
- 1,621
- 13
- 19