.net 4.5 中是否有类似 dbgeometry makevalid 的东西 [英] is there something like dbgeometry makevalid in .net 4.5

查看:38
本文介绍了.net 4.5 中是否有类似 dbgeometry makevalid 的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这样计算折线的面积

I'm trying to calculate area of polyline like that

    string poly = "POLYGON ((637604.918432772 2230520.64934531,
637622.257266129 2230419.44632915, 637279.107128549 2230192.04910755, 636765.470527745 2230179.6468564, 636778.005055813 2229861.77192838, 636529.81646905 2229464.29327025, 635813.486592791 2229523.30345774, 636017.385069448 2229974.32341381, 636267.323659164 2230070.32127916, 637035.026966561 2230404.70764784, 637275.265066307 2230401.13408429, 637604.918432772 2230520.64934531, 637604.918432772 2230520.64934531))";
     DbGeometry gm = DbGeometry.FromText(poly, 32637);
double area= gm.Area.Value; // here I got the error Exception has been thrown by the target of an invocation.

后来我注意到dbgeometry无效的错误原因我尝试 ms sql 2012 中的代码也给了我错误但是当我这样尝试时

I noticed later that the reson of error that the dbgeometry is invalid I try the code in ms sql 2012 also give me the error but when I tried like that

SELECT @gm.MakeValid().STArea()

这在 sql 中有效我的问题是要使几何在 .net 中有效谢谢

thats worked in sql my question is there is away to make the geometry valid in .net thank you

推荐答案

我同意 Bojan 的观点,除非你使用实体框架?

I'd agree with Bojan, unless you are using the Entity Framework?

SqlGeometry 对象有一个 MakeValid() 函数,因此使用您的示例,允许在 DbGeography 和 SqlGeography 之间进行转换:

The SqlGeometry object has a MakeValid() function, so using your example, allowing for a convert between DbGeography and SqlGeography:

DbGeography geog;
SqlGeometry geom = SqlGeometry.STGeomFromWKB(new SqlBytes(geog.AsBinary()), 32637);

但是,除非您使用 EF,否则我建议您只使用 SqlGeometry 作为

However, unless you are using EF, I'd recommend simply using SqlGeometry as

  1. 没有演员表/转换
  2. SqlGeometry 具有比 DbGeometry 多得多的功能.

希望有所帮助.

这篇关于.net 4.5 中是否有类似 dbgeometry makevalid 的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆