private void method_6(IPoint point, IFeature feature, out IPoint ipoint_1, out IPoint ipoint_2, out double double_0) { ipoint_1 = null; ipoint_2 = null; double_0 = 384000000.0; try { object missing = Type.Missing; IPointCollection pointCollection = new Polyline(); pointCollection.AddPoint(point, ref missing, ref missing); for (int i = 0; i < pointCollection.PointCount; i++) { IPoint point2 = pointCollection.get_Point(i); IProximityOperator proximityOperator = (IProximityOperator)feature.Shape; IPoint point3 = proximityOperator.ReturnNearestPoint(point2, 0); double num = Math.Sqrt(Math.Pow(point3.X - point2.X, 2.0) + Math.Pow(point3.Y - point2.Y, 2.0)); if (double_0 > num) { double_0 = num; ipoint_1 = point2; ipoint_2 = point3; } } } catch { MessageBox.Show("所选的实体不能量算"); double_0 = 384000000.0; } }
private static void CalculateNearestDistanceToFeature( IPoint point, IFeature feature, out double distance, out IPoint footPoint) { IGeometry geometry = feature.Shape; IProximityOperator proximity = geometry as IProximityOperator; distance = proximity.ReturnDistance(point); footPoint = proximity.ReturnNearestPoint(point, esriSegmentExtension.esriNoExtension); }
/* * Tuple<int, IFeature, double> * int -- FID of the nearest feature on the target feature class * IFeature -- feature itself * double -- distance from the point */ public static Tuple <int, IFeature, double> FindNearestFeature(IPoint pnt, IFeatureClass targetFeatureClass, double tolerance, ServerLogger logger) { if (null != targetFeatureClass && null != pnt && false == pnt.IsEmpty && tolerance > 0.0) { IFeatureCursor ftrCursor = null; double minDist = double.PositiveInfinity; try { ISpatialFilter sptFilter = new SpatialFilterClass(); sptFilter.GeometryField = targetFeatureClass.ShapeFieldName; sptFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; ITopologicalOperator topoOperator = pnt as ITopologicalOperator; sptFilter.Geometry = topoOperator.Buffer(tolerance); //recycle should be false if you expect a loop against the cursor //otherwise, the feature field inside the cursor will be reused so the reference //you retrieve from the cursor will be changed slicently from your perspective //http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/000100000047000000.htm ftrCursor = targetFeatureClass.Search(sptFilter, false); IFeature ftr = null; IFeature minDistftr = null; IProximityOperator proxOperator = null; while ((ftr = ftrCursor.NextFeature()) != null) { proxOperator = ftr.Shape as IProximityOperator; double curDist = proxOperator.ReturnDistance(pnt); if (curDist < minDist) { minDistftr = ftr; minDist = curDist; } } if (null != minDistftr) { proxOperator = minDistftr.Shape as IProximityOperator; IPoint geom = proxOperator.ReturnNearestPoint(pnt, esriSegmentExtension.esriNoExtension);//ftr.ShapeCopy; return(new Tuple <int, IFeature, double>(minDistftr.OID, minDistftr, minDist)); } return(null); } catch (Exception e) { if (null != logger) { logger.LogMessage(ServerLogger.msgType.error, typeof(AOUtilities).Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, ErrorCode, e.Message); } } finally { ReleaseCOMObj(ftrCursor); } } return(null); }
//查找点到最近线的交点 public static IPoint GetNearestPoint(IPoint pPoint) { try { IFeature pFeatureNearst = GetNearestFeature(pPoint); IProximityOperator pProximityOperator = pFeatureNearst.Shape as IProximityOperator; return(pProximityOperator.ReturnNearestPoint(pPoint, esriSegmentExtension.esriNoExtension)); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "异常"); return(null); } }
/// <summary> /// search the eid nearest from point /// </summary> /// <param name="geometricNetwork">geometric Network</param> /// <param name="searchTolerance">tolerance for search</param> /// <param name="point">point input</param> /// <param name="elementType">type of element</param> /// <returns>return eid</returns> internal static int GetEIDFromPoint(ESRI.ArcGIS.Geodatabase.IGeometricNetwork geometricNetwork, double searchTolerance, IPoint point, esriElementType elementType) { IEnumFeatureClass enumFeatureClassSimple = null; IEnumFeatureClass enumFeatureClassComlex = null; if (elementType == esriElementType.esriETEdge) { enumFeatureClassSimple = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge); enumFeatureClassComlex = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge); } else if (elementType == esriElementType.esriETJunction) { enumFeatureClassSimple = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction); enumFeatureClassComlex = geometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexJunction); } double distance = double.PositiveInfinity; int featureClassID = -1; IGeometry featureGeometry = null; Helper.FindNearestDistance(enumFeatureClassSimple, point, searchTolerance, ref distance, ref featureClassID, ref featureGeometry); Helper.FindNearestDistance(enumFeatureClassComlex, point, searchTolerance, ref distance, ref featureClassID, ref featureGeometry); if (featureClassID == -1) { return(-1); } IProximityOperator proximityPoint = featureGeometry as IProximityOperator; IPoint p = proximityPoint.ReturnNearestPoint(point, esriSegmentExtension.esriNoExtension); if (elementType == esriElementType.esriETEdge) { return(geometricNetwork.get_EdgeElement(p)); } else if (elementType == esriElementType.esriETJunction) { return(geometricNetwork.get_JunctionElement(p)); } return(-1); }
//最近点捕捉 private static void GetNearestPntCollection(List <IFeature> listFeats, IFeatureClass pFeatureClass, IPoint pPnt, double dSearchDist) { IPointCollection pPntColTemp = new MultipointClass(); for (int i = 0; i < listFeats.Count; i++) { IFeature pFeature = listFeats[i]; if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline || pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { IProximityOperator pProximity = pFeature.Shape as IProximityOperator; IPoint pNearestPnt = pProximity.ReturnNearestPoint(pPnt, esriSegmentExtension.esriNoExtension); object befor = Type.Missing; object after = Type.Missing; m_PointCollection.AddPoint(pNearestPnt, ref befor, ref after); pPntColTemp.AddPoint(pNearestPnt, ref befor, ref after); } } m_dicPointCollection.Add(pPntColTemp, "NearestPnt"); }
public bool Snap(ESRI.ArcGIS.Geometry.IGeometry geom, ESRI.ArcGIS.Geometry.IPoint point, double tolerance) { GetFeatureClass(); bool b_setNewFeatureCache = false; if (m_featureClass == null || m_engineeditor == null) { return(false); } if (m_featureClass.ShapeType != esriGeometryType.esriGeometryPoint) { return(false); } //Check if a feature cache has been created. if (!b_setNewFeatureCache) { m_featureCache = new FeatureCache(); b_setNewFeatureCache = true; } //Fill the cache with the geometries. //It is up to the developer to choose an appropriate value //given the map units and the scale at which editing will be undertaken. FillCache(m_featureClass, point, 10000); IProximityOperator proximityOp = point as IProximityOperator; double minDist = tolerance; IPoint cachePt = new PointClass(); IPoint snapPt = new PointClass(); IPolygon outPoly = new PolygonClass(); ITopologicalOperator topoOp; IFeature feature; int Index = 0; for (int Count = 0; Count < m_featureCache.Count; Count++) { feature = m_featureCache.get_Feature(Count); cachePt = feature.Shape as IPoint; topoOp = cachePt as ITopologicalOperator; //Set the buffer distance to an appropriate value //given the map units and data being edited outPoly = topoOp.Buffer(1000) as IPolygon; double Dist = proximityOp.ReturnDistance(outPoly); if (Dist < minDist) { Index = Count; minDist = Dist; } } //Make sure minDist is within the search tolerance. if (minDist >= tolerance) { return(false); } //Retrieve the feature and its part again. feature = m_featureCache.get_Feature(Index); cachePt = feature.Shape as IPoint; topoOp = cachePt as ITopologicalOperator; //Set the buffer distance to an appropriate value //given the map scale and data being edited outPoly = topoOp.Buffer(1000) as IPolygon; proximityOp = outPoly as IProximityOperator; snapPt = proximityOp.ReturnNearestPoint(point, esriSegmentExtension.esriNoExtension); //Since point was passed in ByValue, we have to modify its values instead. //of giving it a new address. point.PutCoords(snapPt.X, snapPt.Y); return(true); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // 右键返回 if (Button == 2) { return; } if (m_pDongshiFeatureLayer == null) { return; } m_pPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_pPoint); double angle = -1; string layerName = LayerNames.LAYER_ALIAS_MR_TUNNEL_FD; //巷道 pFeatLayer = drawSpecialCom.GetFeatureLayerByName(layerName); IFeature pFeature = null; TestExistPointFeature(m_hookHelper, m_pPoint, pFeatLayer, ref pFeature); if (pFeature == null) { MessageBox.Show(@"鼠标点击处没有巷道,请先选择一条巷道边线", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //IPoint hightPoint= Snapping(m_pPoint, pFeatLayer, pFeature); //if (hightPoint.IsEmpty) //{ // MessageBox.Show("获取巷道边界失败,请重新选择", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} IProximityOperator proximityOperator = (IProximityOperator)pFeature.Shape; IPoint mousePoint = proximityOperator.ReturnNearestPoint(m_pPoint, esriSegmentExtension.esriNoExtension); IProximityOperator proximityOperator2 = (IProximityOperator)mousePoint; ISegmentCollection segmentCollection = (ISegmentCollection)pFeature.Shape; for (int i = 0; i < segmentCollection.SegmentCount; i++) { ISegmentCollection geometryCollection = new PolylineClass(); ISegment segment = segmentCollection.get_Segment(i); geometryCollection.AddSegment(segment); geometryCollection.SegmentsChanged(); var distance = proximityOperator2.ReturnDistance((IGeometry)geometryCollection); if (distance < 0.0001) { angle = ((ILine)segment).Angle; break; } } if (angle == -1) { MessageBox.Show(@"获取巷道边界失败,请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //得到相应的中线 string hdid = pFeature.get_Value(pFeature.Fields.FindField(GIS_Const.FIELD_HDID)).ToString(); string bid = pFeature.get_Value(pFeature.Fields.FindField(GIS_Const.FIELD_BID)).ToString(); FormCaveSizeInput frmCaveSize = new FormCaveSizeInput(); frmCaveSize.ShowDialog(); if (frmCaveSize.DialogResult == DialogResult.OK) { //输入正确,获得硐室的长和宽 double Width = frmCaveSize.CaveWidth; double Height = frmCaveSize.CaveHeight; PointClass p0 = RectanglePoint(mousePoint, angle, Width); PointClass p1 = RectanglePoint(mousePoint, angle + Math.PI, Width); PointClass p2 = RectanglePoint2(p0, angle + 90 * Math.PI / 180, Height); PointClass p3 = RectanglePoint2(p1, angle + 90 * Math.PI / 180, Height); //绘制硐室 CreateDongShi(p0, p2, p3, p1, hdid, bid); } }
private void btOK_Click(object sender, EventArgs e) { try { string pPointFileName = cboBoxPointLayer.SelectedItem.ToString(); string pCenterlinName = comboBoxExCenterlineLinearLayer.SelectedItem.ToString(); IFeatureLayer pPointLayer = null; IFeatureLayer pCenterlineLayer = null; for (int i = 0; i < pMapcontrol.LayerCount; i++) { if (pPointFileName == pMapcontrol.get_Layer(i).Name) { pPointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer; } if (pCenterlinName == pMapcontrol.get_Layer(i).Name) { pCenterlineLayer = pMapcontrol.get_Layer(i) as IFeatureLayer; } } IFeatureClass pLineFC = pCenterlineLayer.FeatureClass; IFeatureClass pPointFC = pPointLayer.FeatureClass; IFeatureCursor pLineCursor = pLineFC.Search(null, false); IFeature pLineFeature = pLineCursor.NextFeature(); IQueryFilter qf1 = null; DataTable ptable; if (radioButtonLayer.Checked) { ptable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pPointFC as ITable, qf1); } else { string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + this.textBoxFile.Text + ";Extended Properties=Excel 8.0"; OleDbConnection conn = new OleDbConnection(strCon); string sql1 = "select * from [Sheet1$]"; conn.Open(); OleDbDataAdapter myCommand = new OleDbDataAdapter(sql1, strCon); DataSet ds = new DataSet(); myCommand.Fill(ds); conn.Close(); ptable = ds.Tables[0]; if (ptable.Columns.Contains(EvConfig.IMUMoveDistanceField)) { ptable.Columns[EvConfig.IMUMoveDistanceField].DataType = System.Type.GetType("System.Double"); } } if (!ptable.Columns.Contains("X")) { ptable.Columns.Add("X", System.Type.GetType("System.Double")); } if (!ptable.Columns.Contains("Y")) { ptable.Columns.Add("Y", System.Type.GetType("System.Double")); } if (!ptable.Columns.Contains("Z")) { ptable.Columns.Add("Z", System.Type.GetType("System.Double")); } if (!ptable.Columns.Contains("对齐里程")) { ptable.Columns.Add("对齐里程", System.Type.GetType("System.Double")); } if (!ptable.Columns.Contains("距离偏移")) { ptable.Columns.Add("距离偏移", System.Type.GetType("System.Double")); } ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); //wgs 84 IGeographicCoordinateSystem wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326) as IGeographicCoordinateSystem; IUnit meterUnit = spatialReferenceFactory.CreateUnit((int)ESRI.ArcGIS.Geometry.esriSRUnitType.esriSRUnit_Meter); IPolyline pline = pLineFeature.Shape as IPolyline; pline.SpatialReference = wgs84; IProximityOperator pPO = pline as IProximityOperator; int idx = 0; for (int i = 0; i < ptable.Rows.Count; i++) { try { DataRow r = ptable.Rows[i]; IPoint pt = new PointClass(); pt.X = Convert.ToDouble(r[EvConfig.WeldXField]); pt.Y = Convert.ToDouble(r[EvConfig.WeldYField]); pt.SpatialReference = wgs84; IPoint ptInLine = pPO.ReturnNearestPoint(pt, esriSegmentExtension.esriNoExtension); r["X"] = ptInLine.X; r["Y"] = ptInLine.Y; r["对齐里程"] = ptInLine.M; r["Z"] = ptInLine.Z; r["距离偏移"] = Math.Round(DataAlignment.DataAlignment.CalculateDistanceBetween84TwoPoints(pt, ptInLine), 2); } catch { } } System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory); System.Runtime.InteropServices.Marshal.ReleaseComObject(pLineCursor); FrmIMUAlignmentresult frm = new FrmIMUAlignmentresult(ptable); frm.setResultType("焊缝对齐报告"); frm.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Handler operation Identify Route Ex /// </summary> /// <param name="boundVariables">list of variables bound</param> /// <param name="operationInput">input of operation</param> /// <param name="outputFormat">format of output</param> /// <param name="requestProperties">list of request properties</param> /// <param name="responseProperties">list of response properties </param> /// <returns>response in byte</returns> private byte[] IdentifyRouteExOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = "{\"Content-Type\" : \"application/json\"}"; string methodName = MethodBase.GetCurrentMethod().Name; int routeLayerID = Convert.ToInt32(boundVariables["RouteLayersID"], CultureInfo.InvariantCulture); esriUnits routeMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeMeasureUnit); esriSegmentExtension segmentExtension = DSUtility.GetSegmentExtension(operationInput); IFeatureClass featureClass = this.GetRouteFeatureClass(routeLayerID); JsonObject jsonLocation; if (!operationInput.TryGetJsonObject("location", out jsonLocation)) { throw new ArgumentException("Invalid location", methodName); } IPoint location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPoint) as IPoint; if (location == null) { throw new ArgumentException("Invalid location", methodName); } string routeIDFieldNameValue = DSUtility.GetRouteIDFieldName(operationInput); IFields fields = featureClass.Fields; int indexField = fields.FindField(routeIDFieldNameValue); if (indexField == -1) { throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "routeIDFieldName {0} not found!", routeIDFieldNameValue)); } object routeID; bool found = operationInput.TryGetObject("routeID", out routeID); if (!found) { throw new DynamicSegmentationException("routeID not valid"); } double?tolerance; found = operationInput.TryGetAsDouble("tolerance", out tolerance); if (!found || !tolerance.HasValue) { tolerance = 0.0; } IField field = fields.get_Field(indexField); this.CheckRouteID(routeID, field); IRouteLocator2 routeLocator = DSUtility.GetRouteLocator(featureClass, routeIDFieldNameValue, routeMeasureUnit); IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.SubFields = routeLocator.RouteIDFieldName; queryFilter.AddField(routeLocator.RouteFeatureClass.ShapeFieldName); string where = string.Format("{0} = {1}{2}{1}", routeLocator.RouteIDFieldNameDelimited, routeLocator.RouteIDIsString ? "'" : string.Empty, routeID); queryFilter.WhereClause = where; IPoint locationNearest = null; IFeatureCursor featureCursor = null; try { featureCursor = routeLocator.RouteFeatureClass.Search(queryFilter, true); IFeature featureRoute = featureCursor.NextFeature(); if (featureRoute == null) { throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "Feature with value {0} not found!", routeID)); } IProximityOperator proximityOperator = featureRoute.ShapeCopy as IProximityOperator; locationNearest = proximityOperator.ReturnNearestPoint(location, segmentExtension); } catch { throw; } finally { if (featureCursor != null) { Marshal.ReleaseComObject(featureCursor); } } IEnvelope envelope = locationNearest.Envelope; envelope.Expand(tolerance.Value, tolerance.Value, false); IRouteMeasurePointLocation routeMeasurePointLocation = new RouteMeasurePointLocationClass(); IRouteLocation routeLocation; IFeature feature; JsonObject result = new JsonObject(); List <JsonObject> measures = new List <JsonObject>(); IEnumRouteIdentifyResult enumResult = routeLocator.Identify(envelope, where); for (int i = 1; i <= enumResult.Count; i++) { enumResult.Next(out routeLocation, out feature); routeMeasurePointLocation = (IRouteMeasurePointLocation)routeLocation; JsonObject measure = new JsonObject(); measure.AddString("routeID", routeLocation.RouteID.ToString()); measure.AddDouble("measure", routeMeasurePointLocation.Measure); measure.AddJsonObject("location", Conversion.ToJsonObject(locationNearest, true)); measures.Add(measure); } result.AddArray("location", measures.ToArray()); return(result.JsonByte()); }
/// <summary> /// 等高线高程点点线矛盾检查,还需要完善 /// </summary> /// <param name="pFeaDataset"></param> /// <param name="desFeaCls">等高线要素类</param> /// <param name="oriFeaCls">高程点要素类</param> /// <param name="pointFeature">高程点要素</param> /// <param name="lineFieldName">等高线高程字段名</param> /// <param name="lineIndex">等高线高程字段索引</param> /// <param name="pointIndex">高程点高程字段民</param> /// <param name="nearestFea">离高程点要素最近的等高线要素</param> /// <param name="intervalElev">等高线间距值</param> /// <param name="eError"></param> private void PointLineAccordanceCheck2(IArcgisDataCheckHook hook, IFeatureDataset pFeaDataset, IFeatureClass desFeaCls, IFeatureClass oriFeaCls, IFeature pointFeature, string lineFieldName, int lineIndex, int pointIndex, IFeature nearestFea, double pShortestDis, double intervalElev, out Exception eError) { eError = null; try { double pValue = 0.0; //点要素的高程值 double fValue = 0.0; //最近线要素高程值 double lValue = 0.0; //最近线要素相邻的第一条要素 double sValue = 0.0; //最近线要素相邻的第二条要素 int eErrorID = enumErrorType.等高线点线矛盾检查.GetHashCode(); //错误ID string eErrorDes = "等高线与高程点高程值点线矛盾!"; //错误描述 //点要素的高程值 string pValueStr = pointFeature.get_Value(pointIndex).ToString().Trim(); if (pValueStr == "") { eError = new Exception("高程点的高程值为空,OID为:" + pointFeature.OID); return; } pValue = Convert.ToDouble(pValueStr); //最近线要素高程值 string fValueStr = nearestFea.get_Value(lineIndex).ToString().Trim(); if (fValueStr == "") { eError = new Exception("线要素的高程值为空。OID为:" + nearestFea.OID); return; } fValue = Convert.ToDouble(fValueStr); if (pShortestDis == 0) { //说明点在线上 if (pValue != fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } else { if (fValue < intervalElev) { #region 说明是最小高程,说明该要素是最里面或最外面的要素 //最近线要素相邻的第一条要素的高程值 lValue = fValue + intervalElev; string whereStr = lineFieldName + "=" + lValue; List <IFeature> lstFefa = GetFeatureByStr(desFeaCls, whereStr, out eError); if (eError != null || lstFefa == null || lstFefa.Count == 0) { return; } //bool isIntersact = false; //for (int k = 0; k < lstFefa.Count; k++) //{ if (lstFefa.Count == 1) { IFeature secondFea = lstFefa[0]; //返回secondFea上与高程点最近的点 IProximityOperator pProxiOper = secondFea.Shape as IProximityOperator; IPoint p = new PointClass(); p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension); // if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea)) // { // isIntersact = true; // secondFea = lstFefa[k]; // break; // } //} #region 最近线要素相邻的第一条要素上点与高程点连线与最近线要素的拓扑关系包含两种情况:相交、不相交。 if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea)) { //若两点连线与nearestFea相交,说明高程点在线要素的最里面或者最外面 //由于fValue<lValue if (pValue > fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } else { //若两点连线与nearestFea不相交,高程点在两条线要素之间 if (pValue < fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, secondFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } if (pValue > lValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } #endregion } #endregion } else if (fValue >= intervalElev) { #region 分为两种情况:或者是最里面或最外面的线要素、或者是中间线要素 //与nearestFea相邻的两线要素的高程值 lValue = fValue + intervalElev; sValue = fValue - intervalElev; //与最近要素要素的两个要素 IFeature secondFea = null; IFeature thirdFea = null; string whereStr = lineFieldName + "=" + lValue; List <IFeature> lstFea2 = GetFeatureByStr(desFeaCls, whereStr, out eError); if (eError != null || lstFea2 == null) { return; } whereStr = lineFieldName + "=" + sValue; List <IFeature> lstFea3 = GetFeatureByStr(desFeaCls, whereStr, out eError); if (eError != null || lstFea3 == null) { return; } if (lstFea2.Count == 0 && lstFea3.Count == 0) { //只有一条等高线 eError = new Exception("只有一条等高线,不能进行检查!"); return; } else if (lstFea2.Count == 1 && lstFea3.Count == 1) { secondFea = lstFea2[0]; thirdFea = lstFea3[0]; #region nearestFea不是最里面或最外面的要素 IPoint p = new PointClass(); IProximityOperator pProxiOper = secondFea.Shape as IProximityOperator; p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension); if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea)) { //相交。sValue<fValue<lValue ,pValue应位于sValue与fValue之间 if (pValue < sValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, thirdFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } if (pValue > fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } else { //不相交。sValue<fValue<lValue ,pValue应位于fValue与lValue之间 if (pValue < fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } if (pValue > lValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, secondFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } #endregion } else if (lstFea2.Count == 1 || lstFea3.Count == 1) { if (lstFea2.Count == 1 && lstFea3.Count == 0) { secondFea = lstFea2[0]; } else if (lstFea3.Count == 1 && lstFea2.Count == 0) { thirdFea = lstFea3[0]; } if (secondFea == null && thirdFea == null) { return; } #region nearestFea是最里面或最外面的要素 IPoint p = new PointClass(); if (secondFea != null) { IProximityOperator pProxiOper = secondFea.Shape as IProximityOperator; p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension); } if (thirdFea != null) { IProximityOperator pProxiOper = thirdFea.Shape as IProximityOperator; p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension); } if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea)) { //相交。高程点在等高线的最外面或最里面 if (secondFea != null) { //由于fValue<lValue if (pValue > fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } if (thirdFea != null) { //由于fValue>sValue if (pValue < fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } } else { //不相交。高程点在等高线的最靠边的两条等高线之间 if (secondFea != null) { //由于fValue<lValue if (pValue < fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } if (pValue > lValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, secondFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } if (thirdFea != null) { //由于fValue>sValue if (pValue > fValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } if (pValue < sValue) { //点线高程值矛盾 GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, thirdFea, eErrorID, eErrorDes, out eError); if (eError != null) { return; } } } } #endregion } #endregion } } } catch (Exception ex) { eError = ex; } }
/// <summary> /// 等高线点线矛盾一致性检查 /// </summary> /// <param name="feaClsLst"></param> /// <param name="lineFeaClsName">等高线要素类名称</param> /// <param name="lineFieldName">等高线高程字段名</param> /// <param name="pointFeaClsName">高程点要素类名称</param> /// <param name="pointFieldName">高程点字段名</param> /// <param name="radiu">高程点搜索半径</param> /// <param name="intervalValue">等高线间距值</param> /// <param name="eError"></param> public void PointLineElevCheck(IArcgisDataCheckHook hook, List <IDataset> feaClsLst, string lineFeaClsName, string lineFieldName, string pointFeaClsName, string pointFieldName, double intervalValue, out Exception eError) { eError = null; try { //等高线要素类 IFeatureClass lineFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(lineFeaClsName); foreach (IDataset pDT in feaClsLst) { string tempName = pDT.Name; if (tempName.Contains(".")) { tempName = tempName.Substring(tempName.IndexOf('.') + 1); } if (tempName == lineFeaClsName) { lineFeaCls = pDT as IFeatureClass; break; } } if (lineFeaCls == null) { return; } //等高线高程字段索引值 int lineIndex = lineFeaCls.Fields.FindField(lineFieldName); if (lineIndex == -1) { eError = new Exception("等高线图层的高程字段不存在,字段名为:" + lineFieldName); return; } //高程点要素类 IFeatureClass pointFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(pointFeaClsName); foreach (IDataset pDT in feaClsLst) { string tempName = pDT.Name; if (tempName.Contains(".")) { tempName = tempName.Substring(tempName.IndexOf('.') + 1); } if (tempName == pointFeaClsName) { pointFeaCls = pDT as IFeatureClass; break; } } if (pointFeaCls == null) { return; } int pointIndex = pointFeaCls.Fields.FindField(pointFieldName); if (lineIndex == -1) { eError = new Exception("高程点图层的高程字段不存在,字段名为:" + pointFieldName); return; } //遍历高程点要素 IFeatureCursor pCusor = pointFeaCls.Search(null, false); if (pCusor == null) { return; } IFeature pointFeature = pCusor.NextFeature(); while (pointFeature != null) { //高程点要素的高程值 double pointElevValue = Convert.ToDouble(pointFeature.get_Value(pointIndex).ToString()); //查找高程点相邻的两条高程线要素 //与高程点最近的等高线要素以及最短距离 Dictionary <double, IFeature> nearestFeaDic = GetShortestDis(lineFeaCls, pointFeature, out eError); if (eError != null || nearestFeaDic == null) { eError = new Exception("在搜索范围内的未找到要素!"); return; } double pShortestDis = -1; IFeature nearestFea = null; foreach (KeyValuePair <double, IFeature> item in nearestFeaDic) { pShortestDis = item.Key; nearestFea = item.Value; break; } if (eError != null || pShortestDis == -1) { return; } //获得等高线上离高程点最近的点 IPoint nearestPoint = new PointClass();//等高线上的最近点 IProximityOperator mProxiOpe = nearestFea.Shape as IProximityOperator; if (mProxiOpe == null) { return; } nearestPoint = mProxiOpe.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension); //将高程点和等高线上的点连成线段并进行两端延长 PointLineAccordanceCheck2(hook, null, lineFeaCls, pointFeaCls, pointFeature, lineFieldName, lineIndex, pointIndex, nearestFea, pShortestDis, intervalValue, out eError); //PointLineAccordanceCheck(pFeatureDataset, lineFeaCls, pointFeaCls, pointFeature, lineIndex, pointIndex, pShortestDis, nearestFea, intervalValue, out eError); if (eError != null) { return; } pointFeature = pCusor.NextFeature(); } //释放cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(pCusor); } catch (Exception ex) { eError = ex; } }
/// <summary> /// 等高线点线矛盾一致性检查 /// </summary> /// <param name="pFeatureDataset"></param> /// <param name="lineFeaClsName">等高线要素类名称</param> /// <param name="lineFieldName">等高线高程字段名</param> /// <param name="pointFeaClsName">高程点要素类名称</param> /// <param name="pointFieldName">高程点字段名</param> /// <param name="radiu">高程点搜索半径</param> /// <param name="intervalValue">等高线间距值</param> /// <param name="eError"></param> private void PointLineElevCheck(IArcgisDataCheckHook hook, IFeatureDataset pFeatureDataset, string lineFeaClsName, string lineFieldName, string pointFeaClsName, string pointFieldName, double intervalValue, out Exception eError) { eError = null; try { //等高线要素类 IFeatureClass lineFeaCls = (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(lineFeaClsName); //等高线高程字段索引值 int lineIndex = lineFeaCls.Fields.FindField(lineFieldName); if (lineIndex == -1) { eError = new Exception("等高线图层的高程字段不存在,字段名为:" + lineFieldName); return; } //高程点要素类 IFeatureClass pointFeaCls = (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(pointFeaClsName); int pointIndex = pointFeaCls.Fields.FindField(pointFieldName); if (lineIndex == -1) { eError = new Exception("高程点图层的高程字段不存在,字段名为:" + pointFieldName); return; } //遍历高程点要素 IFeatureCursor pCusor = pointFeaCls.Search(null, false); if (pCusor == null) { return; } IFeature pointFeature = pCusor.NextFeature(); //设置进度条 ProgressChangeEvent eInfo = new ProgressChangeEvent(); eInfo.Max = pointFeaCls.FeatureCount(null); int pValue = 0; while (pointFeature != null) { //高程点要素的高程值 double pointElevValue = Convert.ToDouble(pointFeature.get_Value(pointIndex).ToString()); //查找高程点相邻的两条高程线要素 //与高程点最近的等高线要素以及最短距离 Dictionary <double, IFeature> nearestFeaDic = GetShortestDis(lineFeaCls, pointFeature, out eError); if (eError != null || nearestFeaDic == null) { eError = new Exception("在搜索范围内的未找到要素!"); return; } double pShortestDis = -1; IFeature nearestFea = null; foreach (KeyValuePair <double, IFeature> item in nearestFeaDic) { pShortestDis = item.Key; nearestFea = item.Value; break; } if (eError != null || pShortestDis == -1) { return; } //获得等高线上离高程点最近的点 IPoint nearestPoint = new PointClass();//等高线上的最近点 IProximityOperator mProxiOpe = nearestFea.Shape as IProximityOperator; if (mProxiOpe == null) { return; } nearestPoint = mProxiOpe.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension); //将高程点和等高线上的点连成线段并进行两端延长 PointLineAccordanceCheck2(hook, pFeatureDataset, lineFeaCls, pointFeaCls, pointFeature, lineFieldName, lineIndex, pointIndex, nearestFea, pShortestDis, intervalValue, out eError); //PointLineAccordanceCheck(pFeatureDataset, lineFeaCls, pointFeaCls, pointFeature, lineIndex, pointIndex, pShortestDis, nearestFea, intervalValue, out eError); if (eError != null) { return; } pointFeature = pCusor.NextFeature(); //进度条加1 pValue++; eInfo.Value = pValue; GeoDataChecker.GeoDataChecker_ProgressShow((object)GeoDataChecker._ProgressBarInner, eInfo); } //释放cursor System.Runtime.InteropServices.Marshal.ReleaseComObject(pCusor); } catch (Exception ex) { eError = ex; } }
/// <summary> /// 生成格网信息 /// </summary> /// <param name="pFeature">Featureclass</param> /// <returns></returns> public static string GetCodeString(IFeature pFeature) { double centroidX = 0; double centroidY = 0; IPoint pPoint = null; IPoint pPointEverrage = new PointClass(); IPoint pPointNearest = new PointClass(); IPoint pPointEverrage1 = new PointClass(); IPoint pPointNearest1 = new PointClass(); //求要素的质量中心 switch (pFeature.Shape.GeometryType) { case esriGeometryType.esriGeometryPoint: pPoint = pFeature.ShapeCopy as IPoint; centroidX = pPoint.X; centroidY = pPoint.Y; break; case esriGeometryType.esriGeometryPolyline: IPolyline pPolyline = pFeature.ShapeCopy as IPolyline; IPointCollection pPointCollection = pPolyline as IPointCollection; //20170607 先求出点集的中心点,然后再算出中心点到polyline的最近的点,之后用改点来替代整个polyline,保证了该点在改地理实体上 IProximityOperator proOperator = pPolyline as IProximityOperator; double centerX = 0; double centerY = 0; for (int i = 0; i < pPointCollection.PointCount; i++) { pPoint = pPointCollection.get_Point(i); centerX += pPoint.X; centerY += pPoint.Y; } centroidX = centerX / pPointCollection.PointCount; centroidY = centerY / pPointCollection.PointCount; //20170607 pPointEverrage.X = centroidX; pPointEverrage.Y = centroidY; if (pPointEverrage != null) { pPointNearest = proOperator.ReturnNearestPoint(pPointEverrage, esriSegmentExtension.esriNoExtension); } centroidX = pPointNearest.X; centroidY = pPointNearest.Y; break; case esriGeometryType.esriGeometryPolygon: //多边形获取的是中心节点的坐标 IPolygon pPolygon = pFeature.ShapeCopy as IPolygon; IPointCollection pPolygonCollection = pPolygon as IPointCollection; //20170607 先求出点集的中心点,然后再算出中心点到polyline的最近的点,之后用改点来替代整个polyline,保证了该点在改地理实体上 IProximityOperator pOperator = pPolygon as IProximityOperator; double PolygoncenterX = 0; double PolygoncenterY = 0; for (int i = 0; i < pPolygonCollection.PointCount; i++) { pPoint = pPolygonCollection.get_Point(i); PolygoncenterX += pPoint.X; PolygoncenterY += pPoint.Y; } centroidX = PolygoncenterX / pPolygonCollection.PointCount; centroidY = PolygoncenterY / pPolygonCollection.PointCount; //20170607 pPointEverrage1.X = centroidX; pPointEverrage1.Y = centroidY; if (pPointEverrage != null) { pPointNearest1 = pOperator.ReturnNearestPoint(pPointEverrage1, esriSegmentExtension.esriNoExtension); } centroidX = pPointNearest1.X; centroidY = pPointNearest1.Y; break; } try { //加入第一级格网和第二级格网的信息 string strCode = loadFirstGrid(centroidX, centroidY); return(strCode); } catch (Exception ex) { ClsLog.WriteFile(ex, pFeature.OID.ToString()); return(""); } }
private void btOK_Click(object sender, EventArgs e) { string pPointFileName = cboBoxPointLayer.SelectedItem.ToString(); string pCenterlinName = comboBoxExCenterlineLayer.SelectedItem.ToString(); IFeatureLayer pPointLayer = null; IFeatureLayer pCenterlineLayer = null; for (int i = 0; i < pMapcontrol.LayerCount; i++) { if (pPointFileName == pMapcontrol.get_Layer(i).Name) { pPointLayer = pMapcontrol.get_Layer(i) as IFeatureLayer; } if (pCenterlinName == pMapcontrol.get_Layer(i).Name) { pCenterlineLayer = pMapcontrol.get_Layer(i) as IFeatureLayer; } } IFeatureClass pLineFC = pCenterlineLayer.FeatureClass; IFeatureClass pPointFC = pPointLayer.FeatureClass; IQueryFilter pQF = null; IFeatureCursor pLineCursor = pLineFC.Search(null, false); IFeatureCursor pPointCursor = pPointFC.Search(null, false); IFeature pLineFeature = pLineCursor.NextFeature(); DataTable ptTable = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pPointFC as ITable, pQF); ptTable.Columns.Add("长度"); ptTable.Columns.Add("距离"); ptTable.Columns.Add("中间点坐标"); if (pLineFeature != null) { ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); //wgs 84 IGeographicCoordinateSystem wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326) as IGeographicCoordinateSystem; IUnit meterUnit = spatialReferenceFactory.CreateUnit((int)ESRI.ArcGIS.Geometry.esriSRUnitType.esriSRUnit_Meter); IPolyline pline = pLineFeature.Shape as IPolyline; pline.SpatialReference = wgs84; IProximityOperator pPO = pline as IProximityOperator; IFeature ptFeature = pPointCursor.NextFeature(); int idx = 0; System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory); while (ptFeature != null) { DataRow row = ptTable.Rows[idx]; IPoint pt = ptFeature.Shape as IPoint; pt.SpatialReference = wgs84; IPoint nearestpt = pPO.ReturnNearestPoint(pt, esriSegmentExtension.esriNoExtension); double distance = DataAlignment.DataAlignment.CalculateDistanceBetween84TwoPoints(pt, nearestpt); // = pPO.ReturnDistance(pt); row["距离"] = distance; if (idx == 0) { row["长度"] = 0; } else { DataRow preRow = ptTable.Rows[idx - 1]; row["长度"] = Convert.ToDouble(row[EvConfig.IMUMoveDistanceField]) - Convert.ToDouble(preRow[EvConfig.IMUMoveDistanceField]); } ptFeature = pPointCursor.NextFeature(); idx++; } System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory); } DataTable dt2 = new DataTable(); dt2.Columns.Add("名称"); dt2.Columns.Add("长度"); dt2.Columns.Add("比例"); // List<DataRow> rowlist = (dt2.Rows.Where(e => Convert.ToDouble(e["距离"]) <= 2)).ToList(); List <DataRow> less1 = (from DataRow r in ptTable.Rows where Convert.ToDouble(r["距离"]) <= 1 select r).ToList(); double length1 = less1.Sum(x => Convert.ToDouble(x["长度"])); int sum1 = less1.Count; List <DataRow> Great2 = (from DataRow r in ptTable.Rows where Convert.ToDouble(r["距离"]) > 2 select r).ToList(); double length2 = Great2.Sum(x => Convert.ToDouble(x["长度"])); int sum2 = Great2.Count; List <DataRow> Medium2 = (from DataRow r in ptTable.Rows where Convert.ToDouble(r["距离"]) > 1 && Convert.ToDouble(r["距离"]) <= 2 select r).ToList(); double length3 = Medium2.Sum(x => Convert.ToDouble(x["长度"])); int sum3 = Medium2.Count; DataRow r1; r1 = dt2.Rows.Add(); r1[0] = "≤1米"; r1[1] = length1; r1[2] = 1.0 * sum1 / (sum1 + sum2 + sum3); r1 = dt2.Rows.Add(); r1[0] = ">1米且≤2米"; r1[1] = length3; r1[2] = 1.0 * sum3 / (sum1 + sum2 + sum3); r1 = dt2.Rows.Add(); r1[0] = "大于2米"; r1[1] = length2; r1[2] = 1.0 * sum2 / (sum1 + sum2 + sum3); List <DataTable> tablelist = new List <DataTable>(); tablelist.Add(ptTable); tablelist.Add(dt2); FRMInsideInspectionReport frm = new FRMInsideInspectionReport(tablelist); frm.ShowDialog(); }
/// <summary> /// 生成指定精度的GeoHash编码 /// </summary> /// <param name="pFeature"></param> /// <param name="precision"></param> /// <returns></returns> public string GetGeoHashCode(IFeature pFeature, int precision) { string geoHashGrid = ""; double centroidX = 0; double centroidY = 0; IPoint pPoint = null; IPoint pPointEverrage = new PointClass(); IPoint pPointNearest = new PointClass(); IPoint pPointEverrage1 = new PointClass(); IPoint pPointNearest1 = new PointClass(); if (pFeature != null) { //求要素的质量中心 switch (pFeature.Shape.GeometryType) { case esriGeometryType.esriGeometryPoint: pPoint = pFeature.ShapeCopy as IPoint; centroidX = pPoint.X; centroidY = pPoint.Y; break; case esriGeometryType.esriGeometryPolyline: IPolyline pPolyline = pFeature.ShapeCopy as IPolyline; IPointCollection pPointCollection = pPolyline as IPointCollection; //20170607 先求出点集的中心点,然后再算出中心点到polyline的最近的点,之后用改点来替代整个polyline,保证了该点在改地理实体上 IProximityOperator proOperator = pPolyline as IProximityOperator; double centerX = 0; double centerY = 0; for (int i = 0; i < pPointCollection.PointCount; i++) { pPoint = pPointCollection.get_Point(i); centerX += pPoint.X; centerY += pPoint.Y; } centroidX = centerX / pPointCollection.PointCount; centroidY = centerY / pPointCollection.PointCount; //20170607 pPointEverrage.X = centroidX; pPointEverrage.Y = centroidY; if (pPointEverrage != null) { pPointNearest = proOperator.ReturnNearestPoint(pPointEverrage, esriSegmentExtension.esriNoExtension); } centroidX = pPointNearest.X; centroidY = pPointNearest.Y; break; case esriGeometryType.esriGeometryPolygon: //多边形获取的是中心节点的坐标 IPolygon pPolygon = pFeature.ShapeCopy as IPolygon; IPointCollection pPolygonCollection = pPolygon as IPointCollection; //20170607 先求出点集的中心点,然后再算出中心点到polyline的最近的点,之后用改点来替代整个polyline,保证了该点在改地理实体上 IProximityOperator pOperator = pPolygon as IProximityOperator; double PolygoncenterX = 0; double PolygoncenterY = 0; for (int i = 0; i < pPolygonCollection.PointCount; i++) { pPoint = pPolygonCollection.get_Point(i); PolygoncenterX += pPoint.X; PolygoncenterY += pPoint.Y; } centroidX = PolygoncenterX / pPolygonCollection.PointCount; centroidY = PolygoncenterY / pPolygonCollection.PointCount; //20170607 pPointEverrage1.X = centroidX; pPointEverrage1.Y = centroidY; if (pPointEverrage != null) { pPointNearest1 = pOperator.ReturnNearestPoint(pPointEverrage1, esriSegmentExtension.esriNoExtension); } centroidX = pPointNearest1.X; centroidY = pPointNearest1.Y; break; } try { //生成四级GeoHash格网 geoHashGrid = ClsGeoHash.Encode(centroidX, centroidY, precision); geoHashGrid = geoHashGrid.ToUpper(); } catch (Exception ex) { ClsLog.WriteFile(ex, pFeature.OID.ToString()); return(""); } } else { MessageBox.Show("要素为空!"); } return(geoHashGrid); }