private void cBoxScale_SelectedIndexChanged(object sender, EventArgs e) { if (pPt == null) { return; } Scale = (cBoxScale.Text.Contains(":"))?Convert.ToInt32(cBoxScale.Text.Split(':')[1]):0; if (Scale > 2000) { WKSPoint pPoint = new WKSPoint(); pPoint.X = pPt.X; pPoint.Y = pPt.Y; if (pAxMapControl.Map.SpatialReference is IProjectedCoordinateSystem) { (pAxMapControl.SpatialReference as IProjectedCoordinateSystem).Inverse(1, ref pPoint);//求点投影的经纬度坐标 } GeoDrawSheetMap.basPageLayout.GetNewCodeFromCoordinate(ref MapNo, (long)(pPoint.X * 3600), (long)(pPoint.Y * 3600), Convert.ToInt32(cBoxScale.Text.Split(':')[1])); MapNo = MapNo.Insert(3, " ");//H50 G 054071 MapNo = MapNo.Insert(5, " "); txtMapNo.Text = MapNo; } if (Scale > 400 && Scale <= 2000) { txtMapNo.Text = getMapNOforBigScale(Scale, pPt); } }
/// <summary> /// Create a Polyline from two Points /// </summary> /// <param name="pointFrom">Start point</param> /// <param name="pointTo">End point</param> /// <returns>Esri poliline</returns> public static IPolyline CreatePolylineFromPoints(IPoint pointFrom, IPoint pointTo) { if (pointFrom == null || pointTo == null) { return(null); } WKSPoint[] segmentWksPoints = new WKSPoint[2]; segmentWksPoints[0].X = pointFrom.X; segmentWksPoints[0].Y = pointFrom.Y; segmentWksPoints[1].X = pointTo.X; segmentWksPoints[1].Y = pointTo.Y; IPointCollection4 trackLine = new PolylineClass(); IGeometryBridge2 m_geometryBridge = new GeometryEnvironmentClass(); m_geometryBridge.AddWKSPoints(trackLine, ref segmentWksPoints); var result = trackLine as IPolyline; if (pointFrom.SpatialReference != null && pointTo.SpatialReference != null && pointFrom.SpatialReference == pointTo.SpatialReference) { result.SpatialReference = pointFrom.SpatialReference; } return(result); }
private void pAxMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { pPt = new ESRI.ArcGIS.Geometry.PointClass(); pPt.PutCoords(e.mapX, e.mapY); Scale = Convert.ToInt32(cBoxScale.Text.Split(':')[1]); if (Scale > 2000) { WKSPoint pPoint = new WKSPoint(); pPoint.X = e.mapX; pPoint.Y = e.mapY; if (pAxMapControl.MapUnits == esriUnits.esriMeters) { (pAxMapControl.SpatialReference as IProjectedCoordinateSystem).Inverse(1, ref pPoint);//求点投影的经纬度坐标 } GeoDrawSheetMap.basPageLayout.GetNewCodeFromCoordinate(ref MapNo, (long)(pPoint.X * 3600), (long)(pPoint.Y * 3600), Convert.ToInt32(cBoxScale.Text.Split(':')[1])); MapNo = MapNo.Insert(3, " ");//H50 G 054071 MapNo = MapNo.Insert(5, " "); txtMapNo.Text = MapNo; this.Show(pMainForm); } else { txtMapNo.Text = getMapNOforBigScale(Scale, pPt); this.Show(pMainForm); } }
public IPolygon BoundingPolygon(IList <IPoint> pList, ISpatialReference spatialrefrence) { try { IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2; IPointCollection4 pPointColl = (IPointCollection4) new Multipoint(); // edited here int numPoints = pList.Count; WKSPoint[] aWKSPointBuffer = new WKSPoint[numPoints]; for (int i = 0; i < pList.Count; i++) { WKSPoint A = new WKSPoint(); A.X = pList[i].X; A.Y = pList[i].Y; aWKSPointBuffer[i] = A; } pGeoBrg.SetWKSPoints(pPointColl, ref aWKSPointBuffer); // edits here IGeometry pGeom = (IMultipoint)pPointColl; pGeom.SpatialReference = spatialrefrence; ITopologicalOperator pTopOp = (ITopologicalOperator)pGeom; IPolygon pPointColl2 = (IPolygon)pTopOp.ConvexHull(); pPointColl2.SpatialReference = spatialrefrence; // OutputPolygon = pPointColl2; maybe you don't need this line as the object is not used return(pPointColl2); } catch (Exception e) { return(null); } }
private void OnTimerElapsed(IDisplay Display, IDynamicDisplay dynamicDisplay) { try { //make sure that the current tracking point index does not exceed the list index if (m_pointIndex == (m_points.Count - 1)) { m_pointIndex = 0; return; } //get the current and the next track location WKSPoint currentPoint = m_points[m_pointIndex]; WKSPoint nextPoint = m_points[m_pointIndex + 1]; //calculate the azimuth to the next location double azimuth = (180.0 / Math.PI) * Math.Atan2(nextPoint.X - currentPoint.X, nextPoint.Y - currentPoint.Y); //set the navigation data structure m_navigationData.X = currentPoint.X; m_navigationData.Y = currentPoint.Y; m_navigationData.Azimuth = azimuth; //update the map extent and rotation CenterMap(m_navigationData); //increment the tracking point index m_pointIndex++; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
public static double ConvertPixelDistanceToMapDistance(IActiveView vActiveView, double vPixelDistance) { tagPOINT tagP; WKSPoint WKSP = new WKSPoint(); tagP.x = Convert.ToInt32(vPixelDistance); tagP.y = Convert.ToInt32(vPixelDistance); vActiveView.ScreenDisplay.DisplayTransformation.TransformCoords(ref WKSP, ref tagP, 1, 6); return(WKSP.X); }
/// <summary> /// 把像素(屏幕)距离转化成为地图上的距离 /// </summary> private double ConvertPixelDistanceToMapDistance(double PixelDistance) { tagPOINT tagP = new tagPOINT(); WKSPoint wksP = new WKSPoint(); tagP.x = ( int )PixelDistance; tagP.y = ( int )PixelDistance; (m_CurrentMap as IActiveView).ScreenDisplay.DisplayTransformation.TransformCoords(ref wksP, ref tagP, 1, 6); return(wksP.X); }
//把像素(屏幕)距离转化成为地图上的距离 public static double ConvertPixelDistanceToMapDistance(IActiveView pActiveView, double pPixelDistance) { tagPOINT tagPOINT = new tagPOINT(); tagPOINT.x = Convert.ToInt32(pPixelDistance); tagPOINT.y = Convert.ToInt32(pPixelDistance); WKSPoint pWKSPoint = new WKSPoint(); pActiveView.ScreenDisplay.DisplayTransformation.TransformCoords(ref pWKSPoint, ref tagPOINT, 1, 6); return(pWKSPoint.X); }
/// <summary> /// 把像素(屏幕)距离转化成为地图上的距离 /// </summary> /// <param name="vActiveView">用于构造转换器</param> /// <param name="vPixelDistance">像素距离</param> /// <returns>地图距离</returns> public double ConvertPixelDistanceToMapDistance(IActiveView vActiveView, double vPixelDistance) { tagPOINT tagPOINT; WKSPoint WKSPoint = new WKSPoint(); //依据距离构造一个点 tagPOINT.x = (int)vPixelDistance; tagPOINT.y = (int)vPixelDistance; //转换点的信息 vActiveView.ScreenDisplay.DisplayTransformation.TransformCoords(ref WKSPoint, ref tagPOINT, 1, 6); //返回点x即距离 return(WKSPoint.X); }
public static IPoint ConvertGcsToPcs(IPoint point, IProjectedCoordinateSystem projectedCoordinateSystem) { WKSPoint wksPoint = new WKSPoint(); wksPoint.X = point.X; wksPoint.Y = point.Y; projectedCoordinateSystem.Forward(1, ref wksPoint); IPoint pPoint = new PointClass(); pPoint.X = wksPoint.X; pPoint.Y = wksPoint.Y; return(pPoint); }
//ÉÁ˸Ïß²¢¸ßÁÁÏÔʾ private static void FlashLineAndHiLight(IActiveView pActiveView, IGeometry pGeometry, int interval) { IScreenDisplay pDisplay = pActiveView.ScreenDisplay; ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); ISymbol pSymbol; IRgbColor pRGBColor; tagPOINT tagPOINT = new tagPOINT(); WKSPoint WKSPoint = new WKSPoint(); tagPOINT.x = (int)1; tagPOINT.y = (int)1; pDisplay.DisplayTransformation.TransformCoords(ref WKSPoint, ref tagPOINT, 1, 6); pLineSymbol = new SimpleLineSymbolClass(); //if (pActiveView.FocusMap.MapScale != 0) //{ // pLineSymbol.Width = WKSPoint.X * 10000 / pActiveView.FocusMap.MapScale; //} //else //{ // pLineSymbol.Width = WKSPoint.X / 2; //} pLineSymbol.Width = WKSPoint.X; pRGBColor = new RgbColorClass(); pRGBColor.Green = 148; //148 pRGBColor.Red = 32; //32 pRGBColor.Blue = 0; pSymbol = pLineSymbol as ISymbol; pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; pDisplay.SetSymbol(pSymbol); pDisplay.DrawPolyline(pGeometry); System.Threading.Thread.Sleep(interval); pDisplay.DrawPolyline(pGeometry); pLineSymbol.Width = 3; IElement pEle = new LineElementClass();//yjl¸ßÁÁÏÔʾ pEle.Geometry = pGeometry; (pEle as ILineElement).Symbol = pSymbol as ILineSymbol; (pEle as IElementProperties).Name = _FlashTagName; (pActiveView as IGraphicsContainer).AddElement(pEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pEle, null); //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, pEle, null); }
private IPolygon CreatePolygonByPoints(IPointCollection pCol) { IGeometryBridge2 gb2 = new GeometryEnvironmentClass(); IPointCollection4 pPolygon = new PolygonClass(); WKSPoint[] pWKSPoint = new WKSPoint[pCol.PointCount]; for (int i = 0; i < pCol.PointCount; i++) { pWKSPoint[i].X = pCol.get_Point(i).X; pWKSPoint[i].Y = pCol.get_Point(i).Y; } gb2.SetWKSPoints(pPolygon, ref pWKSPoint); IPolygon poly = pPolygon as IPolygon; poly.Close(); return(poly); }
private void GenerateNavigationData() { try { //get the ArcGIS install path from the registry string runtimeVersion = RuntimeManager.ActiveRuntime.Version; RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ESRI\ArcObjectsSDK" + runtimeVersion); string path = Convert.ToString(key.GetValue("InstallDir")); //get navigationData.xml file from DeveloperKit m_navigationDataFileName = System.IO.Path.Combine(path, @"Samples\data\USAMajorHighways\NavigationData.xml"); if (!System.IO.File.Exists(m_navigationDataFileName)) { throw new Exception("File " + m_navigationDataFileName + " cannot be found!"); } XmlTextReader reader = new XmlTextReader(m_navigationDataFileName); XmlDocument doc = new XmlDocument(); doc.Load(reader); reader.Close(); double X; double Y; //get the navigation items XmlNodeList nodes = doc.DocumentElement.SelectNodes("./navigationItem"); foreach (XmlNode node in nodes) { X = Convert.ToDouble(node.Attributes[0].Value); Y = Convert.ToDouble(node.Attributes[1].Value); WKSPoint p = new WKSPoint(); p.X = X; p.Y = Y; m_points.Add(p); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
private void GenerateNavigationData() { try { string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //get navigationData.xml file from DeveloperKit m_navigationDataFileName = System.IO.Path.Combine(path, @"ArcGIS\data\USAMajorHighways\NavigationData.xml"); if (!System.IO.File.Exists(m_navigationDataFileName)) { throw new Exception("File " + m_navigationDataFileName + " cannot be found!"); } XmlTextReader reader = new XmlTextReader(m_navigationDataFileName); XmlDocument doc = new XmlDocument(); doc.Load(reader); reader.Close(); double X; double Y; //get the navigation items XmlNodeList nodes = doc.DocumentElement.SelectNodes("./navigationItem"); foreach (XmlNode node in nodes) { X = Convert.ToDouble(node.Attributes[0].Value); Y = Convert.ToDouble(node.Attributes[1].Value); WKSPoint p = new WKSPoint(); p.X = X; p.Y = Y; m_points.Add(p); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
/// <summary> /// 设置矩形框范围 /// </summary> /// <param name="pFeature"></param> /// <param name="XLength">X轴方向长度二分之一</param> /// <param name="YLength">Y轴方向长度二分之一</param> /// <returns></returns> private IGeometry SetGeometry(IFeature pFeature, ref string mapNO) { IGeometry res = null; //pGeometry = new EnvelopeClass(); IEnvelope penvelope = new EnvelopeClass(); ISpatialReference pSpatialRefrence = pFeature.ShapeCopy.SpatialReference; string mapNo = ""; if (pSpatialRefrence is IProjectedCoordinateSystem) { IGeographicCoordinateSystem pGCS = (pSpatialRefrence as IProjectedCoordinateSystem).GeographicCoordinateSystem; IArea pArea = pFeature.ShapeCopy as IArea; IPoint pCPoint = pArea.Centroid; double difX = 1 * 3600 / 16, difY = 1 * 3600 / 24; IProjectedCoordinateSystem pPCS = pSpatialRefrence as IProjectedCoordinateSystem; WKSPoint pPointMin = new WKSPoint(); pPointMin.X = pCPoint.X; pPointMin.Y = pCPoint.Y; pPCS.Inverse(1, ref pPointMin); double minX = Math.Floor(pPointMin.X * 3600 / difX) * difX; double minY = Math.Floor(pPointMin.Y * 3600 / difY) * difY; long lScale = 10000; GeoDrawSheetMap.basPageLayout.GetNewCodeFromCoordinate(ref mapNo, (long)(pPointMin.X * 3600), (long)(pPointMin.Y * 3600), lScale); //GeoDrawSheetMap.basPageLayout.GetNewCodeFromCoordinate(ref mapNo, (long)(minX), (long)(minY+3), lScale); penvelope.PutCoords(minX / 3600, minY / 3600, (minX + difX) / 3600, (minY + difY) / 3600); penvelope.SpatialReference = pGCS; penvelope.Project(pSpatialRefrence); res = penvelope; } mapNO = mapNo; return(res); }
//ÉÁ˸Ïß private static void FlashLine(IActiveView pActiveView, IGeometry pGeometry, int interval) { IScreenDisplay pDisplay = pActiveView.ScreenDisplay; ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); ISymbol pSymbol; IRgbColor pRGBColor; tagPOINT tagPOINT = new tagPOINT(); WKSPoint WKSPoint = new WKSPoint(); tagPOINT.x = (int)1; tagPOINT.y = (int)1; pDisplay.DisplayTransformation.TransformCoords(ref WKSPoint, ref tagPOINT, 1, 6); pLineSymbol = new SimpleLineSymbolClass(); //if (pActiveView.FocusMap.MapScale != 0) //{ // pLineSymbol.Width = WKSPoint.X * 10000 / pActiveView.FocusMap.MapScale; //} //else //{ // pLineSymbol.Width = WKSPoint.X / 2; //} pLineSymbol.Width = WKSPoint.X; pRGBColor = new RgbColorClass(); pRGBColor.Green = 148; //148 pRGBColor.Red = 32; //32 pRGBColor.Blue = 0; pSymbol = pLineSymbol as ISymbol; pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; pDisplay.SetSymbol(pSymbol); pDisplay.DrawPolyline(pGeometry); System.Threading.Thread.Sleep(interval); pDisplay.DrawPolyline(pGeometry); }
protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { bool abortOperation = false; ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null; try { if (m_dockableDigit == null) return; if (arg != null) { m_x = arg.X; m_y = arg.Y; } if (m_dockableWindow == null) return; if (m_dockableWindow.IsVisible() == false) { m_dockableWindow.Show(true); } ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension; if (target != null) m_schematicLayer = target.SchematicTarget; if (m_schematicLayer == null) { System.Windows.Forms.MessageBox.Show("No target Layer"); return; } ISchematicInMemoryDiagram inMemoryDiagram; ISchematicInMemoryFeatureClass schematicInMemoryFeatureClass; ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer; //Get the point ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp; ESRI.ArcGIS.Display.IAppDisplay appDisplay; IScreenDisplay screenDisplay; IDisplay display; IDisplayTransformation transform; ISpatialReference spatialReference; inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram; schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram; if (schematicInMemoryFeatureClassContainer == null) return; mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app; if (mxApp == null) return; appDisplay = mxApp.Display; if (appDisplay == null) return; screenDisplay = appDisplay.FocusScreen; display = screenDisplay; if (display == null) return; transform = display.DisplayTransformation; if (transform == null) return; spatialReference = transform.SpatialReference; WKSPoint mapPt = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPoint; devPoint.x = m_x; devPoint.y = m_y; transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap point.SpatialReference = spatialReference; point.Project(spatialReference); point.X = mapPt.X; point.Y = mapPt.Y; schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass()); if (schematicInMemoryFeatureClass == null) { System.Windows.Forms.MessageBox.Show("Invalid Type."); return; } if (m_dockableDigit.CreateNode()) { //TestMandatoryField m_dockableDigit.btnOKPanel1.Visible = false; if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK); return; } ESRI.ArcGIS.Geometry.IGeometry geometry; ISchematicInMemoryFeature schematicInMemoryFeatureNode; geometry = point; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, ""); //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureNode; m_dockableDigit.FillValue(ref schematicFeature); if (m_dockableDigit.AutoClear()) m_dockableDigit.SelectionChanged(); } else { m_dockableDigit.btnOKPanel2.Visible = false; //Get the Tolerance of ArcMap Double tolerance; IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document; ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPt; tolerance = mxDocument.SearchTolerancePixels; devPt.x = (int)tolerance; devPt.y = (int)tolerance; transform.TransformCoords(ref point2, ref devPt, 1, 2);//2 <-> esriTransformSize 4 <-> esriTransformToMap tolerance = point2.X * 5;//increase the tolerance value IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true); ISchematicFeature schematicFeatureSelected = null; double distancetmp; double distance = 0; schematicFeatures.Reset(); if (schematicFeatures.Count <= 0) return; //pSchematicFeatures may contain several features, we are choosing the closest node. ISchematicFeature schematicFeature2 = schematicFeatures.Next(); double dX; double dY; ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode = null; if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode; dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; schematicFeatureSelected = schematicFeature2; distance = SquareDistance(dX - point.X, dY - point.Y); while (schematicFeature2 != null) { //find the closest featureNode... if (schematicInMemoryFeatureNode != null) { schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry) schematicInMemoryFeatureNode; if (schematicInMemoryFeatureNodeGeometry == null) continue; dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; distancetmp = SquareDistance(dX - point.X, dY - point.Y); if (distancetmp < distance) { distance = distancetmp; schematicFeatureSelected = schematicFeature2; } } schematicFeature2 = schematicFeatures.Next(); if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } } if (schematicFeatureSelected == null) return; if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType) return; if (m_schematicFeature1 == null) { m_schematicFeature1 = schematicFeatureSelected; m_dockableDigit.SchematicFeature1(m_schematicFeature1); if (!m_dockableDigit.CheckValidFeature(true)) { m_schematicFeature1 = null; m_dockableDigit.SchematicFeature1(m_schematicFeature1); throw new Exception("Invalid starting node for this link type"); } //Begin Feedback m_linkFbk = new NewLineFeedback(); m_linkFbk.Display = screenDisplay; //symbol ISimpleLineSymbol sLnSym; IRgbColor rGB = new RgbColor(); sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol; //Make a color rGB.Red = 255; rGB.Green = 0; rGB.Blue = 0; // Setup the symbol with color and style sLnSym.Color = rGB; m_linkFbk.Start(point); //End Feedback //To know if we are in the same diagram. m_schematicLayerForLink = m_schematicLayer; } else { if (m_schematicLayerForLink != m_schematicLayer) { System.Windows.Forms.MessageBox.Show("wrong Target layer"); m_schematicLayerForLink = null; EndFeedBack(); return; } m_schematicFeature2 = schematicFeatureSelected; m_dockableDigit.SchematicFeature2(m_schematicFeature2); //TestMandatoryField if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK); return; } if (!m_dockableDigit.CheckValidFeature(false)) { m_schematicFeature2 = null; m_dockableDigit.SchematicFeature2(m_schematicFeature2); throw new Exception("Invalid End node for this link type"); } //CreateLink ISchematicInMemoryFeature schematicInMemoryFeatureLink; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, ""); //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureLink; m_dockableDigit.FillValue(ref schematicFeature); //End Feedback EndFeedBack(); m_schematicLayerForLink = null; if (m_dockableDigit.AutoClear()) m_dockableDigit.SelectionChanged(); } } //Refresh the view and viewer windows RefreshView(); } catch (System.Exception e) { if (abortOperation && (schematicOperation != null)) schematicOperation.AbortOperation(); EndFeedBack(); System.Windows.Forms.MessageBox.Show(e.Message); } return; }
protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { bool abortOperation = false; ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null; try { if (m_dockableDigit == null) { return; } if (arg != null) { m_x = arg.X; m_y = arg.Y; } if (m_dockableWindow == null) { return; } if (m_dockableWindow.IsVisible() == false) { m_dockableWindow.Show(true); } ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension; if (target != null) { m_schematicLayer = target.SchematicTarget; } if (m_schematicLayer == null) { System.Windows.Forms.MessageBox.Show("No target Layer"); return; } ISchematicInMemoryDiagram inMemoryDiagram; ISchematicInMemoryFeatureClass schematicInMemoryFeatureClass; ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer; //Get the point ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point(); ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp; ESRI.ArcGIS.Display.IAppDisplay appDisplay; IScreenDisplay screenDisplay; IDisplay display; IDisplayTransformation transform; ISpatialReference spatialReference; inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram; schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram; if (schematicInMemoryFeatureClassContainer == null) { return; } mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app; if (mxApp == null) { return; } appDisplay = mxApp.Display; if (appDisplay == null) { return; } screenDisplay = appDisplay.FocusScreen; display = screenDisplay; if (display == null) { return; } transform = display.DisplayTransformation; if (transform == null) { return; } spatialReference = transform.SpatialReference; WKSPoint mapPt = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPoint; devPoint.x = m_x; devPoint.y = m_y; transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap point.SpatialReference = spatialReference; point.Project(spatialReference); point.X = mapPt.X; point.Y = mapPt.Y; schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass()); if (schematicInMemoryFeatureClass == null) { System.Windows.Forms.MessageBox.Show("Invalid Type."); return; } if (m_dockableDigit.CreateNode()) { //TestMandatoryField m_dockableDigit.btnOKPanel1.Visible = false; if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK); return; } ESRI.ArcGIS.Geometry.IGeometry geometry; ISchematicInMemoryFeature schematicInMemoryFeatureNode; geometry = point; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, ""); //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureNode; m_dockableDigit.FillValue(ref schematicFeature); if (m_dockableDigit.AutoClear()) { m_dockableDigit.SelectionChanged(); } } else { m_dockableDigit.btnOKPanel2.Visible = false; //Get the Tolerance of ArcMap Double tolerance; IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document; ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint(); ESRI.ArcGIS.Display.tagPOINT devPt; tolerance = mxDocument.SearchTolerancePixels; devPt.x = (int)tolerance; devPt.y = (int)tolerance; transform.TransformCoords(ref point2, ref devPt, 1, 2); //2 <-> esriTransformSize 4 <-> esriTransformToMap tolerance = point2.X * 5; //increase the tolerance value IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true); ISchematicFeature schematicFeatureSelected = null; double distancetmp; double distance = 0; schematicFeatures.Reset(); if (schematicFeatures.Count <= 0) { return; } //pSchematicFeatures may contain several features, we are choosing the closest node. ISchematicFeature schematicFeature2 = schematicFeatures.Next(); double dX; double dY; ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode = null; if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) { schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } } ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode; dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; schematicFeatureSelected = schematicFeature2; distance = SquareDistance(dX - point.X, dY - point.Y); while (schematicFeature2 != null) { //find the closest featureNode... if (schematicInMemoryFeatureNode != null) { schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode; if (schematicInMemoryFeatureNodeGeometry == null) { continue; } dX = schematicInMemoryFeatureNodeGeometry.Position.X; dY = schematicInMemoryFeatureNodeGeometry.Position.Y; distancetmp = SquareDistance(dX - point.X, dY - point.Y); if (distancetmp < distance) { distance = distancetmp; schematicFeatureSelected = schematicFeature2; } } schematicFeature2 = schematicFeatures.Next(); if (schematicFeature2 != null) { if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) { schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2; } } } if (schematicFeatureSelected == null) { return; } if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType) { return; } if (m_schematicFeature1 == null) { m_schematicFeature1 = schematicFeatureSelected; m_dockableDigit.SchematicFeature1(m_schematicFeature1); if (!m_dockableDigit.CheckValidFeature(true)) { m_schematicFeature1 = null; m_dockableDigit.SchematicFeature1(m_schematicFeature1); throw new Exception("Invalid starting node for this link type"); } //Begin Feedback m_linkFbk = new NewLineFeedback(); m_linkFbk.Display = screenDisplay; //symbol ISimpleLineSymbol sLnSym; IRgbColor rGB = new RgbColor(); sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol; //Make a color rGB.Red = 255; rGB.Green = 0; rGB.Blue = 0; // Setup the symbol with color and style sLnSym.Color = rGB; m_linkFbk.Start(point); //End Feedback //To know if we are in the same diagram. m_schematicLayerForLink = m_schematicLayer; } else { if (m_schematicLayerForLink != m_schematicLayer) { System.Windows.Forms.MessageBox.Show("wrong Target layer"); m_schematicLayerForLink = null; EndFeedBack(); return; } m_schematicFeature2 = schematicFeatureSelected; m_dockableDigit.SchematicFeature2(m_schematicFeature2); //TestMandatoryField if (m_dockableDigit.ValidateFields() == false) { m_dockableDigit.x(m_x); m_dockableDigit.y(m_y); System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK); return; } if (!m_dockableDigit.CheckValidFeature(false)) { m_schematicFeature2 = null; m_dockableDigit.SchematicFeature2(m_schematicFeature2); throw new Exception("Invalid End node for this link type"); } //CreateLink ISchematicInMemoryFeature schematicInMemoryFeatureLink; schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation(); //digit operation is undo(redo)able we add it in the stack IMxDocument doc = (IMxDocument)m_app.Document; ESRI.ArcGIS.SystemUI.IOperationStack operationStack; operationStack = doc.OperationStack; operationStack.Do(schematicOperation); schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true); //do abort operation abortOperation = true; schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, ""); //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked; abortOperation = false; schematicOperation.StopOperation(); ISchematicFeature schematicFeature = schematicInMemoryFeatureLink; m_dockableDigit.FillValue(ref schematicFeature); //End Feedback EndFeedBack(); m_schematicLayerForLink = null; if (m_dockableDigit.AutoClear()) { m_dockableDigit.SelectionChanged(); } } } //Refresh the view and viewer windows RefreshView(); } catch (System.Exception e) { if (abortOperation && (schematicOperation != null)) { schematicOperation.AbortOperation(); } EndFeedBack(); System.Windows.Forms.MessageBox.Show(e.Message); } return; }
public bool Apply() { if (this.bool_0) { this.bool_0 = false; double angle = 0.0; double scale = 0.0; try { angle = double.Parse(this.txtRotate.Text); } catch { } try { scale = double.Parse(this.txtScale.Text); } catch { } WKSPoint point = new WKSPoint(); try { point.X = double.Parse(this.txtFromXCoord1.Text); } catch { } try { point.Y = double.Parse(this.txtFromYCoord1.Text); } catch { } WKSPoint point2 = new WKSPoint(); try { point2.X = double.Parse(this.txtToXCoord1.Text); } catch { } try { point2.Y = double.Parse(this.txtToYCoord1.Text); } catch { } WKSPoint point3 = new WKSPoint(); try { point3.X = double.Parse(this.txtFromXCoord1.Text); } catch { } try { point3.Y = double.Parse(this.txtFromYCoord1.Text); } catch { } WKSPoint point4 = new WKSPoint(); try { point4.X = double.Parse(this.txtToXCoord1.Text); } catch { } try { point4.Y = double.Parse(this.txtToYCoord1.Text); } catch { } this.icadTransformations_0.EnableTransformations = this.checkEdit1.Checked; switch (this.radioGroup1.SelectedIndex) { case 0: this.icadTransformations_0.TransformMode = esriCadTransform.esriCadTransformByWorldFile; this.icadTransformations_0.WorldFileName = this.txtWordFileName.Text; break; case 1: this.icadTransformations_0.TransformMode = esriCadTransform.esriCadTransformByPoints; this.icadTransformations_0.SetFromToTransform(ref point, ref point3, ref point2, ref point4); break; case 2: this.icadTransformations_0.TransformMode = esriCadTransform.esriCadTransformByRst; this.icadTransformations_0.SetTransformation(ref point, ref point3, angle, scale); break; } } return(true); }
/// <summary> /// ת������� /// </summary> /// <params name="vActiveView"></params> /// <params name="vPixelDistance"></params> /// <returns></returns> public static double ConvertPixelDistanceToMapDistance(IActiveView vActiveView, double vPixelDistance) { tagPOINT tagP; WKSPoint WKSP = new WKSPoint(); tagP.x = Convert.ToInt32(vPixelDistance); tagP.y = Convert.ToInt32(vPixelDistance); vActiveView.ScreenDisplay.DisplayTransformation.TransformCoords(ref WKSP, ref tagP, 1, 6); return WKSP.X; }
private List<IGeometry> splitGeometry(IGeometry geo,bool mergePolys) { IGeometry geoM = null; if (mergePolys) { geoM = mergeSmallGeos(geo); } else { geoM = geo; } List<IGeometry> geoLst = new List<IGeometry>(); IPolygon4 poly4 = (IPolygon4)geoM; IGeometryCollection geoColl = (IGeometryCollection)poly4.ConnectedComponentBag; for (int i = 0; i < geoColl.GeometryCount; i++) { IGeometry geo2 = geoColl.get_Geometry(i); IEnvelope env = geo2.Envelope; double xmax = env.XMax; double xmin = env.XMin; double ymax = env.YMax; double ymin = env.YMin; double xRange = xmax - xmin; double yRange = ymax - ymin; double nMinX, nMinY, nMaxX, nMaxY; if (xRange > yRange) { nMinY = ymin - 1; nMaxY = ymax + 1; nMinX = xmin + (xRange / 2); nMaxX = nMinX; } else { nMinX = xmin - 1; nMaxX = xmax + 1; nMinY = ymin + (yRange / 2); nMaxY = nMinY; } WKSPoint[] wksPoint = new WKSPoint[2]; IPointCollection4 pointCollection4 = new PolylineClass(); wksPoint[0].X = nMinX; wksPoint[0].Y = nMinY; wksPoint[1].X = nMaxX; wksPoint[1].Y = nMaxY; IGeometryBridge2 geometryBridge2 = new GeometryEnvironmentClass(); geometryBridge2.AddWKSPoints(pointCollection4, ref wksPoint); IPolyline polyline = pointCollection4 as ESRI.ArcGIS.Geometry.IPolyline; polyline.SpatialReference = geo2.SpatialReference; ITopologicalOperator4 tp = (ITopologicalOperator4)geo2; IGeometry geoL = null; IGeometry geoR = null; try { tp.Cut(polyline, out geoL, out geoR); if (((IArea)geoL).Area > maxarea) { geoLst.AddRange(splitGeometry(geoL,false)); } else { geoLst.Add(geoL); } if (((IArea)geoR).Area > maxarea) { geoLst.AddRange(splitGeometry(geoR,false)); } else { geoLst.Add(geoR); } } catch (Exception e) { geoLst.Add(geo2); Console.WriteLine(e.ToString()); } } return geoLst; }
private static void CreateFeatures(List<GdbFromKmlFeature> gdbFeaturesFromKML) { License lic = new License(); IWorkspaceEdit wse = null; try { bool ok = lic.GetLicenses(); IFeatureWorkspace fws = (IFeatureWorkspace)GetWorkspace(); // cast this as an IWorkspace wse = (IWorkspaceEdit)fws; wse.StartEditing(false); wse.StartEditOperation(); IFeatureClass waypointFC = fws.OpenFeatureClass("WAYPOINT"); IFeatureClass trailFC = fws.OpenFeatureClass("TRAIL"); ISpatialReference spatRef = ((IGeoDataset)waypointFC.FeatureDataset).SpatialReference; int counter = 0; foreach (GdbFromKmlFeature gdbFe in gdbFeaturesFromKML) { if (gdbFe.IsPoint) { /*var newWayPoint = waypointFC.CreateFeature(); newWayPoint.set_Value(newWayPoint.Fields.FindField("NAME"), gdbFe.Name); newWayPoint.set_Value(newWayPoint.Fields.FindField("SHORTDESCRIPTION"), gdbFe.Description); newWayPoint.set_Value(newWayPoint.Fields.FindField("SUBTYPE"), 4); double lat = Convert.ToDouble(gdbFe.Coordinates[0][1]); double lon = Convert.ToDouble(gdbFe.Coordinates[0][0]); double elev = Convert.ToDouble(gdbFe.Coordinates[0][2]); newWayPoint.set_Value(newWayPoint.Fields.FindField("LATITUDE"), lat); newWayPoint.set_Value(newWayPoint.Fields.FindField("LONGITUDE"), lon); newWayPoint.set_Value(newWayPoint.Fields.FindField("ELEVATION"), elev); ToWebMercator(ref lon, ref lat); IPoint pnt = new PointClass(); pnt.PutCoords(lon, lat); pnt.SpatialReference = spatRef; newWayPoint.Shape = pnt; newWayPoint.Store();*/ } else { Console.WriteLine(counter); var newTrail = trailFC.CreateFeature(); newTrail.set_Value(newTrail.Fields.FindField("SEGMENT"), gdbFe.Name); //newTrail.set_Value(newTrail.Fields.FindField("SHORTDESCRIPTION"), gdbFe.Description); newTrail.set_Value(newTrail.Fields.FindField("SUBTYPE"), 1); //Define shape IGeometryBridge2 pGeoBrg = new GeometryEnvironment() as IGeometryBridge2; IPointCollection4 pPointColl = new PolylineClass(); ((IGeometry)pPointColl).SpatialReference = spatRef; int vertexCount = gdbFe.Coordinates.Count; WKSPoint[] aWKSPointBuffer = new WKSPoint[vertexCount]; int i = 0; foreach(string[] vertex in gdbFe.Coordinates) { double lat = Convert.ToDouble(vertex[1]); double lon = Convert.ToDouble(vertex[0]); double elev = Convert.ToDouble(vertex[2]); ToWebMercator(ref lon, ref lat); aWKSPointBuffer[i] = new WKSPoint() { X = lon, Y = lat }; i++; } pGeoBrg.SetWKSPoints(pPointColl, ref aWKSPointBuffer); newTrail.Shape = (IGeometry) pPointColl; newTrail.Store(); } counter++; if (counter % 100 == 0) { wse.StopEditOperation(); wse.StopEditing(true); wse.StartEditing(false); wse.StartEditOperation(); } } } finally { wse.StopEditOperation(); wse.StopEditing(true); lic.ReleaseLicenses(); } }
private void PlanarToGeoCoor(ref string X,ref string Y) { IProjectedCoordinateSystem pcs = this.m_mapControl.SpatialReference as IProjectedCoordinateSystem; WKSPoint pt = new WKSPoint(); pt.X = Convert.ToDouble(X); pt.Y = Convert.ToDouble(Y); pcs.Inverse(1, ref pt); int dgree; int minute; double second; double tempValue; dgree = (int)pt.X; tempValue = Math.Abs(pt.X - dgree) * 60; second = Math.Abs(tempValue - (int)tempValue) * 60; minute = (int)tempValue; X = dgree.ToString() + "°" + minute.ToString() + "'" + second.ToString("#######.##") + "''"; dgree = (int)pt.Y; tempValue = Math.Abs(pt.Y - dgree) * 60; second = Math.Abs(tempValue - (int)tempValue) * 60; minute = (int)tempValue; Y = dgree.ToString() + "°" + minute.ToString() + "'" + second.ToString("#######.##") + "''"; }
private List <IGeometry> splitGeometry(IGeometry geo, bool mergePolys) { IGeometry geoM = null; if (mergePolys) { geoM = mergeSmallGeos(geo); } else { geoM = geo; } List <IGeometry> geoLst = new List <IGeometry>(); IPolygon4 poly4 = (IPolygon4)geoM; IGeometryCollection geoColl = (IGeometryCollection)poly4.ConnectedComponentBag; for (int i = 0; i < geoColl.GeometryCount; i++) { IGeometry geo2 = geoColl.get_Geometry(i); IEnvelope env = geo2.Envelope; double xmax = env.XMax; double xmin = env.XMin; double ymax = env.YMax; double ymin = env.YMin; double xRange = xmax - xmin; double yRange = ymax - ymin; double nMinX, nMinY, nMaxX, nMaxY; if (xRange > yRange) { nMinY = ymin - 1; nMaxY = ymax + 1; nMinX = xmin + (xRange / 2); nMaxX = nMinX; } else { nMinX = xmin - 1; nMaxX = xmax + 1; nMinY = ymin + (yRange / 2); nMaxY = nMinY; } WKSPoint[] wksPoint = new WKSPoint[2]; IPointCollection4 pointCollection4 = new PolylineClass(); wksPoint[0].X = nMinX; wksPoint[0].Y = nMinY; wksPoint[1].X = nMaxX; wksPoint[1].Y = nMaxY; IGeometryBridge2 geometryBridge2 = new GeometryEnvironmentClass(); geometryBridge2.AddWKSPoints(pointCollection4, ref wksPoint); IPolyline polyline = pointCollection4 as ESRI.ArcGIS.Geometry.IPolyline; polyline.SpatialReference = geo2.SpatialReference; ITopologicalOperator4 tp = (ITopologicalOperator4)geo2; IGeometry geoL = null; IGeometry geoR = null; try { tp.Cut(polyline, out geoL, out geoR); if (((IArea)geoL).Area > maxarea) { geoLst.AddRange(splitGeometry(geoL, false)); } else { geoLst.Add(geoL); } if (((IArea)geoR).Area > maxarea) { geoLst.AddRange(splitGeometry(geoR, false)); } else { geoLst.Add(geoR); } } catch (Exception e) { geoLst.Add(geo2); Console.WriteLine(e.ToString()); } } return(geoLst); }