private void SetPINValue() { //The Theory. //Select polygons that intersect the sketch. //Construct one polyline from the boundaries and intersect with sketch. //Sort resulting intersection locations (multipoint) by distance of the intersect // from the start of the sketch and create new ordered multipoint. //Loop through new ordered multipoint, select underlying parcel and calc pin. IFeatureLayer featLayer = m_editLayers.CurrentLayer; m_curve = m_edSketch.Geometry as IPolyline; //Search parcel polys by graphic to get feature cursor ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = m_curve; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; IFeatureCursor featCursor = featLayer.Search(spatialFilter,true); IFeature feature = featCursor.NextFeature(); //If we have no intersects then exit if (feature == null) return; //Make a GeomBag of the polygons boundaries (polylines) IGeometryCollection geomBag = new GeometryBagClass(); object missing = Type.Missing; while (feature != null) { ITopologicalOperator poly = feature.Shape as ITopologicalOperator; geomBag.AddGeometry(poly.Boundary,ref missing,ref missing); feature = featCursor.NextFeature(); } //Make one polyline from the boundaries IPolyline polyLineU = new PolylineClass(); ITopologicalOperator topoOp = polyLineU as ITopologicalOperator; topoOp.ConstructUnion(geomBag as IEnumGeometry); //Get the intersections of the boundaries and the curve IPointCollection pointCol = topoOp.Intersect(m_curve, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; //The point collection is not ordered by distance along the curve so //need to create a new collection with this info int[] pointOrder = new int[pointCol.PointCount]; double dac = 0, dfc = 0; bool bRS = false; for (int i = 0; i < pointCol.PointCount; i++) { IPoint queryPoint = new PointClass(); pointCol.QueryPoint(i, queryPoint); m_curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, queryPoint, false, null,ref dac,ref dfc,ref bRS); pointOrder[i] = (int)dac; } //use built in bubble sort System.Array.Sort(pointOrder); //Loop through the sorted array and calc midpoint between parcel boundaries IPointCollection midPoints = new MultipointClass(); for (int i = 0; i < pointOrder.Length -1; i++) { //Get the midpoint distance double midPointDist = (pointOrder[i] + pointOrder[i + 1]) / 2; //create a point at the distance and store in point collection IPoint queryPoint = new PointClass(); m_curve.QueryPoint(esriSegmentExtension.esriNoExtension, midPointDist, false, queryPoint); midPoints.AddPoint(queryPoint,ref missing,ref missing); } //If ends of sketch are included then add them as points if (chkEnds.Checked) { object before = 0 as object; midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing); midPoints.AddPoint(m_curve.ToPoint, ref missing, ref missing); } m_editor.StartOperation(); //Loop through calculated midpoints, select polygon and calc pin for (int i = 0; i < midPoints.PointCount; i++) { IPoint midPoint = midPoints.get_Point(i); spatialFilter = new SpatialFilter(); spatialFilter.Geometry = midPoint; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; featCursor = featLayer.Search(spatialFilter, false); while ((feature = featCursor.NextFeature()) != null) { feature.set_Value(feature.Fields.FindField(cmbPINField.Text), m_lotNum); feature.Store(); m_lotNum += int.Parse(txtlotinc.Text); } } m_editor.StopOperation("ViperPIN"); txtlot.Text = m_lotNum.ToString(); }
/// <summary> /// 计算面积 /// </summary> /// <param name="CurPoint"></param> /// <returns></returns> private double CaculateArea(IPoint CurPoint) { IPointCollection tempCollection = new MultipointClass(); object missing = Type.Missing; for (int i = 0; i < m_ptCollection.PointCount; i++) { IPoint dPoint = m_ptCollection.get_Point(i); tempCollection.AddPoint(dPoint, ref missing, ref missing); } tempCollection.AddPoint(CurPoint, ref missing, ref missing); tempCollection.AddPoint(tempCollection.get_Point(0), ref missing, ref missing); int Count = tempCollection.PointCount; double x1, x2, y1, y2; double tempArea = 0.0; for (int i = 0; i < Count - 1; i++) { x1 = Convert.ToDouble(tempCollection.get_Point(i).X); y1 = Convert.ToDouble(tempCollection.get_Point(i).Y); x2 = Convert.ToDouble(tempCollection.get_Point(i + 1).X); y2 = Convert.ToDouble(tempCollection.get_Point(i + 1).Y); tempArea += (x1 * y2 - x2 * y1); } tempArea = Math.Abs(tempArea) / 2; return(tempArea); }
private void updatePointToolStripMenuItem_Click(object sender, EventArgs e) { IMultipoint multipoint; object missing = Type.Missing; IPoint point1 = new PointClass(); point1.PutCoords(10, 10); IPoint point2 = new PointClass(); point2.PutCoords(20, 20); IPointCollection pointCollection = new MultipointClass(); pointCollection.AddPoint(point1, ref missing, ref missing); pointCollection.AddPoint(point2, ref missing, ref missing); point1 = new PointClass(); point1.PutCoords(40, 10); pointCollection.UpdatePoint(1, point1); multipoint = pointCollection as IMultipoint; addFeature("multipoint", multipoint as IGeometry); System.Windows.Forms.MessageBox.Show("X = " + pointCollection.get_Point(1).X + ", Y = " + pointCollection.get_Point(1).Y); this.axMapControl1.Extent = multipoint.Envelope; this.axMapControl1.Refresh(); }
private void btnDeleteLink_Click(object sender, EventArgs e) { DataGridViewSelectedRowCollection rowCollection = this.dataGridViewX1.SelectedRows; int nCount = rowCollection.Count; int nOriCount = m_OriginPoints.PointCount; IPointCollection tmpPointCollectionOri = new MultipointClass(); IPointCollection tmpPointCollectionDst = new MultipointClass(); for (int i = 0; i < nOriCount; i++) { bool bFlag = false; for (int j = 0; j < nCount; j++) { if (i == rowCollection[j].Index) { bFlag = true; break; } } if (bFlag == false) { tmpPointCollectionOri.AddPoint(m_OriginPoints.get_Point(i)); tmpPointCollectionDst.AddPoint(m_TargetPoints.get_Point(i)); } } m_OriginPoints.RemovePoints(0, m_OriginPoints.PointCount); m_TargetPoints.RemovePoints(0, m_TargetPoints.PointCount); for (int i = 0; i < tmpPointCollectionDst.PointCount; i++) { m_OriginPoints.AddPoint(tmpPointCollectionOri.get_Point(i)); m_TargetPoints.AddPoint(tmpPointCollectionDst.get_Point(i)); } RefreshDataTable(); //m_pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //m_pMapCtr.RefreshLayer(); //if (refreshLayer != null) //{ // refreshLayer(); //} }
//几何图形坐标转换 private void GeometryCoordConvert(ref IGeometry pConvertGeometry, double A1, double B1, double C1, double A2, double B2, double C2, double A3, double C3) { object a = System.Reflection.Missing.Value; object b = System.Reflection.Missing.Value; bool isRing = false; if (pConvertGeometry.GeometryType != esriGeometryType.esriGeometryPoint)//如果为线要素或面要素 { IArray pArrayPoint = new ArrayClass(); IArray pGeometryArray = new ArrayClass(); IGeometryCollection pGeometryCollection = pConvertGeometry as IGeometryCollection; for (int i = 0; i < pGeometryCollection.GeometryCount; i++) { IGeometry pGeometry = pGeometryCollection.get_Geometry(i); if (pGeometry.GeometryType != esriGeometryType.esriGeometryPoint)// { #region if (pGeometry.GeometryType == esriGeometryType.esriGeometryRing) { isRing = true; } if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon) { pGeometry = CommonFunction.GetPolygonBoundary((IPolygon)pGeometry); } ISegmentCollection pSegmentCol = (ISegmentCollection)pGeometry; ISegmentCollection pNewSegmentCol = new PolylineClass(); for (int k = 0; k < pSegmentCol.SegmentCount; k++)//遍历几何形体的每个节(片断) { //该节为直线段 if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryLine) { IPointCollection pPointCol1 = new MultipointClass(); ILine pLine = (ILine)pSegmentCol.get_Segment(k); IPoint pFromPoint = pLine.FromPoint; pPointCol1.AddPoint((IPoint)pFromPoint, ref a, ref b); IPoint pToPoint = pLine.ToPoint; pPointCol1.AddPoint((IPoint)pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol1);//对点集做镜像 //修改线段的端点坐标 pLine.FromPoint = pPointCol1.get_Point(0); pLine.ToPoint = pPointCol1.get_Point(1); pNewSegmentCol.AddSegment((ISegment)pLine, ref a, ref b); } //该节为圆弧 else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryCircularArc) { IPointCollection pPointCol2 = new MultipointClass(); ICircularArc pCircularArc = (ICircularArc)pSegmentCol.get_Segment(k); try { IPoint pCenterPoint = pCircularArc.CenterPoint; pPointCol2.AddPoint((IPoint)pCenterPoint, ref a, ref b); IPoint pFromPoint = pCircularArc.FromPoint; pPointCol2.AddPoint((IPoint)pFromPoint, ref a, ref b); IPoint pToPoint = pCircularArc.ToPoint; pPointCol2.AddPoint((IPoint)pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol2);//对点集做镜像 //构造新的圆弧 ICircularArc pArc = new CircularArcClass(); pArc.PutCoords(pPointCol2.get_Point(0), pPointCol2.get_Point(1), pPointCol2.get_Point(2), (pCircularArc.IsCounterClockwise ? esriArcOrientation.esriArcCounterClockwise : esriArcOrientation.esriArcClockwise)); pNewSegmentCol.AddSegment((ISegment)pArc, ref a, ref b); } catch { } } //该节为贝塞尔曲线 else if (pSegmentCol.get_Segment(k).GeometryType == esriGeometryType.esriGeometryBezier3Curve) { IPointCollection pPointCol3 = new MultipointClass(); IBezierCurve pBezierCurve = (IBezierCurve)pSegmentCol.get_Segment(k); //记录该节贝塞尔曲线的4个控制点 IPoint pFromPoint = new PointClass(); pBezierCurve.QueryCoord(0, pFromPoint); pPointCol3.AddPoint(pFromPoint, ref a, ref b); IPoint pFromTangentPoint = new PointClass(); pBezierCurve.QueryCoord(1, pFromTangentPoint); pPointCol3.AddPoint(pFromTangentPoint, ref a, ref b); IPoint pToTangentPoint = new PointClass(); pBezierCurve.QueryCoord(2, pToTangentPoint); pPointCol3.AddPoint(pToTangentPoint, ref a, ref b); IPoint pToPoint = new PointClass(); pBezierCurve.QueryCoord(3, pToPoint); pPointCol3.AddPoint(pToPoint, ref a, ref b); PointCollCoordConvert(A1, B1, C1, A2, B2, C2, A3, C3, ref pPointCol3);//对点集做镜像 //修改该节贝塞尔曲线的4个控制点 pBezierCurve.PutCoord(0, pPointCol3.get_Point(0)); pBezierCurve.PutCoord(1, pPointCol3.get_Point(1)); pBezierCurve.PutCoord(2, pPointCol3.get_Point(2)); pBezierCurve.PutCoord(3, pPointCol3.get_Point(3)); pNewSegmentCol.AddSegment((ISegment)pBezierCurve, ref a, ref b); } }//end for 遍历几何形体的每个节(片断) CommonFunction.GeometryToArray(pNewSegmentCol as IGeometry, pArrayPoint); IPolycurve2 pPolycurve2 = CommonFunction.BuildPolyLineFromSegmentCollection(pNewSegmentCol); pGeometry = (IGeometry)pPolycurve2; #endregion } if (pConvertGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//由线构成面 { pGeometry = CommonFunction.PolylineToPolygon(pGeometry as IPolyline); } pGeometryArray.Add(pGeometry); } if (pGeometryArray.Count > 1) { pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry; if (isRing == true) { for (int i = 1; i < pGeometryArray.Count; i++) { pConvertGeometry = CommonFunction.DiffenceGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry); } } else { for (int i = 1; i < pGeometryArray.Count; i++) { pConvertGeometry = CommonFunction.UnionGeometry(pConvertGeometry, pGeometryArray.get_Element(i) as IGeometry); } } } else { pConvertGeometry = pGeometryArray.get_Element(0) as IGeometry; } CommonFunction.AddZMValueForGeometry(ref pConvertGeometry, pArrayPoint); } else { PointCoordConvert(ref pConvertGeometry, A1, B1, C1, A2, B2, C2, A3, C3); } }
/// <summary> /// ������� /// </summary> /// <params name="CurPoint"></params> /// <returns></returns> private double CaculateArea(IPoint CurPoint) { IPointCollection tempCollection = new MultipointClass(); object missing = Type.Missing; for (int i = 0; i < m_ptCollection.PointCount; i++) { IPoint dPoint = m_ptCollection.get_Point(i); tempCollection.AddPoint(dPoint, ref missing, ref missing); } tempCollection.AddPoint(CurPoint, ref missing, ref missing); tempCollection.AddPoint(tempCollection.get_Point(0), ref missing, ref missing); int Count = tempCollection.PointCount; double x1, x2, y1, y2; double tempArea = 0.0; for (int i = 0; i < Count - 1; i++) { x1 = Convert.ToDouble(tempCollection.get_Point(i).X); y1 = Convert.ToDouble(tempCollection.get_Point(i).Y); x2 = Convert.ToDouble(tempCollection.get_Point(i + 1).X); y2 = Convert.ToDouble(tempCollection.get_Point(i + 1).Y); tempArea += (x1 * y2 - x2 * y1); } tempArea = Math.Abs(tempArea) / 2; return tempArea; }
private void SetPINValue() { //The Theory. //Select polygons that intersect the sketch. //Construct one polyline from the boundaries and intersect with sketch. //Sort resulting intersection locations (multipoint) by distance of the intersect // from the start of the sketch and create new ordered multipoint. //Loop through new ordered multipoint, select underlying parcel and calc pin. IFeatureLayer featLayer = m_editLayers.CurrentLayer; m_curve = m_edSketch.Geometry as IPolyline; //Search parcel polys by graphic to get feature cursor ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = m_curve; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; IFeatureCursor featCursor = featLayer.Search(spatialFilter, true); IFeature feature = featCursor.NextFeature(); //If we have no intersects then exit if (feature == null) { return; } //Make a GeomBag of the polygons boundaries (polylines) IGeometryCollection geomBag = new GeometryBagClass(); object missing = Type.Missing; while (feature != null) { ITopologicalOperator poly = feature.Shape as ITopologicalOperator; geomBag.AddGeometry(poly.Boundary, ref missing, ref missing); feature = featCursor.NextFeature(); } //Make one polyline from the boundaries IPolyline polyLineU = new PolylineClass(); ITopologicalOperator topoOp = polyLineU as ITopologicalOperator; topoOp.ConstructUnion(geomBag as IEnumGeometry); //Get the intersections of the boundaries and the curve IPointCollection pointCol = topoOp.Intersect(m_curve, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; //The point collection is not ordered by distance along the curve so //need to create a new collection with this info int[] pointOrder = new int[pointCol.PointCount]; double dac = 0, dfc = 0; bool bRS = false; for (int i = 0; i < pointCol.PointCount; i++) { IPoint queryPoint = new PointClass(); pointCol.QueryPoint(i, queryPoint); m_curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, queryPoint, false, null, ref dac, ref dfc, ref bRS); pointOrder[i] = (int)dac; } //use built in bubble sort System.Array.Sort(pointOrder); //Loop through the sorted array and calc midpoint between parcel boundaries IPointCollection midPoints = new MultipointClass(); for (int i = 0; i < pointOrder.Length - 1; i++) { //Get the midpoint distance double midPointDist = (pointOrder[i] + pointOrder[i + 1]) / 2; //create a point at the distance and store in point collection IPoint queryPoint = new PointClass(); m_curve.QueryPoint(esriSegmentExtension.esriNoExtension, midPointDist, false, queryPoint); midPoints.AddPoint(queryPoint, ref missing, ref missing); } //If ends of sketch are included then add them as points if (chkEnds.Checked) { object before = 0 as object; midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing); midPoints.AddPoint(m_curve.ToPoint, ref missing, ref missing); } m_editor.StartOperation(); //Loop through calculated midpoints, select polygon and calc pin for (int i = 0; i < midPoints.PointCount; i++) { IPoint midPoint = midPoints.get_Point(i); spatialFilter = new SpatialFilter(); spatialFilter.Geometry = midPoint; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; featCursor = featLayer.Search(spatialFilter, false); while ((feature = featCursor.NextFeature()) != null) { feature.set_Value(feature.Fields.FindField(cmbPINField.Text), m_lotNum); feature.Store(); m_lotNum += int.Parse(txtlotinc.Text); } } m_editor.StopOperation("ViperPIN"); txtlot.Text = m_lotNum.ToString(); }
/// <summary> /// 内插值法求点的“地面高” /// </summary> /// <param name="pPnt"></param> /// <returns>点的高程值</returns> private double Calculate_Z2(IPoint pPnt) { double pZ = 0; //================================================ double dRad = double.Parse("15".Trim()) / 2.0; //搜索半径一半 double dBufferRad = 0.0; ITopologicalOperator pTopo = pPnt as ITopologicalOperator; IGeometry pBuffer = pTopo.Buffer(dRad); IPointCollection pPC = new MultipointClass(); pPC.AddPointCollection(PointCollectionFromEdit(pPnt, dRad)); pPC.AddPointCollection(pntColl(pBuffer)); //================================================ int pTag = 1; //如果点数小于2,则增大搜索半径,重新搜索 while (pPC.PointCount < 2) { if (pTag > 4)//若重新搜索4次还没有点,则退出 { break; } pTag++; dBufferRad = dRad * pTag; pBuffer = pTopo.Buffer(dBufferRad); pPC.RemovePoints(0, pPC.PointCount); pPC.AddPointCollection(PointCollectionFromEdit(pPnt, dBufferRad)); pPC.AddPointCollection(pntColl(pBuffer)); } //================================================ if (pPC.PointCount > 1) { double pTolZ = 0; double pLength = 0; double iP = 0; double pToliP = 0;//权系数 for (int i = 0; i < pPC.PointCount; i++) { IPoint pPt = pPC.get_Point(i); if (pPt.Z >= 0 || pPt.Z < 0) { pLength = Get_Len_2piont(pPnt, pPt); if (pLength > 0) { iP = 1 / Math.Pow(pLength, 2); pToliP = pToliP + iP; pTolZ = pTolZ + iP * pPt.Z; } }//if (pPt.Z != double.NaN) } if (pToliP != 0) { pZ = pTolZ / pToliP; } //pToliP = 0使用初始化值0作为pZ结果 else //大于两个点均与查询点重合 { pZ = 0; } } else//点数小于两个 { //if (frmSetValue.UseConst) //{ // pZ = frmSetValue.ConstHight; //} //else //{ // frmSetValue pFrmSetValue = new frmSetValue(pPnt.X, pPnt.Y); // if (pFrmSetValue.ShowDialog() == DialogResult.OK) // { // pZ = pFrmSetValue.ReturnValue; // bolEdit = true; // } //} } //================================================ return(pZ); }
public static IPoint Snapping(IActiveView activeView, esriGeometryHitPartType geometryHitPartType, IPoint queryPoint, double searchRaius) { IPoint vetexPoint = null; IPoint hitPoint = new PointClass(); IHitTest hitTest = null; IPointCollection pointCollection = new MultipointClass(); IProximityOperator proximityOperator = null; double hitDistance = 0; int hitPartIndex = 0, hitSegmentIndex = 0; Boolean rightSide = false; IFeatureCache2 featureCache = new FeatureCacheClass(); featureCache.Initialize(queryPoint, searchRaius); //初始化缓存 for (int i = 0; i < activeView.FocusMap.LayerCount; i++) { //只有点、线、面并且可视的图层才加入缓存 IFeatureLayer featLayer = (IFeatureLayer)activeView.FocusMap.get_Layer(i); if (featLayer != null && featLayer.Visible == true && (featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline || featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon || featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)) { featureCache.AddFeatures(featLayer.FeatureClass, null); for (int j = 0; j < featureCache.Count; j++) { IFeature feature = featureCache.get_Feature(j); hitTest = (IHitTest)feature.Shape; //捕捉节点,另外可以设置esriGeometryHitPartType,捕捉边线点,中间点等。 if (hitTest.HitTest(queryPoint, searchRaius, geometryHitPartType, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide)) { object obj = Type.Missing; pointCollection.AddPoint(hitPoint, ref obj, ref obj); break; } } } } proximityOperator = (IProximityOperator)queryPoint; double minDistance = 0, distance = 0; for (int i = 0; i < pointCollection.PointCount; i++) { IPoint tmpPoint = pointCollection.get_Point(i); distance = proximityOperator.ReturnDistance(tmpPoint); if (i == 0) { minDistance = distance; vetexPoint = tmpPoint; } else { if (distance < minDistance) { minDistance = distance; vetexPoint = tmpPoint; } } } return vetexPoint; }
static private void GetRealPt(IFeatureLayer conFyr, IFeature pFeature, bool isPeakOrBottom, int fid, int sMark)//true表示山包线,false表示山洼线 { Dictionary <IPoint, IFeature> feaAndCenPt = RaterPtToVectorPt(pFeature); for (int i = 0; i < feaAndCenPt.Count; i++) { IPoint newPeakOrBotPt = feaAndCenPt.Keys.ElementAt(i); IPointCollection ptC = feaAndCenPt.Values.ElementAt(i).Shape as IPointCollection; double Z = Math.Round(ptC.get_Point(0).Z, 0); IPolyline mainLine = GetMainDirection(pFeature); IPolyline sectionPly = GetaSectionPly(mainLine, newPeakOrBotPt); IPoint leftPtOfMouPt = new PointClass(); IPoint rightPtOfMouPt = new PointClass(); ITopologicalOperator sTopo = sectionPly as ITopologicalOperator; IGeometry pGeo = sTopo.Intersect(pFeature.Shape, esriGeometryDimension.esriGeometry0Dimension); IPointCollection ptCol = new MultipointClass(); if (pGeo.IsEmpty == false) { ptCol = pGeo as IPointCollection; IPoint pt1 = ptCol.get_Point(0); IPoint pt2 = ptCol.get_Point(1); if (pt1.X > pt2.X) { rightPtOfMouPt = pt1; leftPtOfMouPt = pt2; } else { rightPtOfMouPt = pt2; leftPtOfMouPt = pt1; } } IPoint leftPtOfAdjPt = new PointClass(); IPoint rightPtOfAdjPt = new PointClass(); IFeature adjacentF = GetAdjacentFea(closedline, Z, newPeakOrBotPt, isPeakOrBottom); if (adjacentF == null) { adjacentF = GetAdjacentFea(openline, Z, newPeakOrBotPt, isPeakOrBottom); } pGeo = sTopo.Intersect(adjacentF.Shape, esriGeometryDimension.esriGeometry0Dimension); if (pGeo.IsEmpty == false) { ptCol = pGeo as IPointCollection; if (ptCol.PointCount == 2) { IPoint pt1 = ptCol.get_Point(0); IPoint pt2 = ptCol.get_Point(1); if (pt1.X > pt2.X) { rightPtOfAdjPt = pt1; leftPtOfAdjPt = pt2; } else { rightPtOfAdjPt = pt2; leftPtOfAdjPt = pt1; } } else if (ptCol.PointCount > 2) { Dictionary <IPoint, double> dic = new Dictionary <IPoint, double>(); for (int i_1 = 0; i_1 < ptCol.PointCount; i_1++) { IPoint pt = ptCol.get_Point(i_1); double dis = Math.Pow(newPeakOrBotPt.X - pt.X, 2) + Math.Pow(newPeakOrBotPt.Y - pt.Y, 2); dic.Add(pt, dis); } var disCd = from objDic in dic orderby objDic.Value ascending select objDic; List <IPoint> ptList = new List <IPoint>(); foreach (KeyValuePair <IPoint, double> key in disCd) { ptList.Add(key.Key); if (ptList.Count == 2) { break; } } IPoint pt1 = ptList[0]; IPoint pt2 = ptList[1]; if (pt1.X > pt2.X) { rightPtOfAdjPt = pt1; leftPtOfAdjPt = pt2; } else { rightPtOfAdjPt = pt2; leftPtOfAdjPt = pt1; } } else if (ptCol.PointCount == 1) { IPoint pt1 = ptCol.get_Point(0); IPoint pt2 = new PointClass(); Dictionary <IPolyline, int> boundD = GetBounds.GetNewBoundAndPtsDataFun(conFyr); for (int j = 0; j < boundD.Count; j++) { IPolyline ply = boundD.Keys.ElementAt(j); IGeometry pg = sTopo.Intersect(ply, esriGeometryDimension.esriGeometry0Dimension); if (pg.IsEmpty == false) { IPointCollection otherPtc = pg as IPointCollection; pt2 = otherPtc.get_Point(0); break; } } if (pt1.X > pt2.X) { rightPtOfAdjPt = pt1; leftPtOfAdjPt = pt2; } else { rightPtOfAdjPt = pt2; leftPtOfAdjPt = pt1; } } } ILine newLine = new LineClass(); newLine.FromPoint = sectionPly.FromPoint; newLine.ToPoint = sectionPly.ToPoint; IPoint newPt1 = new PointClass(); IPoint newPt2 = new PointClass(); newPt1 = RotateCoordinate(leftPtOfMouPt, newLine.Angle); newPt2 = RotateCoordinate(rightPtOfMouPt, newLine.Angle); double angle1 = 0; double angle2 = 0; double rightDis = Math.Sqrt(Math.Pow(rightPtOfMouPt.X - rightPtOfAdjPt.X, 2) + Math.Pow(rightPtOfMouPt.Y - Math.Abs(rightPtOfAdjPt.Y), 2)); //右边 double leftDis = Math.Sqrt(Math.Pow(leftPtOfAdjPt.X - leftPtOfMouPt.X, 2) + Math.Pow(leftPtOfAdjPt.Y - Math.Abs(leftPtOfMouPt.Y), 2)); //左边 if (isPeakOrBottom == true) { if (leftDis < rightDis) { angle1 = Math.Atan(intervalValue / leftDis); angle2 = 2 * Math.PI - Math.Atan(intervalValue / rightDis); } else if (leftDis > rightDis) { angle1 = Math.PI - Math.Atan(intervalValue / rightDis); angle2 = Math.PI + Math.Atan(intervalValue / leftDis); } } else { if (leftDis < rightDis) { angle1 = 2 * Math.PI - Math.Atan(intervalValue / leftDis); angle2 = Math.Atan(intervalValue / rightDis); } else if (leftDis > rightDis) { angle1 = Math.PI + Math.Atan(intervalValue / rightDis); angle2 = Math.PI - Math.Atan(intervalValue / leftDis); } } Dictionary <double, double> ptXZDic = new Dictionary <double, double>(); GetCalculatedPoints.dTightness = 2.5; for (int j = 0; j < 1; j++) { ptXZDic = GetCalculatedPoints.CreateNewPoint(newPt1.X, Z, newPt2.X, Z, angle1, angle2, 20); ptXZDic = SortedByZValue(ptXZDic, isPeakOrBottom); double diffZ = ptXZDic.Values.ElementAt(0); IPoint ppts = RotateCoordinate(newPeakOrBotPt, newLine.Angle); if ((diffZ < Z + intervalValue && diffZ > Z) || (diffZ > Z - intervalValue && diffZ < Z)) { IPoint pt = new PointClass(); if (ptXZDic.Keys.ElementAt(0) > ppts.X) { pt.X = ppts.X + Math.Abs(ptXZDic.Keys.ElementAt(0) - ppts.X); } else { pt.X = ppts.X - Math.Abs(ptXZDic.Keys.ElementAt(0) - ppts.X); } pt.Y = ((pt.X - newPt2.X) * (newPt1.Y - newPt2.Y) / (newPt1.X - newPt2.X)) + newPt2.Y; IPoint nPt = RotateCoordinate(pt, -newLine.Angle); nPt.Z = ptXZDic.Values.ElementAt(0); mounTPtList.Add(nPt, feaAndCenPt.Values.ElementAt(i)); break; } else { GetCalculatedPoints.dTightness -= 0.1; j = -1; } } } }
private void zoom2selBtn_Click(object sender, EventArgs e) { if (mouseCmd == null || csvDataGrid.SelectedRows.Count == 0) { return; } int maxCount = 30; int i = 0; try { clearGraphics(); IPointCollection points = new MultipointClass(); foreach (DataGridViewRow row in csvDataGrid.SelectedRows) { if (row.Cells["validAdres"].Value == null || row.Cells["validAdres"].Value.ToString() == "") { continue; } if (i > maxCount) { break; } i++; string adres = row.Cells["validAdres"].Value.ToString(); string[] xy = adres.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); double x; double y; string adresType = "Manueel"; if (xy.Count() == 2) { bool xBool = Double.TryParse(xy[0], out x); bool yBool = Double.TryParse(xy[1], out y); if (!xBool || !yBool) { List <datacontract.locationResult> locs = loc.getAdresLocation(adres, 1); if (locs.Count == 0) { continue; } x = locs[0].Location.X_Lambert72; y = locs[0].Location.Y_Lambert72; adresType = locs[0].LocationType; } } else { List <datacontract.locationResult> locs = loc.getAdresLocation(adres, 1); if (locs.Count == 0) { continue; } x = locs[0].Location.X_Lambert72; y = locs[0].Location.Y_Lambert72; adresType = locs[0].LocationType; } IPoint pt = new PointClass() { X = x, Y = y, SpatialReference = lam72 }; IPoint prjPt = geopuntHelper.Transform(pt, map.SpatialReference) as IPoint; points.AddPoint(prjPt); IRgbColor rgb = new RgbColorClass() { Red = 0, Blue = 255, Green = 255 }; IRgbColor black = new RgbColorClass() { Red = 0, Green = 0, Blue = 0 }; IElement grp = geopuntHelper.AddGraphicToMap(map, (IGeometry)prjPt, rgb, black, 5, true); graphics.Add(grp); } if (points.PointCount == 0) { return; } else if (points.PointCount == 1) { IPoint xy = points.get_Point(0); geopuntHelper.ZoomByRatioAndRecenter(view, 1, xy.X, xy.Y); map.MapScale = 1000; view.Refresh(); } else { IEnvelope extent = ((IGeometry)points).Envelope; view.Extent = extent; view.Refresh(); } } catch (WebException wex) { if (wex.Status == WebExceptionStatus.Timeout) { MessageBox.Show("De connectie werd afgebroken." + " Het duurde te lang voor de server een resultaat terug gaf.\n" + "U kunt via de instellingen de 'timout'-tijd optrekken.", wex.Message); } else if (wex.Response != null) { string resp = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd(); MessageBox.Show(resp, wex.Message); } else { MessageBox.Show(wex.Message, "Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message + " : " + ex.StackTrace); } }
private void zoom2selBtn_Click(object sender, EventArgs e) { if (mouseCmd == null || csvDataGrid.SelectedRows.Count == 0) return; int maxCount = 30; int i = 0; try { clearGraphics(); IPointCollection points = new MultipointClass(); foreach (DataGridViewRow row in csvDataGrid.SelectedRows) { if (row.Cells["validAdres"].Value == null || row.Cells["validAdres"].Value.ToString() == "") continue; if( i > maxCount ) break; i++; string adres = row.Cells["validAdres"].Value.ToString(); string[] xy = adres.Split(new string[] {"|"}, StringSplitOptions.RemoveEmptyEntries); double x; double y; string adresType = "Manueel"; if (xy.Count() == 2) { bool xBool = Double.TryParse(xy[0], out x); bool yBool = Double.TryParse(xy[1], out y); if (!xBool || !yBool) { List<datacontract.locationResult> locs = loc.getAdresLocation(adres, 1); if (locs.Count == 0) continue; x = locs[0].Location.X_Lambert72; y = locs[0].Location.Y_Lambert72; adresType = locs[0].LocationType; } } else { List<datacontract.locationResult> locs = loc.getAdresLocation(adres, 1); if (locs.Count == 0) continue; x = locs[0].Location.X_Lambert72; y = locs[0].Location.Y_Lambert72; adresType = locs[0].LocationType; } IPoint pt = new PointClass() { X = x, Y = y, SpatialReference = lam72 }; IPoint prjPt = geopuntHelper.Transform(pt, map.SpatialReference) as IPoint; points.AddPoint(prjPt); IRgbColor rgb = new RgbColorClass() { Red = 0, Blue = 255, Green = 255 }; IRgbColor black = new RgbColorClass() { Red = 0, Green = 0, Blue = 0 }; IElement grp = geopuntHelper.AddGraphicToMap(map, (IGeometry)prjPt, rgb, black, 5, true); graphics.Add(grp); } if (points.PointCount == 0) { return; } else if (points.PointCount == 1) { IPoint xy = points.get_Point(0); geopuntHelper.ZoomByRatioAndRecenter(view, 1, xy.X, xy.Y); map.MapScale = 1000; view.Refresh(); } else { IEnvelope extent = ((IGeometry)points).Envelope; view.Extent = extent; view.Refresh(); } } catch (WebException wex) { if (wex.Status == WebExceptionStatus.Timeout) MessageBox.Show("De connectie werd afgebroken." + " Het duurde te lang voor de server een resultaat terug gaf.\n" + "U kunt via de instellingen de 'timout'-tijd optrekken.", wex.Message); else if (wex.Response != null) { string resp = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd(); MessageBox.Show(resp, wex.Message); } else MessageBox.Show(wex.Message, "Error"); } catch (Exception ex) { MessageBox.Show( ex.Message +" : "+ ex.StackTrace ); } }
private void zoom2selBtn_Click(object sender, EventArgs e) { if (resultGrid.SelectedRows.Count == 0) return; IPointCollection points = new MultipointClass(); try { for (int i = 0; i < resultGrid.SelectedRows.Count; i++) { DataGridViewRow row = resultGrid.SelectedRows[i]; int id = (int)row.Cells[0].Value; List<datacontract.poiLocation> qry = (from n in poiData.pois where n.id == id select n.location).ToList<datacontract.poiLocation>(); if (qry.Count == 0) break; if (qry[0].points == null || qry[0].points.Count == 0) break; datacontract.geojsonPoint jsonPt = qry[0].points[0].Point; IPoint wgsPt = geopuntHelper.geojson2esriPoint(jsonPt, 4326); IPoint prjPt = (IPoint)geopuntHelper.Transform((IGeometry)wgsPt, map.SpatialReference); points.AddPoint(prjPt, Type.Missing, Type.Missing); } if (points.PointCount == 0) { return; } else if (points.PointCount == 1) { IPoint xy = points.get_Point(0); geopuntHelper.ZoomByRatioAndRecenter(view, 1, xy.X, xy.Y); map.MapScale = 1000; } else { IEnvelope extent = ((IGeometry)points).Envelope; view.Extent = extent; } view.Refresh(); } catch (WebException wex) { if (wex.Status == WebExceptionStatus.Timeout) MessageBox.Show("De connectie werd afgebroken." + " Het duurde te lang voor de server een resultaat terug gaf.\n" + "U kunt via de instellingen de 'timout'-tijd optrekken.", wex.Message); else if (wex.Response != null) { string resp = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd(); MessageBox.Show(resp, wex.Message); } else MessageBox.Show(wex.Message, "Error"); } catch (Exception ex) { MessageBox.Show(ex.Message + ": " + ex.StackTrace); } }
static void drawPath(int[] s, int n, int v) { geometry = new IGeometry[VerNum]; pLineSymbol = new ILineSymbol[VerNum]; m_polyline = new ISegmentCollection[VerNum]; int i; //ISegmentCollection m_polyline = null; for (i = 0; i < n; i++) { if (i != v) { if (s[i] == 1) { m_polyline[i] = null; //路径绘制 int pointNum = h[i] + 2; IPoint pt = null; IPointCollection ptCol = new MultipointClass(); for (int pP = 0; pP < pointNum; pP++) { //读取路径上每个点 pt = g.vexs[PathRouteTem[i, pP]].SpatialPoi; if (pt == null) { return; } ptCol.AddPoint(pt); } int tt = ptCol.PointCount; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Blue = 255 - i * 51; pRgbColor.Green = 0 + i * 51; pRgbColor.Red = 0 + i * 51;//不同路径颜色设置 //ISimpleLine3DSymbol pSimpleLine3DSymbol = new SimpleLine3DSymbolClass(); //pSimpleLine3DSymbol.Style = esriSimple3DLineStyle.esriS3DLSTube; //pLineSymbol = pSimpleLine3DSymbol as ILineSymbol; pLineSymbol[i] = new SimpleLineSymbolClass(); pLineSymbol[i].Color = pRgbColor; pLineSymbol[i].Width = 3; //产生线段对象 line //ISegmentCollection m_polyline = null; ILine pLine = new LineClass(); IPoint fromPt = null; //线起点 IPoint toPt = null; //线终点 for (int pP = 0; pP < pointNum - 1; pP++) { fromPt = ptCol.get_Point(pP); toPt = ptCol.get_Point(pP + 1); pLine.PutCoords(fromPt, toPt); object Missing1 = Type.Missing; object Missing2 = Type.Missing; ISegment pSegment = pLine as ISegment; if (m_polyline[i] == null) { m_polyline[i] = new PolylineClass(); } m_polyline[i].AddSegment(pSegment, ref Missing1, ref Missing2); //将线段对象添加到多义线对象polyline } int tttt = m_polyline[i].SegmentCount; geometry[i] = m_polyline[i] as PolylineClass; esriGeometryType aaa = geometry[i].GeometryType; } } } //geometry[0] = (IGeometry)m_polyline; }