sqlgeography

Why is there a difference in SqlGeography STDistance?

本秂侑毒 提交于 2019-12-24 05:56:09
问题 I have been tracking down a bug in my code, and I've found that it's because the Microsoft c# SqlGeography 2014 library returns a slightly different result for STDistance than my regular code for calculating the distance between points. I wrote a small console exe to demonstrate the problem, but I can't figure out why I'm getting such a different result? static void Main(string[] args) { double earthRadius = 6378137; // meters => from both nad83 & wgs84 var a = new { lat = 43.68151632, lng =

Spatial index slowing down query

…衆ロ難τιáo~ 提交于 2019-12-22 05:15:41
问题 Background I have a table that contains POLYGONS/MULTIPOLYGONS which represent customer territories: The table contains roughly 8,000 rows Approximately 90% of the polygons are circles The remainder of the polygons represent one or more states, provinces, or other geographic regions. The raw polygon data for these shapes was imported from US census data. The table has a spatial index and a clustered index on the primary key. No changes to the default SQL Server 2008 R2 settings were made. 16

How to correct Polygon Ring Orientation using C# Entity Framework 5 DbGeography Spatial Data

佐手、 提交于 2019-12-21 04:39:09
问题 I'm working with the new Entity-Framework 5 using the Spatial data type DbGeography as part of my model for storing in one instance, a POINT and in another instance a POLYGON. When setting the value of my POLYGON all saves with no error however this is only the case if I draw the Polygon on the map in a clockwise order. If I draw the POLGON in an anti-clockwise direction I get an error the the sql level indicating that the data is an invalid geography type. Now after doing my own research

Create a SqlGeography polygon-circle from a center and radius

谁都会走 提交于 2019-12-20 20:01:40
问题 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 have tried to following function to create the polygon: private List<Coordinate> getCirclePoints(Coordinate center, int radius, int speed) //speed 1: draws 360 sides, 2 draws 180 etc... { var centerLat = (center.Latitude * Math.PI) / 180.0; //rad

Calculating distances between two tables full of GEOGRAPHY points

蓝咒 提交于 2019-12-13 16:52:20
问题 I'm using SQL Server. I have two tables like this: Table1 : Column1, Column2, Column3, GeoLoc ----------------------------------- a b c 0xE61... Table2 : Column1, Column2, Column3, GeoLoc ----------------------------------- a b c 0xE62... I am looking to get an output table which will compare all of the points in both tables, and show me where table1 has a GeoLoc which is within X distance of GeoLoc in table2 . Does anyone know how to go about this? One table has around 800 rows, and the

Group by value and create geography polyline from points (latitude and longitude) for each group in T-SQL

烂漫一生 提交于 2019-12-12 08:56:30
问题 A similar question has been asked here: Create geography polyline from points in T-SQL Taking that question further, I have a table schema that looks like this: CREATE TABLE [dbo].[LongAndLats]( [Longitude] [float] NULL, [Latitude] [float] NULL, [SortOrder] [bigint] NULL, [SensorID] [bigint] NULL, ) Sample data looks like this: How can I convert these points into a geography polyline for each SensorID using TSQL (so that I would have a SensorID/Polyline record for each SensorID)? I've tried

'The specified input does not represent a valid geography instance' exception when using SqlGeographyBuilder

心已入冬 提交于 2019-12-12 07:20:02
问题 I've written a small application that reads in from a series of KML files and then converts them into the Microsoft.SqlServer.Types.SqlGeography type using the following code: private SqlGeography CreateGeographyFromKML( string kml, bool debug ) { // use SqlGeographyBuilder to help create the SqlGeography type var geographyBuilder = new SqlGeographyBuilder(); // Get co-ordinates var xml = XDocument.Parse(kml); var df = xml.Root.Name.Namespace; XElement coordinates = xml.Descendants(df +

One of the identified items was in an invalid format - Microsoft.SqlServer.Type

我们两清 提交于 2019-12-12 06:36:27
问题 I'm trying to retrieve geography data from my SQl Server 2012 DB with: new SqlDataAdapter("SELECT [SpatialColumn] FROM [SpatialTable]", myConnection).Fill(myDatatable); When the data is a Sql Server 2008 geography type such as Polygon , it's all working fine. But when the type is the new CurvePolygon then that line of code crashes with the error: System.FormatException occurred Message="One of the identified items was in an invalid format." Source="Microsoft.SqlServer.Types" StackTrace: at

Generate view with X and Y from geometry type

让人想犯罪 __ 提交于 2019-12-12 05:04:04
问题 In sql-server-2012 I want to generate view with all points from geometry type. How can I do this? View example GeomKey | X | Y --------+----+----- 1 | X1 | Y1 1 | x2 | Y2 2 | x1 | Y1 Example in Oracle with sys.SDO select c.ngeometrykey, z.* from gis_map.mp_geometry c , table(sdo_util.getvertices(c.geometry)) z 回答1: I don't think you can do this in a view but you can create a table-valued user defined function (a function that returns a table) to get what you want. This example uses a table

SQL Server 2008 geography - spatial result - color based on another column value

廉价感情. 提交于 2019-12-11 17:35:17
问题 I have a table like this in SQL Server 2008: serv_type coords ------------------------ shop 0xE6100000010CE4857478080B49401CD2A8C0C9DE2C40 shop 0xE6100000010C54C6BFCFB80A49408A592F8672DA2C40 restaurant 0xE6100000010C2A00C63368064940B5C189E8D7162D40 shop 0xE6100000010CF9F884ECBC0B49405D6A847EA6FE2C40 restaurant 0xE6100000010CD3BEB9BF7A004940BC202235EDF22C40 restaurant 0xE6100000010CEE76BD3445004940508D976E12F32C40 restaurant 0xE6100000010CFFAECF9CF50B49400ABDFE243EE72C40 ... ... If I SELECT *