需求:
把图元包含的点集合按
点数
x1
y1
x2
y2
...
...
这样保存到byte[]数组中并存储到数据库(oracle的blob或sqlserver的image型)
IFeature ftr ftr=...... IGeometry boundGeometry = ftr.Shape; IPointCollection pointCollection = boundGeometry as IPointCollection; int ptCount = pointCollection.PointCount; byte[] bytePts = new byte[ptCount * 16+4];//blob前4位保存点数,后面保存点坐标 byte[] byteptCount = System.BitConverter.GetBytes(ptCount); int lbc = byteptCount.Length; byteptCount.CopyTo(bytePts, 0); for (int i = 0; i < ptCount; i++) { byte[] bytept = System.BitConverter.GetBytes(pointCollection.get_Point(i).X); bytept.CopyTo(bytePts,4+i*16); bytept = System.BitConverter.GetBytes(pointCollection.get_Point(i).Y); bytept.CopyTo(bytePts, 4 + i * 16+8); }
开始是用string连接多个点坐标,用逗号分隔,然后转成byte数组,但这样的话,
byte数组就凭空大了一倍
在读取的时候还要转换类型,再分解,使用C++做这些操作比较麻烦(客户端是C++写的)
这样存储按位读取,速度效率都不错,记一下
浙公网安备 33010602011771号