/// <summary> /// ↑ /// | 0110 | 0010 | 1010 /// | 6 | 2 | 10 /// | -------|-------|-------- /// | 0100 | 0000 | 1000 /// | 4 | 0 | 8 /// | -------|-------|-------- /// | 0101 | 0001 | 1001 /// | 5 | 1 | 9 /// ---------------------------------→ /// </summary> /// <param name="pt"></param> /// <returns></returns> int PointPosition(TysonGeoPoint pt) { var code1 = "00"; var code2 = "00"; if (pt.X <= Envelope[0]) { code1 = "01"; } else if (pt.X >= Envelope[2]) { code1 = "10"; } if (pt.Y <= Envelope[1]) { code2 = "01"; } else if (pt.Y >= Envelope[3]) { code2 = "10"; } return(Convert.ToInt32(code1 + code2, 2)); }
/// <summary> /// 边界点类型,不检测角点 /// </summary> /// <param name="pt"></param> /// <param name="xieLv"></param> /// <returns></returns> EdgePointType CheckEdgePointType(TysonGeoPoint pt, double xieLv) { if (pt.EdgePointType != EdgePointType.NotCalc) { return(pt.EdgePointType); } EdgePointType type; var pos = PointPosition(pt); //内部 if (pos == 0) { type = EdgePointType.Inner; } //下部 else if (pos == 1) { type = EdgePointType.MinY; } //上部 else if (pos == 2) { type = EdgePointType.MaxY; } //左部 else if (pos == 4) { type = EdgePointType.MinX; } //右部 else if (pos == 8) { type = EdgePointType.MaxX; } else { if (pos == 5) { type = Pos5EdgePointType(pt, xieLv); } else if (pos == 6) { type = Pos6EdgePointType(pt, xieLv); } else if (pos == 9) { type = Pos9EdgePointType(pt, xieLv); } else //if (pos == 10) { type = Pos10EdgePointType(pt, xieLv); } } pt.EdgePointType = type; return(type); }
EdgePointType Pos9EdgePointType(TysonGeoPoint pt, double oLineXieLv) { var xieLv = MathUtil.GetXieLv(pt, _rbPt); if (xieLv > oLineXieLv) { return(EdgePointType.MinY); } else { return(EdgePointType.MaxX); } }
/// <summary> /// 根据起点、重点和中间点构建多个线段 /// </summary> /// <param name="innerPoints"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> List <GraphEdge> InsertPoint(IEnumerable <TysonGeoPoint> innerPoints, TysonGeoPoint start, TysonGeoPoint end) { var lastPt = start; var result = new List <GraphEdge>(); foreach (var innerPoint in innerPoints) { result.Add(new GraphEdge(lastPt, innerPoint)); lastPt = innerPoint; } result.Add(new GraphEdge(lastPt, end)); return(result); }
/// <summary> /// 边界点类型,检测角点 /// </summary> /// <param name="pt"></param> /// <returns></returns> EdgePointType CheckEdgePointTypeWithCorner(TysonGeoPoint pt) { var xPos = PositionX(pt.X); var yPos = PositionY(pt.Y); if (xPos == -1) { if (yPos == -1) { return(EdgePointType.MinXMinY); } else if (yPos == 1) { return(EdgePointType.MinXMaxY); } return(EdgePointType.MinX); } else if (xPos == 1) { if (yPos == -1) { return(EdgePointType.MaxXMinY); } else if (yPos == 1) { return(EdgePointType.MaxXMaxY); } return(EdgePointType.MaxX); } else { if (yPos == -1) { return(EdgePointType.MinY); } else if (yPos == 1) { return(EdgePointType.MaxY); } else { return(EdgePointType.Inner); } } }
public Dictionary <TysonGeoPoint, List <TysonGeoPoint> > Build( List <TysonGeoPoint> points, double[] envelope) { Envelope = envelope; var ge = VoronoiBuilder.BuildLine(points, envelope); //x→,y↑ _lbPt = new TysonGeoPoint(Envelope[0], Envelope[1]); _ltPt = new TysonGeoPoint(Envelope[0], Envelope[3]); _rbPt = new TysonGeoPoint(Envelope[2], Envelope[1]); _rtPt = new TysonGeoPoint(Envelope[2], Envelope[3]); var pointWithLines = new Dictionary <int, List <GraphEdge> >(); var edgeLines = new List <GraphEdge>(); void SafeAddToDict(int pointIndex, GraphEdge edgeLine) { if (pointWithLines.ContainsKey(pointIndex)) { pointWithLines[pointIndex].Add(edgeLine); } else { pointWithLines.Add(pointIndex, new List <GraphEdge>() { edgeLine } ); } } foreach (var graphEdge in ge) { SafeAddToDict(graphEdge.Point1Index, graphEdge); SafeAddToDict(graphEdge.Point2Index, graphEdge); edgeLines.Add(graphEdge); } //处理边界点 EdgePointHandle(points, edgeLines, pointWithLines); //遍历所有的EdgeLine,生成Polygon var pointPolygonDict = new Dictionary <TysonGeoPoint, List <TysonGeoPoint> >(); foreach (var kv in pointWithLines) { var edges = kv.Value; var linearRing = BuildLinearRingWithEdgeLine(edges); //BuildLinearRing(edges); if (linearRing != null) { pointPolygonDict.Add( points[kv.Key], linearRing ); } } return(pointPolygonDict); }