Eri*_*ric 18 sql-server gis spatial geospatial c#-4.0
也许我错过了什么.我有一个"Geography"数据类型的SQL Server列.
我想在我的c#代码中使用DbGeography类型.有什么方法可以从sql的地理位置转换或转换为dbgeography吗?
Jon*_*amy 26
对于迟到的回复感到抱歉 - 但在搜索其他内容时看到了这一点.
只需执行以下操作:
SqlGeography theGeography;
int srid = 4326; // or alternative
DbGeography newGeography = DbGeography.FromText(theGeography.ToString(), srid);
Run Code Online (Sandbox Code Playgroud)
扭转它:
DbGeography theGeography;
SqlGeography newGeography = SqlGeography.Parse(theGeography.AsText()).MakeValid();
Run Code Online (Sandbox Code Playgroud)
希望有所帮助!
Ser*_*lov 10
当性能具有任何重要性时,应使用众所周知的二进制文件而不是众所周知的文本:
var newGeography = DbGeography.FromBinary(theGeography.STAsBinary().Value);
Run Code Online (Sandbox Code Playgroud)
如果这很重要,则使用SRID会出现过载.在我使用1000个相当复杂的多边形的简单测试中,基于二进制的方法比基于文本的方法快4倍:
* Binary-based conversion
Run 1: 1948
Run 2: 1944
Run 3: 1959
Run 4: 1979
Run 5: 1988
Average: 1963.6
* Text-based conversion
Run 1: 8527
Run 2: 8553
Run 3: 8596
Run 4: 8535
Run 5: 8496
Average: 8541.4
Run Code Online (Sandbox Code Playgroud)