Tag: sqlgeography

即使我知道没有交集,SqlGeography.STIntersection()也会返回

关于应用程序; 该应用程序允许用户将多边形绘制并保存到bing贴图WPF api上。 我们感兴趣的代码是找到天气,一个点是否在多边形中。 以下函数只是在bing映射上循环遍历多边形的LocationCollection ,并创建一个SqlGeography object (OpenGisGeographyType.Polygon) ,它是多边形的一个实例。 然后,我们通过纬度和经度将鼠标单击转换为SqlGeography object (OpenGisGeographyType.Point) ,并使用SqlGeography.STIntersection查找我们的点是否位于多边形内。 如图所示,即使该点位于多边形之外,SqlGeography.STIntersection仍然返回一个交点。 (您可以在图片中说明这一点,因为我将标签设置为“在交付区域内”或“客户我们的区域”,具体取决于返回的polygonSearch()函数。 当在多边形内测试位置时,图片中的右侧示例具有预期结果。 图片中的左侧示例包含意外结果 – 这表示一个点在多边形内,当它显然不是! 笔记: 我使用SqlGeography(myShape)将形状放在地图上,所以我知道正在使用适当的顶点构造形状。 我使用SqlGeography(myPoint)将引脚放在地图上,所以我知道引脚正在正确的顶点进行测试。 这只能在大型多边形上失败 下面我给出了在内存中创建多边形的代码,以及将鼠标单击事件转换为纬度,经度。 (我在注释中包含了多边形verticies,这样可以在不需要bing api的情况下查看它,只需用上面的注释替换for循环)虽然,您需要引用Microsoft.SqlServer.Types.dl l创建SqlGeography对象。 它免费提供SQL Express 2008,可以在C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies public bool polygonSearch2(LocationCollection points, double lat, double lon) { SqlGeography myShape = new SqlGeography(); SqlGeographyBuilder shapeBuilder = new SqlGeographyBuilder(); // here […]

使用Dapper映射SqlGeography

我有实体“点”,包含Id,文本和地理坐标。 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() […]

从对象类型System.Data.Spatial.DbGeography到已知的托管提供程序本机类型不存在映射

我正在使用DotNetNuke 7平台构建应用程序,并尝试将地理数据写入数据库。 以下是该项目的一些背景知识。 我在VS 2012中构建,刚刚从2008 R2升级到Server 2012。 DotNetNuke 7为数据层和WebAPI实现了PetaPoco。 我希望我提供的信息足以让我们了解问题。 我的代码在“rep.Insert(location);”行上失败了 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Net; using System.Web; using System.Net.Http; using System.Web.Http; using System.Data.Spatial; using DotNetNuke.Web.Api; using DotNetNuke.Data; namespace DotNetNuke.Modules.GeoLocations { public class LocationController: DnnApiController { [AllowAnonymous] [HttpPost] [ValidateAntiForgeryToken] public HttpResponseMessage addLocation(CP_Location submitted) { submitted.GeoCode = DbGeography.PointFromText(string.Format(“POINT({0} {1})”, submitted.Long, submitted.Lat), […]

EntityType’DbGeography’没有定义键

长时间听众,第一次来电(终于在这里开了帐户!)…… 我正在使用Visual Studio 2013与.NET 4.5.1和entity framework6 (最终版本,而不是RC或beta)。 在尝试向我的实体添加DbGeography属性时,执行时出现此错误: One or more validation errors were detected during model generation: Geocoder.DbGeography: : EntityType ‘DbGeography’ has no key defined. Define the key for this EntityType. DbGeographies: EntityType: EntitySet ‘DbGeographies’ is based on type ‘DbGeography’ that has no keys defined. 我已经确认我没有引用旧版本的Entity Framework( 这里讨论过 )。 我一直在使用这篇文章和这篇MSDN文章中的示例/信息,因为这是我第一次涉及.NET中的空间类型(以及SQL Server,就此而言)。 这是我的实体: public class […]

是否可以使用Linq to Sql的SqlGeography?

我一直在尝试使用Microsoft.SqlServer.Types.SqlGeography遇到很多问题。 我完全知道在Linq to Sql中对此的支持并不是很好。 我尝试了很多方法,从预期的方式开始( geography数据库类型, SqlGeography CLR类型)。 这会产生NotSupportedException ,这是通过博客广泛讨论的。 然后,我将geography列作为varbinary(max) ,因为geography是存储为二进制的UDT。 这似乎工作正常(使用一些二进制读取和写入扩展方法)。 但是,我现在遇到了一个相当模糊的问题,这似乎并没有发生在很多其他人身上。 System.InvalidCastException:无法将类型为“Microsoft.SqlServer.Types.SqlGeography”的对象强制转换为“System.Byte []”。 迭代查询时, ObjectMaterializer会抛出此错误。 它似乎只发生在包含地理列的表隐式包含在查询中时(即使用EntityRef属性进行连接)。 System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() 我的问题:如果我将geography列检索为varbinary(max) ,我可能会发现反向错误:无法将byte[] SqlGeography为SqlGeography 。 我明白了。 我没有。 我对部分LINQ to SQL类有一些隐藏二进制转换的特性……那可能是问题吗? 任何帮助表示赞赏,我知道可能没有足够的信息。 附加function: Visual Studio dbml Designer中具有“服务器数据类型”= geography生成此错误: The specified type ‘geography’ is not a valid provider type. Visual Studio dbml Designer中没有“服务器数据类型”的geography列会生成此错误: Could not format node ‘Value’ […]