//将收集到的点转换成线 private IPolyline CreatePolyline(IPointCollection pPointcollection) { int PointNumber = int.Parse(pPointcollection.PointCount.ToString()); object o = Type.Missing; //线数组 ISegmentCollection pSegmentCollection = new PolylineClass(); IZAware z = pSegmentCollection as IZAware; IMAware m = pSegmentCollection as IMAware; z.ZAware = true; m.MAware = true; for (int i = 0; i < PointNumber - 1; i++) { ILine pLine = new LineClass(); pLine.PutCoords(pPointcollection.get_Point(i), pPointcollection.get_Point(i + 1)); pSegmentCollection.AddSegment((ISegment)pLine, ref o, ref o); } IPolyline pPolyline = new PolylineClass(); pPolyline = pSegmentCollection as IPolyline; return(pPolyline); }
private void CreateFeature(IGeometry geo, IMap pMap, IFeatureClass fc) { try { if (geo == null || fc == null || pMap == null) { return; } IDataset pDataset = fc as IDataset; IWorkspaceEdit pWorkspaceEdit = pDataset.Workspace as IWorkspaceEdit; int index = fc.FindField(fc.ShapeFieldName); IGeometryDef pGD = fc.Fields.get_Field(index).GeometryDef; if (pGD.HasZ) { IZAware pZA = geo as IZAware; pZA.ZAware = true; IZ pZ = geo as IZ; double zmin = -1000, zmax = 1000; if (pGD.SpatialReference.HasZPrecision()) { pGD.SpatialReference.GetZDomain(out zmin, out zmax); } if (pZ != null) { pZ.SetConstantZ(0); } else { IPoint p = geo as IPoint; if (p.Z.ToString() == "非数字") { p.Z = 0; } } } if (pGD.HasM) { IMAware pMA = geo as IMAware; pMA.MAware = true; } if (!pWorkspaceEdit.IsBeingEdited()) { pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); } IFeature pFeature = fc.CreateFeature(); pFeature.Shape = geo; pFeature.Store(); if (pWorkspaceEdit.IsBeingEdited()) { pWorkspaceEdit.StartEditOperation(); pWorkspaceEdit.StopEditing(true); } pMap.ClearSelection(); } catch (System.Exception ex) { return; } }
/// <summary> /// 为几何形体增加Z值和M值 /// </summary> /// <param name="pGeo">存储几何形体</param> /// <param name="pPointArray">用于更新几何形体Z值、M值的点数组</param> public static void AddZMValueForGeometry(ref IGeometry pGeo, IArray pPointArray) { IPointCollection pPointCol = (IPointCollection)pGeo; for (int j = 0; j < pPointCol.PointCount; j++) { IPoint pPoint = pPointCol.get_Point(j); IZAware pZ = (IZAware)pPoint; pZ.ZAware = true; pPoint.Z = 0; IMAware pM = (IMAware)pPoint; pM.MAware = true; pPoint.M = 0; for (int k = 0; k < pPointArray.Count; k++) { IPoint pTempPoint = (IPoint)pPointArray.get_Element(k); if (Math.Abs(pPoint.X - pTempPoint.X) < 0.001 && Math.Abs(pPoint.Y - pTempPoint.Y) < 0.001 && pTempPoint.Z != -999) { pPoint.Z = pTempPoint.Z; pPoint.M = pTempPoint.M; break; } } pPointCol.UpdatePoint(j, pPoint); } IZAware pG = (IZAware)pGeo; pG.ZAware = true; pGeo = (IGeometry)pPointCol; }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add AddNetStopsTool.OnMouseDown implementation try { IPoint pStopsPoint = new PointClass(); pStopsPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IFeature newPointFeature = inputFClass.CreateFeature(); try { pStopsPoint.Z = 0; newPointFeature.Shape = pStopsPoint; IZAware pZAware = pStopsPoint as IZAware; IMAware pMAware = pStopsPoint as IMAware; pZAware.ZAware = true; pMAware.MAware = true; } catch { IGeometry pGeo = pStopsPoint; IZAware pZAware = pGeo as IZAware; pZAware.ZAware = false; newPointFeature.Shape = pGeo; } newPointFeature.Store(); IGraphicsContainer pGrap = m_hookHelper.ActiveView as IGraphicsContainer; IColor pColor; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pRgbColor.Green = 255; pRgbColor.Blue = 255; pColor = pRgbColor as IColor; IPictureMarkerSymbol pms = new PictureMarkerSymbolClass(); pms.BitmapTransparencyColor = pColor; string picturePath = ApplicationV.Data_ImgPath + "\\stops.bmp"; //添加自定义站点图片 pms.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, picturePath); pms.Size = 18; IMarkerElement pMarkerEle = new MarkerElementClass(); pMarkerEle.Symbol = pms as IMarkerSymbol; pStopsPoint.SpatialReference = m_hookHelper.ActiveView.FocusMap.SpatialReference; IElement pEle = pMarkerEle as IElement; pEle.Geometry = pStopsPoint; pGrap.AddElement(pEle, 1); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch { MessageBox.Show("添加站点失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add AddNetStopsTool.OnMouseDown implementation try { //根据人为用鼠标在地图上单击的点的坐标新建站点要素 IPoint pStopsPoint = new PointClass(); //将鼠标在屏幕上点击的一点的坐标转换为地图上的坐标,并赋给pStopsPoint pStopsPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IFeature newPointFeature = inputFClass.CreateFeature();//创建新的障碍点要素 try { pStopsPoint.Z = 0; newPointFeature.Shape = pStopsPoint; //将pStopsPoint赋给新要素的Shape属性 IZAware pZAware = pStopsPoint as IZAware; //Z值为高程 IMAware pMAware = pStopsPoint as IMAware; //M值是用来储存其他属性信息,如温度、浓度 pZAware.ZAware = true; pMAware.MAware = true; } catch { IGeometry pGeo = pStopsPoint; IZAware pZAware = pGeo as IZAware; pZAware.ZAware = false; newPointFeature.Shape = pGeo; } newPointFeature.Store();//储存新建的站点要素 //将站点图标添加到图层 IGraphicsContainer pGrap = m_hookHelper.ActiveView as IGraphicsContainer; IColor pColor; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pRgbColor.Green = 255; pRgbColor.Blue = 255; pColor = pRgbColor as IColor; IPictureMarkerSymbol pms = new PictureMarkerSymbolClass(); pms.BitmapTransparencyColor = pColor; string picturePath = NetWorkAnalysClass.getPath(path) + "\\data\\Img\\stops.bmp"; //添加自定义站点图片 pms.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, picturePath); pms.Size = 18; IMarkerElement pMarkerEle = new MarkerElementClass(); pMarkerEle.Symbol = pms as IMarkerSymbol; //将站点位置数据的空间参考设为与地图空间参考一致 pStopsPoint.SpatialReference = m_hookHelper.ActiveView.FocusMap.SpatialReference; IElement pEle = pMarkerEle as IElement; pEle.Geometry = pStopsPoint; pGrap.AddElement(pEle, 1); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch { MessageBox.Show("添加站点失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
public static void PointAddM(IPoint point, double value) { IMAware pMAware = point as IMAware; if (pMAware == null) { return; } pMAware.MAware = true; point.M = value; }
/// <summary> /// Gets polyline geometry corresponding to the subcurve(s) between the fromM and the toM. /// </summary> /// <param name="source">The source.</param> /// <param name="fromM">From m.</param> /// <param name="toM">To m.</param> /// <returns></returns> public static IPolyline GetPolylineByMs(this IMSegmentation4 source, double fromM, double toM) { IMAware aware = source as IMAware; if (aware != null && aware.MAware) { var collection = source.GetSubcurveBetweenMs(fromM, toM); return(collection as IPolyline); } return(null); }
public static IPointCollection CreatePointCollection(IPoint point1, IPoint point2, bool hasZ = true, bool hasM = true) { IPointCollection pointCollection = new PolylineClass(); IZAware pZAware = pointCollection as IZAware; pZAware.ZAware = hasZ; IMAware pMAware = pointCollection as IMAware; pMAware.MAware = hasM; pointCollection.AddPoint(CreatePoint(point1.X, point1.Y, point1.Z, point1.M, hasZ, hasM)); pointCollection.AddPoint(CreatePoint(point2.X, point2.Y, point2.Z, point2.M, hasZ, hasM)); return(pointCollection); }
public static IPointCollection CreatePointCollection(List <IPoint> list, bool hasZ = true, bool hasM = true) { IPointCollection pointCollection = new PolylineClass(); IZAware pZAware = pointCollection as IZAware; pZAware.ZAware = hasZ; IMAware pMAware = pointCollection as IMAware; pMAware.MAware = hasM; for (int i = 0; i < list.Count; i++) { pointCollection.AddPoint(list[i]); } return(pointCollection); }
public static IGeometry GeometryConvertM(IFeature feature, bool hasZ, bool hasM) { IGeometry geometry = feature.ShapeCopy; IZAware zAware = geometry as IZAware; if (zAware != null) { zAware.ZAware = hasZ; } IMAware mAware = geometry as IMAware; if (mAware != null) { mAware.MAware = hasM; } return(geometry); }
private void SetZMProperty(IGeometry pGeom) { IFeatureClass featureClass = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer.FeatureClass; int index = featureClass.FindField(featureClass.ShapeFieldName); IGeometryDef geometryDef = featureClass.Fields.get_Field(index).GeometryDef; if (geometryDef.HasZ) { IZAware aware = (IZAware)pGeom; aware.ZAware = true; } if (geometryDef.HasM) { IMAware aware2 = (IMAware)pGeom; aware2.MAware = true; } }
/// <summary> /// Geometry中Z值和M值处理 /// </summary> /// <params name="feature"></params> /// <params name="geometry"></params> /// <params name="zValue"></params> public static void HandleZMValue(IFeature feature, IGeometry geometry, double zValue) { //先判断图层要素是否有Z值 int index; index = feature.Fields.FindField(GIS_Const.FIELD_SHAPE); IGeometryDef pGeometryDef; pGeometryDef = feature.Fields.get_Field(index).GeometryDef as IGeometryDef; IPointCollection pPointCollection = geometry as IPointCollection; if (pGeometryDef.HasZ) { IZAware pZAware = (IZAware)geometry; pZAware.ZAware = true; if (geometry.GeometryType == esriGeometryType.esriGeometryPoint) { IPoint point = (IPoint)geometry; point.Z = zValue; } else { IZ iz1 = (IZ)geometry; iz1.SetConstantZ(zValue); //将Z值设置为zValue } } else { IZAware pZAware = (IZAware)geometry; pZAware.ZAware = false; } if (pGeometryDef.HasM) { IMAware pMAware = (IMAware)geometry; pMAware.MAware = true; } else { IMAware pMAware = (IMAware)geometry; pMAware.MAware = false; } }
public static void PolylineAddM(IPolyline polyline, double sValue, double eValue) { IMAware pMAware = polyline as IMAware; if (pMAware == null) { return; } pMAware.MAware = true; IPoint fromPoint = polyline.FromPoint; PointAddM(fromPoint, sValue); polyline.FromPoint = fromPoint; IPoint toPoint = polyline.ToPoint; PointAddM(toPoint, eValue); polyline.ToPoint = toPoint; }
/// <summary> /// Returns M values at the distance along the polyline. An array of one or two Ms is returned. Two Ms can be returned /// if the given distance is exactly at the beginning or ending of a part. /// </summary> /// <param name="source">The source.</param> /// <param name="point">The point.</param> /// <returns>Returns a <see cref="double" /> array of the m values.</returns> /// <remarks> /// Does not assume that the point is on top of the polyline. If the point is equally distant from more that one /// location along the polyline, then returns the all the M values. /// </remarks> public static double[] GetMsAtPoint(this IPolyline source, IPoint point) { IMAware aware = (IMAware)source; if (aware.MAware) { double distanceAlongCurve = 0.0; double distanceFromCurve = 0.0; bool rightSide = false; IPoint queryPoint = new PointClass(); source.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, queryPoint, ref distanceAlongCurve, ref distanceFromCurve, ref rightSide); IMSegmentation segmentation = (IMSegmentation)source; var values = segmentation.GetMsAtDistance(distanceAlongCurve, false) as double[]; return(values); } return(null); }
public static IGeometry ModifyGeometryZMValue(IObjectClass featureClass, IGeometry modifiedGeometry) { IFeatureClass targetFeatureClass = featureClass as IFeatureClass; if (targetFeatureClass == null) { return(null); } string shapeFieldName = targetFeatureClass.ShapeFieldName; IFields fields = targetFeatureClass.Fields; int geometryIndex = fields.FindField(shapeFieldName); IField field = fields.get_Field(geometryIndex); IGeometryDef geometryDef = field.GeometryDef; IPointCollection pointCollection = modifiedGeometry as IPointCollection; if (geometryDef.HasZ) { IZAware zAware = modifiedGeometry as IZAware; zAware.ZAware = true; IZ iz = modifiedGeometry as IZ; //将Z值设置为0 iz.SetConstantZ(0); } else { IZAware zAware = modifiedGeometry as IZAware; zAware.ZAware = false; } if (geometryDef.HasM) { IMAware mAware = modifiedGeometry as IMAware; mAware.MAware = true; } else { IMAware mAware = modifiedGeometry as IMAware; mAware.MAware = false; } return(modifiedGeometry); }
/// <summary> /// Geometry中Z值和M值处理 /// </summary> /// <params name="feature"></params> /// <params name="geometry"></params> /// <params name="zValue"></params> public static void HandleZMValue(IFeature feature, IGeometry geometry) { //先判断图层要素是否有Z值 int index; index = feature.Fields.FindField(GIS_Const.FIELD_SHAPE); IGeometryDef pGeometryDef; pGeometryDef = feature.Fields.get_Field(index).GeometryDef as IGeometryDef; IPointCollection pPointCollection = geometry as IPointCollection; if (pGeometryDef.HasZ) { IZAware pZAware = (IZAware)geometry; pZAware.ZAware = true; if (geometry.Envelope.ZMax.ToString() == "非数字" || geometry.Envelope.ZMax.ToString() == "NaN") { IZ iz1 = (IZ)geometry; iz1.SetConstantZ(0); //将Z值设置为0 } //IPoint point = (IPoint)geometry; //point.Z = 0; } else { IZAware pZAware = (IZAware)geometry; pZAware.ZAware = false; } if (pGeometryDef.HasM) { IMAware pMAware = (IMAware)geometry; pMAware.MAware = true; } else { IMAware pMAware = (IMAware)geometry; pMAware.MAware = false; } }
public static void MakeZMAware(IGeometry igeometry_0, bool bool_0) { if (igeometry_0 is IZAware) { IZAware iZAware = igeometry_0 as IZAware; if (iZAware.ZAware && !bool_0) { iZAware.DropZs(); } iZAware.ZAware = bool_0; } if (igeometry_0 is IMAware) { IMAware iMAware = igeometry_0 as IMAware; if (iMAware.MAware && !bool_0) { iMAware.DropMs(); } iMAware.MAware = bool_0; } }
public static void MakeZMAware(IGeometry igeometry_0, bool bool_0) { if (igeometry_0 is IZAware) { IZAware igeometry0 = igeometry_0 as IZAware; if ((!igeometry0.ZAware ? false : !bool_0)) { igeometry0.DropZs(); } igeometry0.ZAware = bool_0; } if (igeometry_0 is IMAware) { IMAware bool0 = igeometry_0 as IMAware; if ((!bool0.MAware ? false : !bool_0)) { bool0.DropMs(); } bool0.MAware = bool_0; } }
public static IGeometry ModifyGeomtryZMValue(IObjectClass featureClass, IGeometry modifiedGeo) { IFeatureClass trgFtCls = featureClass as IFeatureClass; if (trgFtCls == null) { return(null); } string shapeFieldName = trgFtCls.ShapeFieldName; IFields fields = trgFtCls.Fields; int geometryIndex = fields.FindField(shapeFieldName); IField field = fields.get_Field(geometryIndex); IGeometryDef pGeometryDef = field.GeometryDef; IPointCollection pPointCollection = modifiedGeo as IPointCollection; if (pGeometryDef.HasZ) { IZAware pZAware = modifiedGeo as IZAware; pZAware.ZAware = true; IZ iz1 = modifiedGeo as IZ; //将z值设置为0 iz1.SetConstantZ(0); } else { IZAware pZAware = modifiedGeo as IZAware; pZAware.ZAware = false; } if (pGeometryDef.HasM) { IMAware pMAware = modifiedGeo as IMAware; pMAware.MAware = true; } else { IMAware pMAware = modifiedGeo as IMAware; pMAware.MAware = false; } return(modifiedGeo); }
public static List <IPolyline> ToPolylineList(IPolyline polyline) { List <IPolyline> polylines = new List <IPolyline>(); IZAware pZAware = polyline as IZAware; IMAware pMAware = polyline as IMAware; if (pZAware == null || pMAware == null) { return(polylines); } IPointCollection pointCollection = polyline as IPointCollection; if (pointCollection == null) { return(polylines); } for (int i = 1; i < pointCollection.PointCount; i++) { IPolyline tempPolyline = new PolylineClass { FromPoint = new PointClass { X = pointCollection.Point[i - 1].X, Y = pointCollection.Point[i - 1].Y }, ToPoint = new PointClass { X = pointCollection.Point[i].X, Y = pointCollection.Point[i].Y } }; IZAware pTempZAware = tempPolyline as IZAware; pTempZAware.ZAware = pZAware.ZAware; IMAware pTempMAware = tempPolyline as IMAware; pTempMAware.MAware = pMAware.MAware; polylines.Add(tempPolyline); } return(polylines); }
public static IPoint CreatePoint(double x, double y, double z = 0, double m = 0, bool hasZ = true, bool hasM = true) { IPoint point = new PointClass { X = x, Y = y }; IZAware pZAware = point as IZAware; pZAware.ZAware = hasZ; if (hasZ) { point.Z = z; } IMAware pMAware = point as IMAware; pMAware.MAware = hasM; if (hasM) { point.M = m; } return(point); }
/// <summary> /// object polyline. Distance negative -> upstream /// </summary> /// <param name="geometricNetwork">object geometricNetwork</param> /// <param name="resultEdges">objects resultEdges</param> /// <param name="distance">value of distance</param> /// <param name="point">object point</param> /// <param name="offset">offset of polyline</param> /// <param name="messageInfo">info on result</param> /// <returns>object IGeometry (polyline or point)</returns> internal static IGeometry GetPolylinePosAlong(ESRI.ArcGIS.Geodatabase.IGeometricNetwork geometricNetwork, IEnumNetEID resultEdges, double distance, IPoint point, double?offset, ref string messageInfo) { IGeometry geometryBag = new GeometryBagClass(); geometryBag.SpatialReference = point.SpatialReference; IGeometryCollection geometryCollection = geometryBag as IGeometryCollection; IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = geometricNetwork; eidHelper.ReturnGeometries = true; eidHelper.ReturnFeatures = false; IEnumEIDInfo enumEIDinfo = eidHelper.CreateEnumEIDInfo(resultEdges); enumEIDinfo.Reset(); IEIDInfo eidInfo = enumEIDinfo.Next(); while (eidInfo != null) { IGeometry geometry = eidInfo.Geometry; geometryCollection.AddGeometry(geometry); eidInfo = enumEIDinfo.Next(); } ITopologicalOperator unionedPolyline = new PolylineClass(); unionedPolyline.ConstructUnion(geometryBag as IEnumGeometry); IPolyline pl = unionedPolyline as IPolyline; if (distance < 0) { pl.ReverseOrientation(); distance = Math.Abs(distance); } IMAware mAware = pl as IMAware; mAware.MAware = true; IMSegmentation3 mSegmentation = unionedPolyline as IMSegmentation3; mSegmentation.SetMsAsDistance(false); IPoint ptTmp = new PointClass(); double distanceAlong = 0; double distanceFromCurve = 0; bool rightSide = false; pl.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, ptTmp, ref distanceAlong, ref distanceFromCurve, ref rightSide); object mStartArray = mSegmentation.GetMsAtDistance(distanceAlong, false); double[] mStart = mStartArray as double[]; double distanceDownStream = distanceAlong + distance; IPolyline resultPolyline = mSegmentation.GetSubcurveBetweenMs(mStart[0], distanceDownStream) as IPolyline; if (resultPolyline.IsEmpty) { return(point); } if (mSegmentation.MMax < distanceDownStream) { messageInfo = "The set distance exceeds the length of network"; } return(Helper.ConstructOffset(resultPolyline, offset)); }
//要素坐标转换 private void CoordConvertFeature(IFeature inFeature, ref IFeature outFeature) { try { IGeometry resultGeometry = inFeature.ShapeCopy; if (resultGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { PointCoordConvert(ref resultGeometry, m_A1, m_B1, m_C1, m_A2, m_B2, m_C2, m_A3, m_C3); } else { GeometryCoordConvert(ref resultGeometry, m_A1, m_B1, m_C1, m_A2, m_B2, m_C2, m_A3, m_C3); } IFields fields = inFeature.Fields; int shapeIndex = fields.FindField("SHAPE"); if (resultGeometry.GeometryType == esriGeometryType.esriGeometryPoint)//如果为点要素 { int GeoObjNumIndex = fields.FindField("GeoObjNum"); string GeoObjNumValue = inFeature.get_Value(GeoObjNumIndex).ToString(); if (GeoObjNumValue == "211101" || GeoObjNumValue == "238121" || GeoObjNumValue == "322131" || GeoObjNumValue == "322231" || GeoObjNumValue == "322311" || GeoObjNumValue == "322341" || GeoObjNumValue == "322351" || GeoObjNumValue == "323111" || GeoObjNumValue == "324101" || GeoObjNumValue == "381101" || GeoObjNumValue == "411211" || GeoObjNumValue == "411221" || GeoObjNumValue == "411231" || GeoObjNumValue == "411241" || GeoObjNumValue == "411311" || GeoObjNumValue == "427101" || GeoObjNumValue == "411321" || GeoObjNumValue == "427001" || GeoObjNumValue == "517511" || GeoObjNumValue == "517521" || GeoObjNumValue == "515101" || GeoObjNumValue == "516101" || GeoObjNumValue == "515201" || GeoObjNumValue == "515601" || GeoObjNumValue == "515701" || GeoObjNumValue == "525101" || GeoObjNumValue == "525201" || GeoObjNumValue == "525701" || GeoObjNumValue == "525201" || GeoObjNumValue == "535701" || GeoObjNumValue == "535801" || GeoObjNumValue == "535901" || GeoObjNumValue == "545511" || GeoObjNumValue == "545521" || GeoObjNumValue == "545601" || GeoObjNumValue == "545701" || GeoObjNumValue == "545801" || GeoObjNumValue == "545901" || GeoObjNumValue == "546001" || GeoObjNumValue == "555701" || GeoObjNumValue == "555801" || GeoObjNumValue == "555901" || GeoObjNumValue == "565701" || GeoObjNumValue == "565801" || GeoObjNumValue == "565901" || GeoObjNumValue == "571571" || GeoObjNumValue == "571581" || GeoObjNumValue == "571591" || GeoObjNumValue == "572571" || GeoObjNumValue == "572581" || GeoObjNumValue == "572591" || GeoObjNumValue == "573571" || GeoObjNumValue == "573581" || GeoObjNumValue == "573591" || GeoObjNumValue == "574571" || GeoObjNumValue == "574581" || GeoObjNumValue == "574591" || GeoObjNumValue == "574551" || GeoObjNumValue == "633101" || GeoObjNumValue == "641301" || GeoObjNumValue == "641401" || GeoObjNumValue == "671001") //枚举 有方向的符号 { int DirctionIndex = fields.FindField("DIRCTION"); //方向字段 double dblDirctionValue = Convert.ToDouble(inFeature.get_Value(DirctionIndex)); //方向字段的值 for (int i = 0; i < fields.FieldCount; i++) { if (fields.get_Field(i).Editable&& i != shapeIndex) //如果不为shape字段 { if (i != DirctionIndex) { outFeature.set_Value(i, inFeature.get_Value(i)); } else //方向字段 { outFeature.set_Value(i, Convert.ToDouble(inFeature.get_Value(i)) - (Math.Atan(m_A1 / m_A2) * 180 / Math.PI - 90)); } } } } else //无方向的符号 { SetOutFeatureValue(inFeature, shapeIndex, ref outFeature); //for (int i = 0; i < fields.FieldCount; i++) //{ // if (fields.get_Field(i).Editable && i != shapeIndex)//如果不为shape字段 // { // outFeature.set_Value(i, inFeature.get_Value(i)); // } //} } } else//线、面、注记要素 { SetOutFeatureValue(inFeature, shapeIndex, ref outFeature); //for (int i = 0; i < fields.FieldCount; i++) //{ // if (fields.get_Field(i).Editable && i != shapeIndex)//如果不为shape字段 // { // outFeature.set_Value(i, inFeature.get_Value(i)); // } //} } try { outFeature.Shape = resultGeometry; } catch { IGeometryDef pGD = fields.get_Field(shapeIndex).GeometryDef; if (pGD.HasZ) { IZAware pZA = (IZAware)resultGeometry; pZA.ZAware = true; } else { IZAware pZA = (IZAware)resultGeometry; pZA.ZAware = false; } if (pGD.HasM) { IMAware pMA = (IMAware)resultGeometry; pMA.MAware = true; } else { IMAware pMA = (IMAware)resultGeometry; pMA.MAware = false; } try { outFeature.Shape = resultGeometry; } catch { } } } catch { } }
/// <summary> /// 存储范围线 /// </summary> /// <param name="geo"></param> /// <param name="strRegionName"></param> /// <param name="fc"></param> private void SaveFanWei(IGeometry geo, string strRegionName, IFeatureClass fc) { try { int index1, index2, index3, index4; IFeature pFea; index1 = fc.FindField("REGIONNAME"); index2 = fc.FindField("SMSCODE"); index3 = fc.FindField("GEOOBJNUM"); index4 = fc.FindField("Mark"); //存储范围线 pFea = fc.CreateFeature(); pFea.set_Value(index1, strRegionName); pFea.set_Value(index2, "更新范围"); pFea.set_Value(index3, "194013"); pFea.set_Value(index4, "已导出,未导入更新"); int index = fc.FindField(fc.ShapeFieldName); IGeometryDef pGD = fc.Fields.get_Field(index).GeometryDef; if (pGD.HasZ) { IZAware pZA = geo as IZAware; pZA.ZAware = true; IZ pZ = geo as IZ; double zmin = -1000, zmax = 1000; if (pGD.SpatialReference.HasZPrecision()) { pGD.SpatialReference.GetZDomain(out zmin, out zmax); } if (pZ != null) { pZ.SetConstantZ(0); } else { IPoint p = geo as IPoint; if (p != null) { if (p.Z.ToString() == "非数字") { p.Z = 0; } } } } if (pGD.HasM) { IMAware pMA = geo as IMAware; pMA.MAware = true; } (geo as ITopologicalOperator).Simplify(); pFea.Shape = geo as IGeometry; pFea.Store(); } catch (System.Exception ex) { } }
public static IFeature CutOffPolylineByPoint(IFeatureClass featureClass, IFeature polylineFeature, IFeature pointFeature, string keyValue, string sKeyValue, string eKeyValue) { int idxKeyField = pointFeature.Fields.FindField(keyValue); int idxSKeyField = polylineFeature.Fields.FindField(sKeyValue); int idxEKeyField = polylineFeature.Fields.FindField(eKeyValue); if (idxKeyField == -1 || idxSKeyField == -1 || idxEKeyField == -1) { return(null); } bool hasZ = FeatureClassUtil.CheckHasZ(featureClass); bool hasM = FeatureClassUtil.CheckHasM(featureClass); IPoint point = pointFeature.Shape as IPoint; if (point == null) { return(null); } IPolyline polyline1 = polylineFeature.ShapeCopy as IPolyline; if (polyline1 == null) { return(null); } IPolyline firstPolyline = new PolylineClass { FromPoint = GeometryHelper.CreatePoint(polyline1.FromPoint.X, polyline1.FromPoint.Y, polyline1.FromPoint.Z, polyline1.FromPoint.M, hasZ, hasM), ToPoint = GeometryHelper.CreatePoint(point.X, point.Y, point.Z, point.M, hasZ, hasM) }; if (hasZ) { IZAware pZAware = firstPolyline as IZAware; pZAware.ZAware = true; } if (hasM) { IMAware pMAware = firstPolyline as IMAware; pMAware.MAware = true; } polylineFeature.Shape = firstPolyline; polylineFeature.Store(); IFeature secondFeature = featureClass.CreateFeature(); IPolyline secondPolyline = new PolylineClass { FromPoint = GeometryHelper.CreatePoint(point.X, point.Y, point.Z, point.M, hasZ, hasM), ToPoint = GeometryHelper.CreatePoint(polyline1.ToPoint.X, polyline1.ToPoint.Y, polyline1.ToPoint.Z, polyline1.ToPoint.M, hasZ, hasM), }; if (hasZ) { IZAware pZAware = secondPolyline as IZAware; pZAware.ZAware = true; } if (hasM) { IMAware pMAware = secondPolyline as IMAware; pMAware.MAware = true; } secondFeature.Shape = secondPolyline; IField pField; for (int i = 0; i < featureClass.Fields.FieldCount; i++) { pField = featureClass.Fields.Field[i]; if (pField.Type == esriFieldType.esriFieldTypeGeometry) { continue; } int idx = secondFeature.Fields.FindField(pField.Name); if (pField.Editable && idx != -1) { secondFeature.Value[idx] = polylineFeature.Value[idx]; } } secondFeature.Store(); polylineFeature.Value[idxEKeyField] = pointFeature.Value[idxKeyField]; polylineFeature.Store(); secondFeature.Value[idxSKeyField] = pointFeature.Value[idxKeyField]; secondFeature.Store(); return(secondFeature); }
public void CreateFeature(IGeometry igeometry_0) { try { if (igeometry_0 != null) { IFeatureLayer featureLayer = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer; IDataset dataset = (IDataset)featureLayer.FeatureClass; IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)dataset.Workspace; int index = featureLayer.FeatureClass.FindField(featureLayer.FeatureClass.ShapeFieldName); IGeometryDef geometryDef = featureLayer.FeatureClass.Fields.get_Field(index).GeometryDef; if (geometryDef.HasZ) { IZAware iZAware = (IZAware)igeometry_0; iZAware.ZAware = true; IZ iZ = (IZ)igeometry_0; double constantZ; double num; geometryDef.SpatialReference.GetZDomain(out constantZ, out num); iZ.SetConstantZ(constantZ); } if (geometryDef.HasM) { IMAware iMAware = (IMAware)igeometry_0; iMAware.MAware = true; } workspaceEdit.StartEditOperation(); IFeature feature = featureLayer.FeatureClass.CreateFeature(); if (igeometry_0 is ITopologicalOperator) { (igeometry_0 as ITopologicalOperator).Simplify(); } feature.Shape = igeometry_0; try { IRowSubtypes rowSubtypes = (IRowSubtypes)feature; rowSubtypes.InitDefaultValues(); } catch (Exception exception_) { CErrorLog.writeErrorLog(this, exception_, ""); } feature.Store(); workspaceEdit.StopEditOperation(); EditorEvent.AddFeature(featureLayer, feature); IActiveView activeView = (IActiveView)_context.FocusMap; _context.FocusMap.ClearSelection(); _context.FocusMap.SelectFeature(featureLayer, feature); if (igeometry_0.GeometryType == esriGeometryType.esriGeometryPoint) { double distance = Common.ConvertPixelsToMapUnits((IActiveView)_context.FocusMap, 30.0); ITopologicalOperator topologicalOperator = (ITopologicalOperator)igeometry_0; topologicalOperator.Buffer(distance); activeView.Refresh(); } else { activeView.Refresh(); } } } catch (COMException ex) { if (ex.ErrorCode == -2147220936) { System.Windows.Forms.MessageBox.Show("坐标值或量测值超出范围!", "创建要素", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand); } } }
//从点图层中收集所有点 public IPointCollection ReadPoint(IFeatureLayer pFeatureLayer) { IFeatureCursor pFeatureCursor = pFeatureLayer.Search(null, false); //获取数据库或者单个文件的第一个属性字段 IFeature pFeature = pFeatureCursor.NextFeature(); IField pField = null; if (pFeatureLayer.FeatureClass.Fields.FindField("FID") != -1) { pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("FID")); } else if (pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID") != -1) { pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID")); } //第一个属性字段名称 string FirstFieldName = pField.AliasName; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = FirstFieldName + ">=0"; int number = pFeatureLayer.FeatureClass.FeatureCount(pQueryFilter); //DataTable dt = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pFeatureLayer.FeatureClass as ITable, ""); //DataAlignment.DataAlignment.CanlculateDistanceInMiddlePointTable(dt); CustomizedControls.StatusForm frm = new CustomizedControls.StatusForm(); frm.StartPosition = FormStartPosition.CenterScreen; frm.Show(); IPointCollection pPointCollection = new MultipointClass(); IPoint PrevPT = null; try { for (int i = 0; i < number; i++) { Application.DoEvents(); frm.Status = "处理点 " + i.ToString() + "/ " + number.ToString(); IGeometry pGeometry = pFeature.Shape as IGeometry; IPoint pt = pGeometry as IPoint; IPoint pPoint = new PointClass(); IZAware zpt = pPoint as IZAware; zpt.ZAware = true; IMAware mpt = pPoint as IMAware; mpt.MAware = true; pPoint.PutCoords(pt.X, pt.Y); pPoint.Z = Convert.ToDouble(pFeature.Value[pFeature.Fields.FindField(EvConfig.CenterlineZField)]); if (i == 0) { pPoint.M = 0; PrevPT = pPoint; } else { pPoint.M = PrevPT.M + DataAlignment.DataAlignment.CalculateDistanceBetween84TwoPoints(pPoint, PrevPT); PrevPT = pPoint; } pPointCollection.AddPoint(pPoint); pFeature.Value[pFeature.Fields.FindField(EvConfig.CenterlineMeasureField)] = pPoint.M; pFeature.Store(); frm.Progress = Convert.ToInt16(Convert.ToDouble(i) / Convert.ToDouble(number) * 100); pFeature = pFeatureCursor.NextFeature(); } } catch (SystemException ex) { MessageBox.Show(ex.Message); } finally { frm.Close(); } return(pPointCollection); }
private void method_1(IFeatureClass ifeatureClass_0) { string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + this.string_0 + @"\" + this.string_1 + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=2'"; string cmdText = "SELECT * FROM [XYDATA$]"; DataSet dataSet = new DataSet(); dataSet.Tables.Add("XYDATA"); OleDbConnection connection = new OleDbConnection(connectionString); OleDbCommand selectCommand = new OleDbCommand(cmdText, connection); OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand); connection.Open(); try { adapter.Fill(dataSet, "XYDATA"); } finally { connection.Close(); } DataRowCollection rows = dataSet.Tables["XYDATA"].Rows; IDataset dataset = (IDataset)ifeatureClass_0; IWorkspaceEdit workspace = (IWorkspaceEdit)dataset.Workspace; workspace.StartEditing(true); int index = ifeatureClass_0.FindField(ifeatureClass_0.ShapeFieldName); IGeometryDef geometryDef = ifeatureClass_0.Fields.get_Field(index).GeometryDef; foreach (DataRow row in rows) { IPoint point = null; point = new PointClass { X = Convert.ToDouble(row[this.cboXField.Text].ToString()), Y = Convert.ToDouble(row[this.cboYField.Text].ToString()) }; if (this.cboZField.SelectedIndex > 0) { point.Z = Convert.ToDouble(row[this.cboZField.Text].ToString()); } if (geometryDef.HasZ) { IZAware aware = (IZAware)point; aware.ZAware = true; } if (geometryDef.HasM) { IMAware aware2 = (IMAware)point; aware2.MAware = true; } try { ITable table = (ITable)ifeatureClass_0; IRowBuffer buffer = table.CreateRowBuffer(); int num2 = buffer.Fields.FindField("SHAPE"); buffer.set_Value(num2, point); for (int i = 0; i < row.Table.Columns.Count; i++) { string name = row.Table.Columns[i].ToString(); if (name.ToLower() == "as") { name = name + "_"; } num2 = buffer.Fields.FindField(name); buffer.set_Value(num2, row[i].ToString()); } table.Insert(true).InsertRow(buffer); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } } workspace.StopEditing(true); }
public IGeometry CreateSphere(IPoint centerPoint, double radius, double minLon = 0.0, double maxLon = 360.0, double minLat = -90.0, double maxLat = 90.0, double stepAngle = 18.0, bool bSmooth = false, bool bFlipS = false, bool bFlipT = false) { IMultiPatch patch = new MultiPatchClass(); IGeometryCollection pGCol = patch as IGeometryCollection; IGeometry2 pGeom; IPoint pt; IPointCollection pStrip; IVector3D pVector = new Vector3DClass(); IEncode3DProperties pGE = new GeometryEnvironmentClass(); double xStep = (maxLon - minLon) / stepAngle; double yStep = (maxLat - minLat) / (stepAngle / 2.0); double lonRange = maxLon - minLon; double latRange = maxLat - minLat; object missing = Type.Missing; double lon = minLon; while (lon < maxLon) { pStrip = new TriangleStripClass(); double lat = minLat; while (lat < maxLat) { double azi = DegreesToRadians(lon); double inc = DegreesToRadians(lat); pVector.PolarSet(-azi, inc, radius); pt = new PointClass(); pt.X = centerPoint.X + pVector.XComponent; pt.Y = centerPoint.Y + pVector.YComponent; pt.Z = centerPoint.Z + pVector.ZComponent; double s = (lon - minLon) / lonRange; if (bFlipS) { s = 1 + (s * -1); } if (s <= 0) { s = 0.001; } else if (s >= 1) { s = 0.999; } double t = (maxLat - lat) / latRange; if (bFlipT) { t = 1 + (t * -1); } if (t <= 0) { t = 0.001; } else if (t >= 1) { t = 0.999; } double m = 0.0; pGE.PackTexture2D(s, t, out m); if (bSmooth) { pVector.Normalize(); pGE.PackNormal(pVector, out m); } pt.M = m; pStrip.AddPoint(pt, ref missing, ref missing); if ((lat != -90) && (lat != 90)) { azi = (lon + xStep) * Math.PI / 180.00; inc = lat * Math.PI / 180.00; pVector.PolarSet(-azi, inc, radius); pt = new PointClass(); pt.X = centerPoint.X + pVector.XComponent; pt.Y = centerPoint.Y + pVector.YComponent; pt.Z = centerPoint.Z + pVector.ZComponent; s = (lon + xStep - minLon) / lonRange; if (bFlipS) { s = 1 + (s * -1); } if (s <= 0) { s = 0.001; } else if (s >= 1) { s = 0.999; } t = (maxLat - lat) / latRange; if (bFlipT) { t = 1 + (t * -1); } if (t <= 0) { t = 0.001; } else if (t >= 1) { t = 0.999; } m = 0.0; pGE.PackTexture2D(s, t, out m); if (bSmooth) { pVector.Normalize(); pGE.PackNormal(pVector, out m); } pt.M = m; pStrip.AddPoint(pt, ref missing, ref missing); } lat = lat + yStep; } pGeom = pStrip as IGeometry2; pGCol.AddGeometry(pGeom, ref missing, ref missing); lon = lon + xStep; } IMAware pMAware = patch as IMAware; pMAware.MAware = true; return(patch); }
//从点图层中收集所有点 public IPointCollection ReadPoint(IFeatureLayer pFeatureLayer) { IFeatureCursor pFeatureCursor = pFeatureLayer.Search(null, false); //获取数据库或者单个文件的第一个属性字段 IFeature pFeature = pFeatureCursor.NextFeature(); IField pField = null; if (pFeatureLayer.FeatureClass.Fields.FindField("FID") != -1) { pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("FID")); } else if (pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID") != -1) { pField = pFeatureLayer.FeatureClass.Fields.get_Field(pFeatureLayer.FeatureClass.Fields.FindField("OBJECTID")); } //第一个属性字段名称 string FirstFieldName = pField.AliasName; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = FirstFieldName + ">=0"; int number = pFeatureLayer.FeatureClass.FeatureCount(pQueryFilter); //DataTable dt = AOFunctions.GDB.ITableUtil.GetDataTableFromITable(pFeatureLayer.FeatureClass as ITable, ""); //DataAlignment.DataAlignment.CanlculateDistanceInMiddlePointTable(dt); IPointCollection pPointCollection = new MultipointClass(); IPoint PrevPT = null; for (int i = 0; i < number; i++) { IGeometry pGeometry = pFeature.Shape as IGeometry; IPoint pt = pGeometry as IPoint; IPoint pPoint = new PointClass(); IZAware zpt = pPoint as IZAware; zpt.ZAware = true; IMAware mpt = pPoint as IMAware; mpt.MAware = true; pPoint.PutCoords(pt.X, pt.Y); pPoint.Z = Convert.ToDouble(pFeature.Value[pFeature.Fields.FindField(EvConfig.CenterlineZField)]); if (i == 0) { pPoint.M = 0; PrevPT = pPoint; } else { pPoint.M = PrevPT.M + DataAlignment.DataAlignment.CalculateDistanceBetween84TwoPoints(pPoint, PrevPT); PrevPT = pPoint; } pPointCollection.AddPoint(pPoint); pFeature = pFeatureCursor.NextFeature(); } return(pPointCollection); }