在SqlGeometry和DbGeometry之间转换

VBA*_*ole 8 c# geospatial sqlgeometry

有没有一种简单的方法在SqlGeometry和DbGeometry之间进行转换?我正在使用一个流行的sql空间助手库,并且那里的所有函数都需要SqlGeometry.但是当我对ESRI ArcSDE要素类使用Entity Framework时,Shape字段将作为DbGeometry返回.我不能使用该DbGeometry类型调用我想要的任何方法(例如LocateAlongGeom).也许有一种方法可以将它序列化为二进制或文本,然后将其作为SqlGeometry读回来?

小智 11

//Convert from SqlGeometry to DbGeometry 
SqlGeometry sqlGeo = ...
DbGeometry dbGeo = DbGeometry.FromBinary(sqlGeo.STAsBinary().Buffer);

//Convert from DBGeometry to SqlGeometry
 SqlGeometry sqlGeo2 = SqlGeometry.STGeomFromWKB(new SqlBytes(dbGeo.AsBinary()), 0);
Run Code Online (Sandbox Code Playgroud)

  • 不应该将`DbGeometry`转换为`SqlGeometry`转换为...`SqlGeometry sqlGeo2 = SqlGeometry.STGeomFromWKB(new SqlBytes(dbGeo.AsBinary()),dbGeo.CoordinateSystemId);`考虑不在SRID中的几何-0? (2认同)