/// <summary> /// 创建要素 /// </summary> /// <param name="pGeometry"></param> private void CreateFeature(IGeometry pGeometry) { try { if (m_EngineEditLayers == null) { return; } IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) { return; } IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) { return; } if (m_EngineEditor == null) { return; } if (pGeometry == null) { return; } ITopologicalOperator pTop = pGeometry as ITopologicalOperator; pTop.Simplify(); IGeoDataset pGeoDataset = pFeatCls as IGeoDataset; if (pGeoDataset.SpatialReference != null) { pGeometry.Project(pGeoDataset.SpatialReference); } m_EngineEditor.StartOperation(); IFeature pFeature = null; pFeature = pFeatCls.CreateFeature(); IZAware ipZAware = pGeometry as IZAware; if (ipZAware.ZAware == true) { ipZAware.ZAware = false; } if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { pFeature.Shape = pGeometry; } else { pFeature.Shape = SupportZMFeatureClass.ModifyGeomtryZMValue(pFeatCls, pGeometry); } pFeature.Store(); m_EngineEditor.StopOperation("添加要素"); m_Map.SelectFeature(pFeatLyr, pFeature); m_activeView.Refresh(); } catch (Exception ex) { //SysLogHelper.WriteOperationLog("要素添加错误", ex.Source, "数据编辑"); } }
//function for generating camera to target direction public void cameraToTargetDirection(double camLat, double camLong, double camAlt, double tarLat, double tarLong, double tarAlt) { IPoint camPosition = new PointClass(); IPoint targetPosition = new PointClass(); ICamera pCamera = (ICamera)globeCamera; IZAware obsZAware = (IZAware)camPosition; obsZAware.ZAware = true; camPosition.PutCoords(camLong, camLat); camPosition.Z = camAlt * 1000; IZAware targetZAware = (IZAware)targetPosition; targetZAware.ZAware = true; targetPosition.PutCoords(tarLong, tarLat); targetPosition.Z = tarAlt; IPolyline directionLine = new PolylineClass(); IZAware zAwareLine = (IZAware)directionLine; zAwareLine.ZAware = true; directionLine.FromPoint = camPosition; directionLine.ToPoint = targetPosition; addLineGraphicElements(directionLine, 255); }
//---------------------------------------------------------------------------------- public static IPolyline MaakPolyline() { //Declaraties en initialisaties IPolyline pPolyline = new PolylineClass(); IGeometryCollection pGCol = (IGeometryCollection)pPolyline; IZAware pZAware = (IZAware)pPolyline; pZAware.ZAware = ImportInArcscene.ZBoolean; int aantalpaths = ImportInArcscene.binReader.ReadInt32(); for (int i = 1; i <= aantalpaths; i++) { IPath pPath = new PathClass(); IPointCollection pPointCol = (IPointCollection)pPath; int aantalvertices = ImportInArcscene.binReader.ReadInt32(); for (int k = 1; k <= aantalvertices; k++) { double ptx = ImportInArcscene.binReader.ReadSingle(); double pty = ImportInArcscene.binReader.ReadSingle(); double ptz = ImportInArcscene.binReader.ReadSingle(); pPointCol.AddPoint(PuntTransformatie(ptx, pty, ptz), ref _missing, ref _missing); } pGCol.AddGeometry(pPath, ref _missing, ref _missing); } return(pPolyline); }
/// <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 void AddShapeToTin() { object Missing = Type.Missing; IPointCollection ptc = pGeometry as IPointCollection; if (ptc == null) { return; } //for (int i = 0; i < ptc.PointCount; i++) //{ // IPoint pt = ptc.get_Point(i); // IZAware pza = pt as IZAware; // pza.ZAware = true; // pt.Z = dHeight; //} IZAware pza = pGeometry as IZAware; pza.ZAware = true; IZ pz = pGeometry as IZ; pz.SetConstantZ(dHeight); try { pTinEdit.AddShapeZ(pGeometry, esriTinSurfaceType.esriTinHardReplace, 0, ref Missing); } catch (SystemException e) { } if (pMapCtr != null) { pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } }
/// <summary> /// 去掉图形中的Z值(高程值) /// </summary> /// <param name="geometry"></param> public static void DropZs(this IGeometry geometry) { IZAware pZaware = geometry as IZAware; pZaware.DropZs(); pZaware.ZAware = false; }
/// <summary> /// 三维场景中绘制面要素 20110609 /// </summary> /// <param name="pGeometry">面要素</param> /// <param name="r"></param> /// <param name="g"></param> /// <param name="b"></param> /// <param name="Z"></param> /// <param name="Width"></param> /// <returns></returns> public static IElement DrawPolygonZ(IGeometry pGeometry, int r, int g, int b, int Z, double Width) { IPolygon pEnvPolygon = (IPolygon)pGeometry; IZAware pZAware = (IZAware)pEnvPolygon; ((IZAware)pZAware).ZAware = true; IZ pZ = (IZ)pEnvPolygon; pZ.SetConstantZ(Z); IElement pElement; IPolygonElement pPolygonElement = new PolygonElementClass(); pElement = pPolygonElement as IElement; IFillShapeElement pFillShapeElement = pPolygonElement as IFillShapeElement; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; pSimpleFillSymbol.Color = getRGB(r, g, b); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; pSimpleLineSymbol.Color = getRGB(r, g, b); pSimpleLineSymbol.Color.Transparency = 10; pSimpleLineSymbol.Width = Width; ISymbol pSymbol = pSimpleLineSymbol as ISymbol; pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; pSimpleFillSymbol.Outline = pSimpleLineSymbol; pElement.Geometry = pZ as IGeometry; pFillShapeElement.Symbol = pSimpleFillSymbol; return(pElement); }
public IGeometry CreateGeometry(double radius, IPolyline polyline, double qdgc, double zdgc) { IPointCollection pointCollection = CreatePointCollectionForCircle(radius); IVector3D pVectorZ = new Vector3DClass(); pVectorZ.SetComponents(0, 0, 1); IConstructMultiPatch patch = new MultiPatchClass(); IZAware zAware = pointCollection as IZAware; if (zAware == null) { return(null); } zAware.ZAware = true; // 依据管线长度拉伸 patch.ConstructExtrude(polyline.Length, pointCollection as IGeometry); // 依据管线角度旋转 IVector3D pVector3D = new Vector3DClass(); pVector3D.SetComponents(polyline.ToPoint.X - polyline.FromPoint.X, polyline.ToPoint.Y - polyline.FromPoint.Y, zdgc - qdgc); double rotateAngle = Math.Acos(pVector3D.ZComponent / pVector3D.Magnitude); IVector3D vectorAxis = pVectorZ.CrossProduct(pVector3D) as IVector3D; ITransform3D transform3D = patch as ITransform3D; transform3D.RotateVector3D(vectorAxis, rotateAngle); // 平移到指定位置 transform3D.Move3D(polyline.FromPoint.X, polyline.FromPoint.Y, qdgc); return(patch as IGeometry); }
//step.3 遍历待复制的要素类,复制图形和属性并改变图形的坐标系 /// <summary> /// 遍历待复制的要素类,复制图形和属性并改变图形的坐标系 /// </summary> /// <param name="fromFeatureClass">待复制的要素类</param> /// <param name="toFeatureClass">目标要素类</param> private void featureClassTransSpatialRef(IFeatureClass fromFeatureClass, IFeatureClass toFeatureClass) { IFeature pFeature; IGeometry2 pGeometry; IFeatureCursor toCursor = toFeatureClass.Insert(true); int FeatureCount = fromFeatureClass.FeatureCount(null); for (int i = 0; i < FeatureCount; i++) { pFeature = fromFeatureClass.GetFeature(i); pGeometry = pFeature.Shape as IGeometry2; IZAware pZAware = pGeometry as IZAware; pZAware.ZAware = true; pGeometry.ProjectEx(spatialRefTo, esriTransformDirection.esriTransformForward, geoTransformation, false, 0, 0); IFeatureBuffer pFeaBuffer = toFeatureClass.CreateFeatureBuffer(); pFeaBuffer.Shape = pGeometry; for (int j = 2; j < fromFeatureClass.Fields.FieldCount; j++) { try { pFeaBuffer.set_Value(j, pFeature.Value[fromFeatureClass.FindField(toFeatureClass.Fields.Field[j].Name)]); } catch { continue; } } toCursor.InsertFeature(pFeaBuffer); toCursor.Flush(); } }
/// <summary> /// 更新半径 /// </summary> /// <param name="radius"></param> public void UpdatePosition(double radius) { this.radius = radius; IZAware zAware = (IGeometry)centerPoint as IZAware; zAware.ZAware = true; upperAxisVector3D = new Vector3DClass(); upperAxisVector3D.SetComponents(0, 0, 10); lowerAxisVector3D = new Vector3DClass(); lowerAxisVector3D.SetComponents(0, 0, -10); lowerAxisVector3D.XComponent -= vectorComponentOffset; normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D; normalVector3D.Magnitude = this.radius; double rotationAngleInRadians = 2 * (Math.PI / 180); geometryCollection = new MultiPatchClass(); pointCollection.RemovePoints(0, pointCollection.PointCount); for (int i = 0; i < 180; i++) { normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D); IPoint vertexPoint = new PointClass(); vertexPoint.X = centerPoint.X + normalVector3D.XComponent; vertexPoint.Y = centerPoint.Y + normalVector3D.YComponent; vertexPoint.Z = centerPoint.Z; pointCollection.AddPoint(vertexPoint, missing, missing); } base.Geometry = pointCollection as IGeometry; this.Update(); }
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; } }
public void DisplaySymbol() { IGraphicsLayer layer; if (this.axSceneControl1.SceneGraph.Scene.LayerCount == 0) { layer = new GraphicsLayer3DClass(); this.axSceneControl1.SceneGraph.Scene.AddLayer(layer as ILayer, false); } else { layer = this.axSceneControl1.SceneGraph.Scene.get_Layer(0) as IGraphicsLayer; } IGraphicsContainer3D containerd = layer as IGraphicsContainer3D; containerd.DeleteAllElements(); if (this.m_pCharacterMarker3DSymbol != null) { IPoint point = new PointClass(); IZAware aware = point as IZAware; aware.ZAware = true; point.X = 0.0; point.Y = 0.0; point.Z = 0.0; IElement element = new MarkerElementClass(); IMarkerElement element2 = element as IMarkerElement; element2.Symbol = this.m_pCharacterMarker3DSymbol; element.Geometry = point; containerd.AddElement(element); } this.axSceneControl1.SceneGraph.RefreshViewers(); }
public static IPolygon GetVisilityPolygon(IPointCollection points) { IGeometryBridge2 geometryBridge2 = new GeometryEnvironmentClass(); IPointCollection4 pointCollection4 = new PolygonClass(); WKSPointZ[] aWKSPoints = new WKSPointZ[points.PointCount]; for (int i = 0; i < aWKSPoints.Length; i++) { aWKSPoints[i] = PointToWKSPoint(points.Point[i]); } geometryBridge2.SetWKSPointZs(pointCollection4, ref aWKSPoints); var geometry = pointCollection4 as IGeometry; IZAware zAware = geometry as IZAware; zAware.ZAware = true; var result = pointCollection4 as IPolygon; result.SpatialReference = points.Point[0].SpatialReference; return(result); }
static public double CalculateDistanceBetween84TwoPoints(IPoint pt1, IPoint pt2) { ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatialReferenceFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass(); //wgs 84 IGeographicCoordinateSystem wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326) as IGeographicCoordinateSystem; IUnit meterUnit = spatialReferenceFactory.CreateUnit((int)ESRI.ArcGIS.Geometry.esriSRUnitType.esriSRUnit_Meter); ISpatialReference pSR = wgs84 as ISpatialReference; IGeometryServer2 pGS = new GeometryServerClass(); double dis = pGS.GetDistanceGeodesic(wgs84, pt1, pt2, (ILinearUnit)meterUnit); IZAware z1 = pt1 as IZAware; IZAware z2 = pt2 as IZAware; if (double.IsNaN(pt1.Z) == false && double.IsNaN(pt2.Z) == false) { double deltaZ = Math.Abs(pt1.Z - pt2.Z); System.Runtime.InteropServices.Marshal.ReleaseComObject(pGS); System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory); return(Math.Sqrt(dis * dis + deltaZ * deltaZ)); } else { System.Runtime.InteropServices.Marshal.ReleaseComObject(pGS); System.Runtime.InteropServices.Marshal.ReleaseComObject(spatialReferenceFactory); return(dis); } }
public override IGeometry CreateGeometry() { IPointCollection pointCollection = new PolygonClass(); IZAware zAware = pointCollection as IZAware; zAware.ZAware = true; double angle = 2 * Math.PI / _division; for (int i = 0; i < _division; i++) { IPoint point = new PointClass(); point.X = _diameter * Math.Cos(angle * i) / 2; point.Y = _diameter * Math.Sin(angle * i) / 2; point.Z = 0; pointCollection.AddPoint(point); } ((IPolygon)pointCollection).Close(); IConstructMultiPatch patch = new MultiPatchClass(); patch.ConstructExtrude(0 - _depth, pointCollection as IGeometry); ITransform3D transform3D = patch as ITransform3D; transform3D.Move3D(_x, _y, _z); return(patch as IGeometry); }
//将收集到的点转换成线 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); }
// public static void Cardinal_P1234(IPoint pk_1, IPoint pk, IPoint pk1, IPoint pk2, int Sum, ref IArray pArray) { //pArray.RemoveAll(); double xk_1 = pk_1.X; double yk_1 = pk_1.Y; double zk_1 = pk_1.Z; double xk = pk.X; double yk = pk.Y; double zk = pk.Z; double xk1 = pk1.X; double yk1 = pk1.Y; double zk1 = pk1.Z; double xk2 = pk2.X; double yk2 = pk2.Y; double zk2 = pk2.Z; // double u = 0; double t = 0; double CAR0 = 0; double CAR1 = 0; double CAR2 = 0; double CAR3 = 0; // double s = (1 - t)/2; for (t = 0; t <= 1; t = t + 1.0 / Sum) { // double CAR0 = 2*s * Math.Pow(u,2) - s * Math.Pow(u,3) - s*u; // double CAR1 = (2 - s) * Math.Pow(u,3) + (s - 3) * Math.Pow(u,2) + 1; // double CAR2 = (s - 2) * Math.Pow(u,3) + (3 - 2*s) * Math.Pow(u,2) + s*u; // double CAR3 = s * Math.Pow(u,3) - s * Math.Pow(u,2); CAR0 = (3 * Math.Pow(t, 2) - Math.Pow(t, 3) - 3 * t + 1) / 6; CAR1 = (3 * Math.Pow(t, 3) - 6 * Math.Pow(t, 2) + 4) / 6; CAR2 = (3 * Math.Pow(t, 2) - 3 * Math.Pow(t, 3) + 3 * t + 1) / 6; CAR0 = Math.Pow(t, 3) / 6; double x = xk_1 * CAR0 + xk * CAR1 + xk1 * CAR2 + xk2 * CAR3; double y = yk_1 * CAR0 + yk * CAR1 + yk1 * CAR2 + yk2 * CAR3; double z = zk_1 * CAR0 + zk * CAR1 + zk1 * CAR2 + zk2 * CAR3; IPoint p = new PointClass(); IZAware pZA = (IZAware)p; pZA.ZAware = true; p.X = x; p.Y = y; p.Z = z; pArray.Add(p); } }
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 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; } }
private void CopyFeatureClassData(IFeatureClass sourceFeatureClass, IFeatureClass targetFeatureClass, IDictionary <int, int> filedIndexDictionary) { errorRowCount = 0; using (var comReleaser = new ComReleaser()) { IFeatureCursor sourceFeatureCursor = sourceFeatureClass.Search(null, false); IFeatureCursor targetFeatureCursor = targetFeatureClass.Insert(true); comReleaser.ManageLifetime(sourceFeatureCursor); comReleaser.ManageLifetime(targetFeatureCursor); List <int> targeFieldIndexs = filedIndexDictionary.Keys.ToList(); int fieldsLen = targeFieldIndexs.Count; IFeature sourceFeature = sourceFeatureCursor.NextFeature(); var count = 0; while (sourceFeature != null) { try { //错误:Geometry cannot have Z values 处理 IGeometry geometry = sourceFeature.ShapeCopy; IZAware zAware = geometry as IZAware; if (zAware != null && zAware.ZAware == true) { zAware.ZAware = false; } IFeatureBuffer targetFatureBuffer = targetFeatureClass.CreateFeatureBuffer(); targetFatureBuffer.Shape = geometry;//sourceFeature.ShapeCopy; for (int i = 0; i < fieldsLen; i++) { var targetIndex = targeFieldIndexs[i]; int sourceIndex = filedIndexDictionary[targeFieldIndexs[i]]; var value = sourceFeature.get_Value(sourceIndex); targetFatureBuffer.set_Value(targetIndex, value); } targetFeatureCursor.InsertFeature(targetFatureBuffer); count++; if (count == 1000) { targetFeatureCursor.Flush(); count = 0; } } catch (Exception ex) { errorRowCount++; var message = "字段赋值错误"; //LoggingManager.GetLogger(GetType()).Error(message, ex); } sourceFeature = sourceFeatureCursor.NextFeature(); } targetFeatureCursor.Flush(); } }
public void OnDblClick() { IGeometry pResultGeometry = null; if (m_EngineEditLayers == null) { return; } //获取编辑目标图层 IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) { return; } IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) { return; } switch (pFeatCls.ShapeType) { case esriGeometryType.esriGeometryPoint: m_newMultPtFeedBack.Stop(); pResultGeometry = m_pointCollection as IGeometry; m_newMultPtFeedBack = null; break; case esriGeometryType.esriGeometryPolyline: IPolyline pPolyline = null; pPolyline = m_newLineFeedBack.Stop(); pResultGeometry = pPolyline as IGeometry; m_newLineFeedBack = null; break; case esriGeometryType.esriGeometryPolygon: IPolygon pPolygon = null; pPolygon = m_newPolyFeedBack.Stop(); pResultGeometry = pPolygon as IGeometry; m_newPolyFeedBack = null; break; } IZAware pZAware = pResultGeometry as IZAware; if (pZAware == null) { return; } pZAware.ZAware = true; //创建新要素 CreateFeature(pResultGeometry); }
public static void PointAddZ(IPoint point, double value) { IZAware pZAware = point as IZAware; if (pZAware == null) { return; } pZAware.ZAware = true; point.Z = value; }
private void EditMouseMove(IPoint pPnt) { if (m_editDispFeed != null) { m_mousePointer = esriControlsMousePointer.esriPointerSizeWE; IZAware pIZAware = null; pIZAware = pPnt as IZAware; pIZAware.ZAware = true; pPnt.Z = 0; m_editDispFeed.MoveTo(pPnt); } }
public IPoint GetMultiPatchCenter(IMultiPatch pMultiPatch) { IPoint pt = new PointClass(); pt.PutCoords((pMultiPatch.Envelope.XMax + pMultiPatch.Envelope.XMin) / 2, (pMultiPatch.Envelope.YMax + pMultiPatch.Envelope.YMin) / 2); IZAware za = pt as IZAware; za.ZAware = true; pt.Z = (pMultiPatch.Envelope.ZMax + pMultiPatch.Envelope.ZMin) / 2; return(pt); }
public override IGeometry CreateGeometry() { IPointCollection pointCollection = new PolygonClass(); IZAware zAware = pointCollection as IZAware; zAware.ZAware = true; IPoint point = new PointClass(); point.X = -_width / 2; point.Y = -_height / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = -_width / 2; point.Y = _height / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = _width / 2; point.Y = _height / 2; point.Z = 0; pointCollection.AddPoint(point); point = new PointClass(); point.X = _width / 2; point.Y = -_height / 2; point.Z = 0; pointCollection.AddPoint(point); ((IPolygon)pointCollection).Close(); IConstructMultiPatch patch = new MultiPatchClass(); patch.ConstructExtrude(_polyline.Length, pointCollection as IGeometry); IVector3D vectorZ = new Vector3DClass(); vectorZ.SetComponents(0, 0, 1); IVector3D vector3D = new Vector3DClass(); vector3D.SetComponents(_polyline.ToPoint.X - _polyline.FromPoint.X, _polyline.ToPoint.Y - _polyline.FromPoint.Y, _zdgc - _qdgc); double rotateAngle = Math.Acos(vector3D.ZComponent / vector3D.Magnitude); IVector3D vectorAxis = vectorZ.CrossProduct(vector3D) as IVector3D; ITransform3D transform3D = patch as ITransform3D; transform3D.RotateVector3D(vectorAxis, rotateAngle); transform3D.Move3D(_polyline.FromPoint.X, _polyline.FromPoint.Y, _qdgc); return(patch as IGeometry); }
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); }
/// <summary> /// 显示参考面 张琪 20110629 /// </summary> /// <param name="pPoly">参考多边形</param> private void ShowRefPlane(IPolygon pPoly) { SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条"); try { IGeometry pBoundary = new PolylineClass(); pBoundary = null; IGeometry pPolygon = new PolygonClass(); pPolygon = null; object StepSize = Type.Missing; m_SurFace.InterpolateShape(pPoly as IGeometry, out pPolygon, ref StepSize); Cls3DMarkDraw.DeleteAllElementsWithName(m_pCurrentSceneControl.Scene, sRefPlaneName); //清除已有的参考面 if (!chkShowLWRP.Checked) //当为false时不显示参考面 { m_pCurrentSceneControl.SceneGraph.RefreshViewers(); return; } vProgress.EnableCancel = false;//设置进度条 vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); vProgress.SetProgress("正在绘制参考面"); ITopologicalOperator pTopo = pPolygon as ITopologicalOperator; pBoundary = pTopo.Boundary as IPolyline; //设置Z值方向显示 IZAware pZAware = pBoundary as IZAware; pZAware.ZAware = true; m_SurFace.InterpolateShape(pBoundary as IGeometry, out pBoundary, ref StepSize); m_SurFace.InterpolateShape(pPoly as IGeometry, out pPolygon, ref StepSize); IExtrude pExtrude = new GeometryEnvironmentClass(); //获取参考面的多面体 IMultiPatch pMultiPatchRefPlaneWall = pExtrude.ExtrudeAbsolute(Convert.ToDouble(txtPlaneHeight.Text), pBoundary as IGeometry) as IMultiPatch; pMultiPatchRefPlaneWall.SpatialReference = m_pCurrentSceneControl.Scene.SpatialReference; IZ pZ; pZAware = pPolygon as IZAware; pZAware.ZAware = true; pZ = pPolygon as IZ; pZ.SetConstantZ(Convert.ToDouble(txtPlaneHeight.Text)); //用于绘制三维效果 IGroupElement pGroup = null; Cls3DMarkDraw.AddSimpleGraphic(pMultiPatchRefPlaneWall as IGeometry, Cls3DMarkDraw.getRGB(71, 61, 255), 1, sRefPlaneName, m_pCurrentSceneControl.Scene, pGroup); Cls3DMarkDraw.AddSimpleGraphic(pPolygon as IGeometry, Cls3DMarkDraw.getRGB(71, 61, 255), 1, sRefPlaneName, m_pCurrentSceneControl.Scene, pGroup); m_pCurrentSceneControl.SceneGraph.RefreshViewers(); vProgress.Close(); } catch { vProgress.Close(); } }
public static IPoint GetObserverPoint(IPoint firstPoint, double observerHeight, ISpatialReference spatialReference) { ProjectToMapSpatialReference(firstPoint, spatialReference); var point = new Point() { X = firstPoint.X, Y = firstPoint.Y, Z = firstPoint.Z + observerHeight, SpatialReference = spatialReference } as IPoint; var geometry = point as IGeometry; IZAware zAware = geometry as IZAware; zAware.ZAware = true; return(point); }
/// <summary> /// 更新数据 /// </summary> /// <param name="lyr">图层</param> /// <param name="fea">要素对象</param> /// <param name="attributes">属性集合</param> /// <param name="pGeo">空间对象</param> /// <returns>成功失败标志</returns> public bool UpdateFeature(IFeatureLayer lyr, IFeature fea, Dictionary <string, string> attributes, IGeometry pGeo) { bool bres = false; try { IFeatureClass Featureclass = lyr.FeatureClass; IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace; workspace.StartEditing(false); workspace.StartEditOperation(); int index = Featureclass.Fields.FindField(GIS_Const.FIELD_SHAPE); IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef; if (geometryDef.HasZ) { IZAware pZAware = (IZAware)pGeo; pZAware.ZAware = true; fea.Shape = pGeo; foreach (string key in attributes.Keys) { int findex = fea.Fields.FindField(key); if (findex != -1) { fea.set_Value(findex, attributes[key]); } } fea.Store(); } else { fea.Shape = pGeo; foreach (string key in attributes.Keys) { int findex = fea.Fields.FindField(key); if (findex != -1) { fea.set_Value(findex, attributes[key]); } } fea.Store(); } workspace.StopEditOperation(); workspace.StopEditing(true); bres = true; } catch (Exception ei) { Log.Debug("[GIS] Update Feature: " + ei.ToString()); } return(bres); }
private IPoint ComputeCenterPointFromRadius(IPolyline ThePolyline, double NewRadius, bool IsMinorCurve) { IConstructCircularArc pCircArcConst = new CircularArc() as IConstructCircularArc; pCircArcConst.ConstructEndPointsRadius(ThePolyline.FromPoint, ThePolyline.ToPoint, (NewRadius < 0), Math.Abs(NewRadius), IsMinorCurve); ICircularArc pCircArc = pCircArcConst as ICircularArc; IPoint pCtrPoint = pCircArc.CenterPoint; IZAware pZAw = pCtrPoint as IZAware; pZAw.ZAware = true; pCtrPoint.Z = 0; return(pCtrPoint); }