/// <summary> /// 由于多边形创建要求环闭合,需要在调用构造函数前进行检查,故不具备用点数组作为集合的构造函数 /// </summary> /// <param name="ring">单独外环</param> public MLPolygon(PolylineD ring) { featureType = FeatureType.POLYGON; mbr[0] = mbr[1] = ring.GetPoint(0).X; mbr[2] = mbr[3] = ring.GetPoint(0).Y; for (int i = 1; i < ring.Count; ++i) { if (ring.GetPoint(i).X < mbr[0]) { mbr[0] = ring.GetPoint(i).X; } if (ring.GetPoint(i).X > mbr[1]) { mbr[1] = ring.GetPoint(i).X; } if (ring.GetPoint(i).Y < mbr[2]) { mbr[2] = ring.GetPoint(i).Y; } if (ring.GetPoint(i).Y > mbr[3]) { mbr[3] = ring.GetPoint(i).Y; } } pointNum = ring.Count; polygon = new PolygonD(new PolylineD[] { ring }); }
public MLPolygon(byte[] feaContent) : base() { using (MemoryStream ms = new MemoryStream(feaContent)) { using (BinaryReader br = new BinaryReader(ms)) { featureType = FeatureType.POLYGON; br.BaseStream.Seek(4, SeekOrigin.Current); mbr[0] = br.ReadDouble(); mbr[2] = br.ReadDouble(); mbr[1] = br.ReadDouble(); mbr[3] = br.ReadDouble(); int partNum = br.ReadInt32(); pointNum = br.ReadInt32(); PolylineD[] rings = new PolylineD[partNum]; //将part数组后面多加一个元素pointNum,方便计算每个part的长度 int[] parts = new int[partNum + 1]; for (int i = 0; i < partNum; ++i) { parts[i] = br.ReadInt32(); } parts[partNum] = pointNum; double x, y; PointD[] segPoints; for (int i = 0; i < partNum; ++i) { segPoints = new PointD[parts[i + 1] - parts[i]]; for (int j = 0; j < parts[i + 1] - parts[i]; ++j) { x = br.ReadDouble(); y = br.ReadDouble(); segPoints[j] = new PointD(x, y); } rings[i] = new PolylineD(segPoints); } polygon = new PolygonD(rings); } } }