Example #1
0
        public void getGlobeCoodinates(AxGlobeControl axGlobeControl, int x, int y, out double X, out double Y, out double Z)
        {
            //string coordInfo = "坐标信息";
            try
            {
                //获取点击坐标的X、Y
                IPoint globePoint = new PointClass();
                IGlobeDisplay globeDisplay = axGlobeControl.GlobeDisplay;
                ISceneViewer sceneViewer = globeDisplay.ActiveViewer;
                System.Object owner = System.Type.Missing;
                System.Object object1 = System.Type.Missing;
                globeDisplay.Locate(sceneViewer, x, y, false, false, out globePoint, out owner, out object1);

                //coordInfo = globePoint.X.ToString("F8") + "," + globePoint.Y.ToString("F8") + "," + globePoint.Z.ToString("F4");
                X = globePoint.X;
                Y = globePoint.Y;
                Z = globePoint.Z;
                //return coordInfo;
            }
            catch
            {
                X = 0;
                Y = 0;
                Z = 0;
                //return coordInfo;
            }
        }
Example #2
0
        public Form1()
        {
            if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.ArcReader))
            {
                if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop))
                {
                    MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
                    return;
                }
            }
            InitializeComponent();

            //IMap.ClipGeometry Property;

            string filePath = @"E:\Downloads\ARCgis\United States\USA Base Map.mxd";
            if (axMapControl1.CheckMxFile(filePath))
                axMapControl1.LoadMxFile(filePath, Type.Missing, Type.Missing);
            IPoint point = new PointClass();
            point.X = -100;
            point.Y = 40000;

            System.Drawing.Point p = new System.Drawing.Point(101, 37);

               // axMapControl1.CenterAt(point);
            //IEnvelope pEnvelope = this.axMapControl1.Extent;
            axMapControl1.PointToClient(p);
            //pEnvelope.CenterAt(point);
            //this.axMapControl1.Extent = pEnvelope;

            //axMapControl1.ActiveView.ScreenDisplay.RotateMoveTo(point);
            ////Draw the rotated display.
            //axMapControl1.ActiveView.ScreenDisplay.RotateTimer();

            axMapControl1.Refresh();
        }
    static void Main()
    {
        PointStruct ps1 = new PointStruct();
        ps1.x = ps1.y = 22;

        PointStruct ps2 = new PointStruct();
        ps2.x = ps2.y = 33;

        ps1 = ps2;
        ps2.x = ps2.y = 55;

        Console.WriteLine("ps1 is ({0}, {1})", ps1.x, ps1.y);
        Console.WriteLine("ps2 is ({0}, {1})", ps2.x, ps2.y);
        Console.WriteLine("ps1.Equals(ps2) results in " + ps1.Equals(ps2));

        PointClass pc1 = new PointClass();
        pc1.x = pc1.y = 22;

        PointClass pc2 = new PointClass();
        pc2.x = pc2.y = 33;

        pc1 = pc2;
        pc2.x = pc2.y = 55;

        Console.WriteLine("pc1 is ({0}, {1})", pc1.x, pc1.y);
        Console.WriteLine("pc2 is ({0}, {1})", pc2.x, pc2.y);
        Console.WriteLine("pc1.Equals(pc2) results in " + pc1.Equals(pc2));
        Console.WriteLine("pc1 == pc2 results in " + (pc1 == pc2));
    }
        /// <summary>
        /// 绘制推断断层
        /// </summary>
        /// <params name="title"></params>
        /// <params name="faultagePointList"></params>
        /// <params name="bId"></params>
        /// <returns></returns>
        public static bool DrawTddc(String title, List<InferFaultagePoint> faultagePointList, String bId)
        {
            List<IPoint> listptS = new List<IPoint>();
            List<IPoint> listptX = new List<IPoint>();

            foreach (var i in faultagePointList)
            {
                if (i.up_or_down == "上盘")
                {
                    IPoint point = new PointClass();
                    point.X = i.coordinate_x;
                    point.Y = i.coordinate_y;
                    point.Z = i.coordinate_z;

                    listptS.Add(point);
                }
                else if (i.up_or_down == "下盘")
                {
                    IPoint point = new PointClass();
                    point.X = i.coordinate_x;
                    point.Y = i.coordinate_y;
                    point.Z = i.coordinate_z;

                    listptX.Add(point);
                }
            }

            return DrawTDDC(title, bId, listptS, listptX);
        }
        protected override void OnClick()
        {
            IActiveView activeView = ArcMap.Document.ActiveView;
            
            IMap map = activeView as IMap;
            ILayer layer = map.get_Layer(0);
            IFeatureLayer featureLayer = layer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;

            IPoint point = new PointClass();
            point.PutCoords(-117.1, 34.075); //(LONG, LAT)

            IWorkspace workspace = GetWorkspace();
            IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();

            // -------------- Perform your editing tests here ------------------
            CreateFeature(featureClass, point);     
            //UpdateFeature(featureClass);
            //DeleteFeature(featureClass);

            // -----------------------------------------------------------------

            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);

            ArcMap.Application.CurrentTool = null;
        }
Example #6
0
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            int intx = arg.X;
            int inty = arg.Y;
            IPoint pPoints = new PointClass();
            pPoints.PutCoords(intx, inty);

            IActiveView activeView = ArcMap.Document.ActiveView;
            pPoints = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(-100, 40);//x,y为屏幕坐标

            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;
            ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
            pPoints=displayTransformation.ToMapPoint(-120, 40);

            IMxDocument doc = ArcMap.Document;
            IMap map = doc.FocusMap;
            pPoints=doc.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(-100, 40);

            AlterForm frm = null;
            if (frm == null || frm.IsDisposed)
                frm = new AlterForm(intx,inty);

            frm.Show();
            frm.TopMost = true;
            frm.Width = 400;
            frm.Height = 300;
            frm.Left = 500;
        }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            //calc distance between points
              double dbp = 0;
              if (rbNOP.Checked)
            dbp = m_polyline.Length / (int.Parse(txtNOP.Text) + 1);
              else
            dbp = int.Parse(txtDist.Text);

              m_editor.StartOperation();
              this.Cursor = Cursors.WaitCursor;

              //create points at distance between points up to total length
              for (double d = dbp; d < m_polyline.Length; d += dbp)
              {
            IConstructPoint contructionPoint = new PointClass();
            contructionPoint.ConstructAlong(m_polyline, esriSegmentExtension.esriNoExtension,d,false);
            CreatePoint(contructionPoint as IPoint);
              }

              //create points at start and end of sketch
              if (chkEnds.Checked)
              {
            CreatePoint(m_polyline.FromPoint);
            CreatePoint(m_polyline.ToPoint);
               }

              this.Cursor = Cursors.Default;
              m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtPtsAlongLine"));
              this.Close();
        }
Example #8
0
        /// <summary>
        /// 将字符串格式转化为Geometry
        /// </summary>
        /// <param name="geom">    客户端传递多边形格式 1) x1,y1;x2,y2;x3,y3.......xn,yn;x1,y1;保证起始闭合 为无环
        ///                                            2) x1,y1,flag3;x2,y2,flag3;x3,y3,flag3.......xn,yn,,flagn;
        /// </param>
        /// <returns></returns>
        public static IPolygon BuildPolygon(string geom)
        {
            if (string.IsNullOrEmpty(geom) == true)
            {
                throw new Exception(sErroCoordinatesIsNull);
            }

            string[] points = geom.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (points != null && points.Length > 2)
            {
                int pointCount = points.Length;
                IPolygon polygon = null;
                IPoint point = null;
                object missing = Type.Missing;
                IGeometryCollection pGeoColl = new PolygonClass() as IGeometryCollection;
                IPointCollection pPointCol = new RingClass();
                for (int i = 0; i < pointCount; i++)
                {
                    string[] pts = points[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    point = new PointClass();
                    double x = 0.0;
                    double y = 0.0;
                    int flag = 0;
                    bool bX = double.TryParse(pts[0], out x);
                    bool bY = double.TryParse(pts[1], out y);
                    bool bFlag = int.TryParse(pts[2], out flag);
                    if (bX && bY && bFlag)
                    {
                        pPointCol.AddPoint(point, ref  missing, ref missing);
                        if (flag == -1 || i == (pointCount - 1))
                        {
                            pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                            pPointCol = null;
                            break;
                        }
                        else if (flag == -2)
                        {
                            pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                            pPointCol = new RingClass();
                            continue;
                        }
                    }
                    else
                    {
                        throw new Exception(sErroCoordinatesValueIllegal);
                    }
                }
                if (pPointCol.PointCount > 0)
                {
                    pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                }
                polygon = pGeoColl as IPolygon;
                SimplifyGeometry(polygon);
                return polygon;
            }
            else
            {
                throw new Exception(sErroCoordinatesValueIllegal);
            }
        }
Example #9
0
        private void axPageLayoutControl1_OnDoubleClick(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnDoubleClickEvent e)
        {
            if (e.button == 1)
            {
                //标注的修改
                if (axPageLayoutControl1.CurrentTool == null) return;
                if (((axPageLayoutControl1.CurrentTool) as ICommand).Name == "ControlToolsGraphicElement_SelectTool")
                {
                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(e.pageX, e.pageY);

                    IGraphicsContainer pGraphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;

                    IEnumElement pEnumElement = pGraphicsContainer.LocateElements(pPoint, 10);
                    if (pEnumElement != null)
                    {
                        IElement pElement = pEnumElement.Next();
                        if (pElement is ITextElement)
                        {
                            ITextElement ptextElement = pElement as ITextElement;
                            MapPrint.TextSetUp textSetUp = new MapPrint.TextSetUp();
                            textSetUp.UpdateTextElement(ptextElement);
                            textSetUp.Show();
                        }
                    }

                }
            }
        }
		public SimplePointCursor(string filePath, IFields fields, int OID, 
			System.Array fieldMap, IEnvelope queryEnv, esriGeometryType geomType)	
		{
			//HIGHLIGHT: 0 - Set up cursor
			m_bIsFinished = false;
			m_pStreamReader = new System.IO.StreamReader(filePath);
			m_fields = fields;
			m_iOID = OID;
			m_fieldMap = fieldMap;
			m_searchEnv = queryEnv;
			switch (geomType)
			{
				case esriGeometryType.esriGeometryPolygon:
					m_wkGeom = new Polygon() as IGeometry;
					m_workPts = new PointClass[5];
					for (int i = 0; i < m_workPts.Length; i++)
						m_workPts[i] = new PointClass();
					break;
				case esriGeometryType.esriGeometryPolyline:
					m_wkGeom = new PolylineClass() as IGeometry;
					m_workPts = new PointClass[5];
					for (int i = 0; i < m_workPts.Length; i++)
						m_workPts[i] = new PointClass();
					break;
				
				case esriGeometryType.esriGeometryPoint:
					m_wkGeom = new PointClass() as IGeometry;
					break;
				default:	//doesn't need to set worker geometry if it is table 
					break;
			}

			//advance cursor so data is readily available
			this.NextRecord();
		}
        public static IPoint ConstructPoint2D(double x, double y)
        {
            IPoint point = new PointClass();
            point.X = x;
            point.Y = y;

            return point;
        }
Example #12
0
 /// <summary>
 /// 坐标系转换-----投影坐标系转WGS84
 /// </summary>
 /// <param name="x">x坐标</param>
 /// <param name="y">y坐标</param>
 /// <returns>转换后的IPoint</returns>
 public static IPoint getGeoPoint(double x, double y)
 {
     IPoint pProjPoint = new PointClass();
     pProjPoint.PutCoords(x, y);
     ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
     pProjPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem((int)(esriSRProjCSType.esriSRProjCS_WGS1984UTM_31N));
     pProjPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)(esriSRGeoCSType.esriSRGeoCS_WGS1984)));
     return pProjPoint;      //此时为经纬度点
 }
Example #13
0
        public static IPoint GeographicToTile(double lon, double lat, int zoom)
        {
            // From http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#C.23

            IPoint point = new PointClass();
            point.X = (float)((lon + 180.0) / 360.0 * (1 << zoom));
            point.Y = (float)((1.0 - Math.Log(Math.Tan(lat * Math.PI / 180.0) + 1.0 / Math.Cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << zoom));

            return point;
        }
Example #14
0
        public static IPoint TileToGeographic(int tileX, int tileY, int zoom)
        {
            // From http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#C.23

            IPoint point = new PointClass();
            double n = Math.PI - ((2.0 * Math.PI * tileY) / Math.Pow(2.0, zoom));
            point.X = (float)((tileX / Math.Pow(2.0, zoom) * 360.0) - 180.0);
            point.Y = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n)));
            return point;
        }
Example #15
0
        /// <summary>
        /// Returns NW corner of the tile
        /// </summary>
        /// <param name="tile_x"></param>
        /// <param name="tile_y"></param>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public static IPoint TileToWorldPos(long tile_x, long tile_y, long zoom)
        {
            IPoint p = new PointClass();
            double n = Math.PI - ((2.0 * Math.PI * tile_y) / Math.Pow(2.0, zoom));

            p.X = (float)((tile_x / Math.Pow(2.0, zoom) * 360.0) - 180.0);
            p.Y = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n)));

            return p;
        }
        internal void AddPPGeocodedPoint(double lat, double lng)
        {
            // Set the coordinate system of the data frame.
            ArcMap.Document.ActiveView.FocusMap.SpatialReference = DefineGCS(); 
            ArcMap.Document.ActiveView.Refresh();

            IPoint iPoint = new PointClass();
            // Set the coordinate system of your point to match your data frame
            iPoint.SpatialReference = DefineGCS();
            iPoint.X = lng;
            iPoint.Y = lat;

            IMap map = ArcMap.Document.ActiveView as IMap;
            IGraphicsContainer graphicsContainer = (IGraphicsContainer)map; // Explicit Cast
            IElement element = null;

            // set the point color
            IColor pointColor = new RgbColor();
            //pointColor.RGB = 255255255;
            pointColor.RGB = 255000000;

            // Marker symbols
            ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
            simpleMarkerSymbol.Color = pointColor;
            simpleMarkerSymbol.Outline = true;
            simpleMarkerSymbol.OutlineColor = pointColor;
            simpleMarkerSymbol.Size = 10;
            simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;

            // Marker element
            IMarkerElement markerElement = new MarkerElementClass();
            markerElement.Symbol = simpleMarkerSymbol;
            markerElement.Symbol.Color = pointColor;

            element = (IElement)markerElement; // Explicit Cast

            // set the element name
            IElementProperties3 elemProperties = element as IElementProperties3;
            elemProperties.Name = string.Concat(lng, " ,", lat);
            elemProperties.AnchorPoint = esriAnchorPointEnum.esriCenterPoint;

            // Add the element to a graphics container and refresh the ActiveView
            if (!(element == null))
            {
                element.Geometry = iPoint;
                graphicsContainer.AddElement(element, 0);
                IEnvelope envelope = new EnvelopeClass();
                envelope = ArcMap.Document.ActiveView.Extent;
                envelope.CenterAt(iPoint);
                //ArcMap.Document.ActiveView.Extent = envelope;
                //map.MapScale = 2400;
                map.MapScale = 5000;
                ArcMap.Document.ActiveView.Refresh();
            }
        }
Example #17
0
 static Button1()
 {
     IPoint p1 = null;
     for (int i = 0; i < pntlst.Count - 1; ++i)
     {
         p1 = new PointClass();
         p1.X = pntlst[i];
         p1.Y = pntlst[i + 1];
         pntclassList.Add(p1);
     }
 }
Example #18
0
 private void toolStripButton2_Click(object sender, EventArgs e)
 {
     IPoint pPoint = new PointClass();
     pPoint.PutCoords(Convert.ToDouble(txtlong.Text), Convert.ToDouble(txtlat.Text));
     IEnvelope pEnvelope = new EnvelopeClass();
     pEnvelope = pAxMapControl.Extent;
     //pEnvelope.Expand(10, -10, true);
     pEnvelope.Width = 20;
     pEnvelope.Height = 15;
     pEnvelope.CenterAt(pPoint);
     pAxMapControl.Extent = pEnvelope.Envelope;
     pAxMapControl.FlashShape(pPoint as IGeometry);
 }
Example #19
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            IEnvelope pEnvelope = new EnvelopeClass();
            IPoint pPoint = new PointClass();
            pPoint.PutCoords(Convert.ToDouble(txtlong.Text), Convert.ToDouble(txtlat.Text));

            pEnvelope = pAxMapControl.Extent;
            pEnvelope.CenterAt(pPoint);
            pAxMapControl.Extent = pEnvelope.Envelope;
            pAxMapControl.FlashShape(pPoint as IGeometry);
            //ccc(pPoint);
            //ddd(pPoint);
        }
Example #20
0
        protected override void OnClick()
        {
            //
            //  TODO: Sample code showing how to access button host
            //

            var referenceFactory2 = (ISpatialReferenceFactory2)new SpatialReferenceEnvironment();
            ISpatialReference WGS84 = referenceFactory2.CreateSpatialReference((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            IPointCollection pointCollection = new PolylineClass();

            // ------------- Ensure that both points have negative longitude values -------------------
            IPoint point = new PointClass();
            point.PutCoords(-170, 10); // Equivalent to 170 degrees WEST
            point.SpatialReference = WGS84;
            pointCollection.AddPoint(point);


            point = new PointClass();
            point.PutCoords(-200, 10); // Equivalent to 160 degrees EAST
            point.SpatialReference = WGS84;
            pointCollection.AddPoint(point);
            // -----------------------------------------------------------------------

            IPolyline polyline = (IPolyline)pointCollection;
            polyline.SpatialReference = WGS84;

            var geometryDefEdit = (IGeometryDefEdit)new GeometryDef();
            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            geometryDefEdit.SpatialReference_2 = WGS84;

            var field = (IFieldEdit)new Field();
            field.Name_2 = "Shape";
            field.Type_2 = esriFieldType.esriFieldTypeGeometry;
            field.GeometryDef_2 = geometryDefEdit;

            var fields = (IFieldsEdit)new Fields();
            fields.AddField(field);

            IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
            var featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile("C:\\Temp\\", 0);
            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass
                        ("test3.shp", fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            var feature = featureClass.CreateFeature();
            feature.Shape = polyline;
            feature.Store();


            ArcMap.Application.CurrentTool = null;
        }
        /// <summary>
        /// The main functionality to use Intersection Reverse Geocoding 
        /// </summary>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        private static void ReverseGeocodeIntersection(double X, double Y)
        {
            // Get a locator from the locator Workspace
            System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"));
            ILocatorManager2 locatorManager = obj as ILocatorManager2;
            ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath(@"C:\California_fdb.gdb");
            ILocator locator = locatorWorkspace.GetLocator("California_streets_10");
            IReverseGeocoding reverseGeocoding = locator as IReverseGeocoding;

            // Get the spatial reference from the locator
            IAddressGeocoding addressGeocoding = locator as IAddressGeocoding;
            IFields matchFields = addressGeocoding.MatchFields;
            IField shapeField = matchFields.get_Field(matchFields.FindField("Shape"));
            ISpatialReference spatialReference = shapeField.GeometryDef.SpatialReference;

            // Set up the point from the X and Y values
            IPoint point = new PointClass();
            point.SpatialReference = spatialReference;
            point.X = X;
            point.Y = Y;

            // Set the search tolerance for reverse geocoding
            IReverseGeocodingProperties reverseGeocodingProperties = reverseGeocoding as IReverseGeocodingProperties;
            reverseGeocodingProperties.SearchDistance = 2;
            reverseGeocodingProperties.SearchDistanceUnits = esriUnits.esriKilometers;

            // Determine if the locator supports intersection geocoding.
            // intersectionGeocoding will be null if it is not supported.
            IIntersectionGeocoding intersectionGeocoding = locator as IIntersectionGeocoding;
            if (intersectionGeocoding == null)
            {
                Console.WriteLine("You must use a locator that supports intersections.  Use a locator that was built off of one"
                    + "of the US Streets Locator styles.");
            }
            else
            {
                // Find the intersection that is nearest to the Point
                IPropertySet addressProperties = reverseGeocoding.ReverseGeocode(point, true);

                // Print the intersection properties
                IAddressInputs addressInputs = reverseGeocoding as IAddressInputs;
                IFields addressFields = addressInputs.AddressFields;
                for (int i = 0; i < addressFields.FieldCount; i++)
                {
                    IField addressField = addressFields.get_Field(i);
                    Console.WriteLine(addressField.AliasName + ": " + addressProperties.GetProperty(addressField.Name));
                }
            }
        }
Example #22
0
        bool aimsAt(Point a, Point b, Point c, Point d, PointClass aclass, CrossingClass crossType)
        {
            Point va = new Point(b.X - a.X, b.Y - a.Y);
            Point vb = new Point(d.X - c.X, d.Y - c.Y);

            if (crossType != CrossingClass.COLLINEAR)
            {
                if  ( (va.X * vb.Y) >= (vb.X * va.Y) )
                    return (aclass != PointClass.RIGHT);
                else
                    return (aclass != PointClass.LEFT);
            } else {
                return (aclass != PointClass.BEYOND);
            }
        }
Example #23
0
        private static IPolyline CreatePl()
        {
            Random r = new Random();

            IPointCollection pc = (IPointCollection)new PolylineClass();
            for (int i=0;i<500;i++)
            {
                IPoint p = new PointClass();
                p.X = r.Next(100000);
                p.Y = r.Next(100000);
                object missing = Type.Missing;
                pc.AddPoint(p, ref missing, ref missing);
            }
            return (IPolyline)pc;
        }
    static void Main()
    {
        PointStruct ps = new PointStruct();
        ps.x = ps.y = 22;

        Console.WriteLine("Before method: ps is ({0}, {1})", ps.x, ps.y);
        ChangeStructure(ps);
        Console.WriteLine("After method:  ps is ({0}, {1})", ps.x, ps.y);

        PointClass pc = new PointClass();
        pc.x = pc.y = 22;

        Console.WriteLine("Before method: pc is ({0}, {1})", pc.x, pc.y);
        ChangeClass(pc);
        Console.WriteLine("After method:  pc is ({0}, {1})", pc.x, pc.y);
    }
Example #25
0
 private void drawLineWithText(IPoint startPt, IPoint endPt, string text, bool horizontal)
 {
     IPolyline line = new PolylineClass();
     IPointCollection ptCol = line as IPointCollection;
     ptCol.AddPoint(startPt);
     ptCol.AddPoint(endPt);
     IPoint midPt = new PointClass();
     midPt.X = (startPt.X + endPt.X) / 2;
     midPt.Y = (startPt.Y + endPt.Y) / 2;
     if (horizontal)
     {
         midPt.Y = midPt.Y + textAdjustGap;
     }
     GisUtil.DrawPolyline(line, mapControl);
     GisUtil.drawText(text, midPt, textColor, mapControl);
 }
        public void TestGetGridReferenceCorrectValues(double x, double y, string sRef, string expectedRes)
        {
            BindRunTime();
            IPoint testPoint = new PointClass();
            testPoint.PutCoords(x, y);

            if (sRef == "BNG")
                testPoint.SpatialReference = bngSRef;
            else
                testPoint.SpatialReference = wgs84SRef;

            BNG_Locator bng = new BNG_Locator();
            IPropertySet results = bng.ReverseGeocode(testPoint, false);
            object obj = results.GetProperty("BNG");
            Assert.IsTrue(obj.ToString() == expectedRes);
        }
Example #27
0
        public DataTable SearchByCarLocation(Point centerPoint, double searchRaduis)
        {
            DataTable dtResult = new RealtimeMonite.TrackingDataTableStruct();
            Point oCarLocation = new PointClass();
            MapUtil.MapOperation oMapOper = new GPSTrackingMonitor.MapUtil.MapOperation();

            foreach (DataRow dr in this._realtimeCarInfos.Rows)
            {
                oCarLocation.X = Convert.ToDouble(dr["x"]);
                oCarLocation.Y = Convert.ToDouble(dr["y"]);

                if (oMapOper.ComputeDistance(centerPoint, oCarLocation) <= searchRaduis)
                    dtResult.Rows.Add(dr.ItemArray);
            }

            return dtResult;
        }
        private IGeometry GetGeometry(double longitude, double latitude, double altitudeInKilometers, ISpatialReference spatialReference)
        {
            IGeometry geometry;

            IPoint point = new PointClass();

            point.X = longitude;
            point.Y = latitude;
            point.Z = altitudeInKilometers;

            point.SpatialReference = spatialReference;

            geometry = point as IGeometry;

            MakeZAware(geometry);

            return geometry;
        }
Example #29
0
        /// <summary>
        /// �����ͼ�ĵ�ǰ������
        /// </summary>
        /// <param name="mapControl"></param>
        /// <returns></returns>
        public double ComputeMapScale(AxMapObjects2.AxMap mapControl)
        {
            System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd((System.IntPtr)mapControl.hWnd);

            Point oPoint1 = new PointClass();
            oPoint1.X = mapControl.Extent.Left;
            oPoint1.Y = mapControl.Extent.Top;

            Point oPoint2 = new PointClass();
            oPoint2.X = mapControl.Extent.Right;
            oPoint2.Y =mapControl.Extent.Top;

            double dLen1 = this.ComputeDistance(oPoint1, oPoint2);
            double dLen2 = mapControl.Width / g.DpiX * 2.54 / 100;

            g.Dispose();

            return dLen1 / dLen2;
        }
    static void Main()
    {
        PointStruct ps1 = new PointStruct();
        ps1.x = ps1.y = 55;

        PointStruct ps2 = new PointStruct();
        ps2.x = ps2.y = 55;

        PointClass pc1 = new PointClass();
        pc1.x = pc1.y = 55;

        PointClass pc2 = new PointClass();
        pc2.x = pc2.y = 55;

        Console.WriteLine("ps1.Equals(ps2) results in " + ps1.Equals(ps2));
        Console.WriteLine("ps1.Equals(pc1) results in " + ps1.Equals(pc1));
        Console.WriteLine("pc1.Equals(pc2) results in " + pc1.Equals(pc2));
        Console.WriteLine("pc1 == pc2 results in " + (pc1 == pc2));
        // Console.WriteLine("ps1 == ps2 results in " + (ps1 == ps2));
    }
Example #31
0
 public EventRecord(System.UInt16 index, PointClass clazz)
     : base(index)
 {
     this.clazz = clazz;
 }
Example #32
0
 public DeadbandRecord(System.UInt16 index, PointClass pointClass) : base(index, pointClass)
 {
     this.deadband = default(T);
 }
Example #33
0
        public void TestMultipart()
        {
            IFeatureWorkspace ws         = TestWorkspaceUtils.CreateInMemoryWorkspace("TestMultipart");
            IFieldsEdit       lineFields = new FieldsClass();

            lineFields.AddField(FieldUtils.CreateOIDField());
            lineFields.AddField(FieldUtils.CreateTextField("FromVal", 50));
            lineFields.AddField(FieldUtils.CreateTextField("ToVal", 50));
            lineFields.AddField(FieldUtils.CreateShapeField(
                                    "Shape", esriGeometryType.esriGeometryPolyline,
                                    SpatialReferenceUtils.CreateSpatialReference
                                        ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                        true), 1000));

            IFeatureClass lineFc = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestFieldValuesExpression1", lineFields);

            IFieldsEdit pointFields = new FieldsClass();

            pointFields.AddField(FieldUtils.CreateOIDField());
            pointFields.AddField(FieldUtils.CreateTextField("Name", 50));
            pointFields.AddField(FieldUtils.CreateShapeField(
                                     "Shape", esriGeometryType.esriGeometryPoint,
                                     SpatialReferenceUtils.CreateSpatialReference
                                         ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                         true), 1000));

            IFeatureClass pointFc = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestFieldValuesExpression2", pointFields);

            IPoint center = new PointClass();

            center.PutCoords(200, 200);

            IFeature row1 = lineFc.CreateFeature();

            row1.set_Value(1, "Name");
            row1.set_Value(2, "AndererName");
            row1.Shape =
                CurveConstruction.StartLine(100, 100).LineTo(200, 160).MoveTo(100, 160)
                .LineTo(center).Curve;
            row1.Store();

            IFeature row2 = lineFc.CreateFeature();

            row2.set_Value(1, "Name");
            row2.Shape = CurveConstruction
                         .StartLine(200, 100).LineTo(300, 140).MoveTo(200, 160).LineTo(center)
                         .Curve;
            row2.Store();

            IFeature row3 = lineFc.CreateFeature();

            row3.set_Value(1, "Name");
            row3.Shape = CurveConstruction
                         .StartLine(300, 100).LineTo(300, 140).MoveTo(300, 160).LineTo(center)
                         .Curve;
            row3.Store();

            IFeature row4 = pointFc.CreateFeature();

            row4.set_Value(1, "AndererName");
            row4.Shape = center;
            row4.Store();

            string lineField = $"IIF({QaConnections.StartsIn}, FromVal, ToVal)";
            var    test      = new QaLineConnectionFieldValues(
                lineFc, lineField,
                LineFieldValuesConstraint.AllEqualOrValidPointExists,
                pointFc, "Name",
                PointFieldValuesConstraint.AllEqualAndMatchAnyLineValue);

            test.UseMultiParts = false;
            var runner = new QaContainerTestRunner(500, test);

            Assert.AreEqual(0, runner.Execute());

            test.UseMultiParts = true;
            runner             = new QaContainerTestRunner(500, test);
            Assert.AreEqual(1, runner.Execute());
        }
        //保存应急处置空间位置的信息
        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.Text == "")
                {
                    MessageBox.Show("请输入可供选择的应急处置空间位置的数据", "输入可供选择的应急处置空间位置的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox2.Text == "")
                {
                    MessageBox.Show("请输入河流流速的数据", "输入河流流速的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox3.Text == "")
                {
                    MessageBox.Show("请输入河流流量的数据", "输入河流流量的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox4.Text == "")
                {
                    MessageBox.Show("请输入河流宽度的数据", "输入河流宽度的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox5.Text == "")
                {
                    MessageBox.Show("请输入河流污染物浓度的数据", "输入河流污染物浓度的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else if (comboBox6.Text == "")
                {
                    MessageBox.Show("请输入河流总量的数据", "输入河流污染物总量的数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else
                {
                    IRasterLayer   pVRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox2.Text);
                    IRasterLayer   pQRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox3.Text);
                    IRasterLayer   pLRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox4.Text);
                    IRasterLayer   pCRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox5.Text);
                    IRasterLayer   pSRasterLayer      = CDataImport.ImportRasterLayerFromControltext(comboBox6.Text);
                    IFeatureLayer  pFeatureLayerSave  = CDataImport.ImportFeatureLayerFromControltext(comboBox1.Text);
                    IFeatureClass  pFeatureClassSave  = pFeatureLayerSave.FeatureClass;
                    IFeatureCursor pFeatureCursorSave = pFeatureClassSave.Update(null, false);
                    IFeature       pFeatureSave       = pFeatureCursorSave.NextFeature();
                    IPoint         point = new PointClass();
                    double         X = 0.0, Y = 0.0;
                    int            column = 0, row = 0;
                    while (pFeatureSave != null)
                    {
                        point = pFeatureSave.Shape as IPoint;
                        X     = point.X;
                        Y     = point.Y;
                        RasterManagement.XYconvertNumber(pVRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("V"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pVRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pQRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("Q"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pQRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pLRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("L"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pLRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pCRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("C"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pCRasterLayer, 0, column, row)), 4));

                        RasterManagement.XYconvertNumber(pSRasterLayer, X, Y, ref column, ref row);
                        pFeatureSave.set_Value(pFeatureSave.Fields.FindField("S"), Math.Round(Convert.ToDouble(RasterManagement.GetPixelValue(pSRasterLayer, 0, column, row)), 4));

                        pFeatureCursorSave.UpdateFeature(pFeatureSave);
                        pFeatureSave = pFeatureCursorSave.NextFeature();
                    }

                    MessageBox.Show("程序运行完成!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
            }
        }
Example #35
0
        //TextSymbol
        private void button18_Click(object sender, EventArgs e)
        {
            ITextSymbol textSymbol = new TextSymbolClass();

            System.Drawing.Font drawFont = new System.Drawing.Font("宋体", 16, FontStyle.Bold);
            stdole.IFontDisp    fontDisp = (stdole.IFontDisp)(new stdole.StdFontClass());
            textSymbol.Font  = fontDisp;
            textSymbol.Color = getRGB(0, 255, 0);
            textSymbol.Size  = 20;
            IPolyline polyline = new PolylineClass();
            IPoint    point    = new PointClass();

            point.PutCoords(1, 1);
            polyline.FromPoint = point;
            point.PutCoords(10, 10);
            polyline.ToPoint = point;
            ITextPath textPath = new BezierTextPathClass();
            //创建简单标注
            ILineSymbol lineSymbol = new SimpleLineSymbolClass();

            lineSymbol.Color = getRGB(255, 0, 0);
            lineSymbol.Width = 5;
            ISimpleTextSymbol simpleTextSymbol = textSymbol as ISimpleTextSymbol;

            simpleTextSymbol.TextPath = textPath;
            object      oLineSymbol = lineSymbol;
            object      oTextSymbol = textSymbol;
            IActiveView activeView  = this.axMapControl1.ActiveView;

            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(oLineSymbol as ISymbol);
            activeView.ScreenDisplay.DrawPolyline(polyline as IGeometry);
            activeView.ScreenDisplay.SetSymbol(oTextSymbol as ISymbol);
            activeView.ScreenDisplay.DrawText(polyline as IGeometry, "简单标注");;
            activeView.ScreenDisplay.FinishDrawing();

            //创建气泡标注(两中风格,一种是有锚点,一种是marker方式)
            //锚点方式
            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();

            simpleFillSymbol.Color = getRGB(0, 255, 0);
            simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
            IBalloonCallout balloonCallout = new BalloonCalloutClass();

            balloonCallout.Style           = esriBalloonCalloutStyle.esriBCSRectangle;
            balloonCallout.Symbol          = simpleFillSymbol;
            balloonCallout.LeaderTolerance = 10;

            point.PutCoords(5, 5);
            balloonCallout.AnchorPoint = point;

            IGraphicsContainer   graphicsContainer   = activeView as IGraphicsContainer;
            IFormattedTextSymbol formattedTextSymbol = new TextSymbolClass();

            formattedTextSymbol.Color = getRGB(0, 0, 255);
            point.PutCoords(10, 5);
            ITextBackground textBackground = balloonCallout as ITextBackground;

            formattedTextSymbol.Background = textBackground;
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(formattedTextSymbol as ISymbol);
            activeView.ScreenDisplay.DrawText(point as IGeometry, "气泡1");
            activeView.ScreenDisplay.FinishDrawing();


            //marker方式
            textSymbol                     = new TextSymbolClass();
            textSymbol.Color               = getRGB(255, 0, 0);
            textSymbol.Angle               = 0;
            textSymbol.RightToLeft         = false;
            textSymbol.VerticalAlignment   = esriTextVerticalAlignment.esriTVABaseline;
            textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;


            IMarkerTextBackground markerTextBackground = new MarkerTextBackgroundClass();

            markerTextBackground.ScaleToFit = true;
            markerTextBackground.TextSymbol = textSymbol;

            IRgbColor            rgbColor            = new RgbColorClass();
            IPictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbolClass();
            //string fileName = @"E:\vs2005\第五章\lesson2\lesson2\data\qq.bmp";
            string path     = Directory.GetCurrentDirectory();
            string fileName = path + @"\qq.bmp";

            pictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, fileName);
            pictureMarkerSymbol.Angle = 0;
            pictureMarkerSymbol.BitmapTransparencyColor = rgbColor;
            pictureMarkerSymbol.Size    = 20;
            pictureMarkerSymbol.XOffset = 0;
            pictureMarkerSymbol.YOffset = 0;

            markerTextBackground.Symbol = pictureMarkerSymbol as IMarkerSymbol;

            formattedTextSymbol       = new TextSymbolClass();
            formattedTextSymbol.Color = getRGB(255, 0, 0);
            fontDisp.Size             = 10;
            fontDisp.Bold             = true;
            formattedTextSymbol.Font  = fontDisp;

            point.PutCoords(15, 5);

            formattedTextSymbol.Background = markerTextBackground;
            activeView.ScreenDisplay.StartDrawing(activeView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
            activeView.ScreenDisplay.SetSymbol(formattedTextSymbol as ISymbol);
            activeView.ScreenDisplay.DrawText(point as IGeometry, "气泡2");
            activeView.ScreenDisplay.FinishDrawing();
        }
Example #36
0
        public IFeatureClass CreatePointFeatureClass(IFeatureDataset pFeatureDataset, CParkPoint xml)
        {
            try
            {
                //建立shape字段
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //设置Geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGeometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint; //点、线、面
                pGeometryDefEdit.SpatialReference_2 = ClsGDBDataCommon.CreateProjectedCoordinateSystem();
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //新建字段
                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "SzID";       //代号
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "Changed";       //停泊点类型是否改变
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "Symbol";       //停泊点类型
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "BegineTime";       //到达停泊点时间
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "LeaveTime";       //离开停泊点时间
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "太阳方位角";       //太阳方位角
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "地球方位角";       //地球方位角
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "WorkModeNum";       //离开停泊点时间
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeSmallInteger;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                for (int i = 0; i <= 7; i++)
                {
                    pField                  = new FieldClass();
                    pFieldEdit              = (IFieldEdit)pField;
                    pFieldEdit.Name_2       = "Mode_" + i.ToString() + "_symbol";     //第i工作模式名称
                    pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                    pFieldEdit.IsNullable_2 = true;
                    pFieldsEdit.AddField(pField);

                    //pField = new FieldClass();
                    //pFieldEdit = (IFieldEdit)pField;
                    //pFieldEdit.Name_2 = "Mode_" + i.ToString() + "_Name";             //第i工作模式名称
                    //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    //pFieldEdit.IsNullable_2 = true;
                    //pFieldsEdit.AddField(pField);

                    pField                  = new FieldClass();
                    pFieldEdit              = (IFieldEdit)pField;
                    pFieldEdit.Name_2       = "Mode_" + i.ToString() + "_Slice";       //第i工作模式固有时长
                    pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                    pFieldEdit.IsNullable_2 = true;
                    pFieldsEdit.AddField(pField);

                    pField                  = new FieldClass();
                    pFieldEdit              = (IFieldEdit)pField;
                    pFieldEdit.Name_2       = "Mode_" + i.ToString() + "_AssSlice";       //第i工作模式分配时长
                    pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                    pFieldEdit.IsNullable_2 = true;
                    pFieldsEdit.AddField(pField);

                    pField                  = new FieldClass();
                    pFieldEdit              = (IFieldEdit)pField;
                    pFieldEdit.Name_2       = "Mode_" + i.ToString() + "_BeginTime";       //第i工作模式开始时刻
                    pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                    pFieldEdit.IsNullable_2 = true;
                    pFieldsEdit.AddField(pField);

                    pField                  = new FieldClass();
                    pFieldEdit              = (IFieldEdit)pField;
                    pFieldEdit.Name_2       = "Mode_" + i.ToString() + "_EndTime";       //第i工作模式结束时刻
                    pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                    pFieldEdit.IsNullable_2 = true;
                    pFieldsEdit.AddField(pField);

                    //pField = new FieldClass();
                    //pFieldEdit = (IFieldEdit)pField;
                    //pFieldEdit.Name_2 = "Mode_" + i.ToString() + "_Energy";             //第i工作模式结束能量
                    //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                    //pFieldEdit.IsNullable_2 = true;
                    //pFieldsEdit.AddField(pField);
                }

                IFeatureClass pFeatureClass = pFeatureDataset.CreateFeatureClass(textBoxX3.Text + "_parkpoint", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                for (int j = 0; j < xml.uiParkNum; j++)
                {
                    IPoint pPoint = new PointClass();
                    pPoint.X = xml.ParkSList[j].stCoord.dx;
                    pPoint.Y = xml.ParkSList[j].stCoord.dy;
                    IFeature pFeature = pFeatureClass.CreateFeature();
                    pFeature.Shape = pPoint;
                    pFeature.Store();
                    AddAttributeTable(pFeature, xml.ParkSList[j], j);
                }
                return(pFeatureClass);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(null);
            }
        }
        private CoordinateType GetCoordinateType(string input, out ESRI.ArcGIS.Geometry.IPoint point)
        {
            point = new PointClass();
            var  cn = point as IConversionNotation;
            Type t  = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");

            System.Object            obj    = Activator.CreateInstance(t);
            ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory;

            // Use the enumeration to create an instance of the predefined object.

            IGeographicCoordinateSystem geographicCS =
                srFact.CreateGeographicCoordinateSystem((int)
                                                        esriSRGeoCSType.esriSRGeoCS_WGS1984);

            point.SpatialReference = geographicCS;
            string numSep = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            input = numSep != "." ? input.Replace(numSep, ".") : input;

            try
            {
                CoordinateDD dd;
                if (CoordinateDD.TryParse(input, out dd))
                {
                    // Reformat the string for cases where lat/lon have been switched
                    // PutCoords calls fail if the double uses decimal separator other than a decimal point
                    // Added InvariantCulture option to ensure the current culture is ignored
                    string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1}", dd.Lat, dd.Lon);
                    cn.PutCoordsFromDD(newInput);

                    return(CoordinateType.DD);
                }
            }
            catch { }

            try
            {
                CoordinateDDM ddm;
                if (CoordinateDDM.TryParse(input, out ddm))
                {
                    // Reformat the string for cases where lat/lon have been switched
                    // PutCoords calls fail if the double uses decimal separator other than a decimal point
                    // Added InvariantCulture option to ensure the current culture is ignored
                    string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", ddm.LatDegrees, ddm.LatMinutes, ddm.LonDegrees, ddm.LonMinutes);
                    cn.PutCoordsFromDD(newInput);

                    return(CoordinateType.DDM);
                }
            }
            catch { }

            try
            {
                CoordinateDMS dms;
                if (CoordinateDMS.TryParse(input, out dms))
                {
                    // Reformat the string for cases where lat/lon have been switched
                    // PutCoords calls fail if the double uses decimal separator other than a decimal point
                    // Added InvariantCulture option to ensure the current culture is ignored
                    string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3} {4} {5}", dms.LatDegrees, dms.LatMinutes, dms.LatSeconds, dms.LonDegrees, dms.LonMinutes, dms.LonSeconds);
                    cn.PutCoordsFromDD(newInput);

                    return(CoordinateType.DMS);
                }
            }
            catch { }

            try
            {
                cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeCENTER, input);
                return(CoordinateType.GARS);
            }
            catch { }

            try
            {
                cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeLL, input);
                return(CoordinateType.GARS);
            }
            catch { }

            CoordinateGARS gars;

            if (CoordinateGARS.TryParse(input, out gars))
            {
                try
                {
                    cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeCENTER, gars.ToString("", new CoordinateGARSFormatter()));
                    return(CoordinateType.GARS);
                }
                catch { }
            }

            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_Automatic);
                return(CoordinateType.MGRS);
            }
            catch { }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_NewStyle);
                return(CoordinateType.MGRS);
            }
            catch { }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_NewWith180InZone01);
                return(CoordinateType.MGRS);
            }
            catch { }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_OldStyle);
                return(CoordinateType.MGRS);
            }
            catch { }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_OldWith180InZone01);
                return(CoordinateType.MGRS);
            }
            catch { }

            // mgrs try parse
            CoordinateMGRS mgrs;

            if (CoordinateMGRS.TryParse(input, out mgrs))
            {
                try
                {
                    cn.PutCoordsFromMGRS(mgrs.ToString("", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_NewStyle);
                    return(CoordinateType.MGRS);
                }
                catch { }
            }

            try
            {
                cn.PutCoordsFromUSNG(input);
                return(CoordinateType.USNG);
            }
            catch { }

            CoordinateUSNG usng;

            if (CoordinateUSNG.TryParse(input, out usng))
            {
                try
                {
                    cn.PutCoordsFromUSNG(usng.ToString("", new CoordinateMGRSFormatter()));
                    return(CoordinateType.USNG);
                }
                catch { }
            }

            try
            {
                cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMAddSpaces, input);
                return(CoordinateType.UTM);
            }
            catch { }

            try
            {
                cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMNoOptions, input);
                return(CoordinateType.UTM);
            }
            catch { }

            try
            {
                cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMUseNS, input);
                return(CoordinateType.UTM);
            }
            catch { }

            CoordinateUTM utm;

            if (CoordinateUTM.TryParse(input, out utm))
            {
                try
                {
                    cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMNoOptions, utm.ToString("", new CoordinateUTMFormatter()));
                    return(CoordinateType.UTM);
                }
                catch { }
            }

            Regex regexMercator = new Regex(@"^(?<latitude>\-?\d+[.,]?\d*)[+,;:\s]*(?<longitude>\-?\d+[.,]?\d*)");

            var matchMercator = regexMercator.Match(input);

            if (matchMercator.Success && matchMercator.Length == input.Length)
            {
                try
                {
                    var  Lat = Double.Parse(matchMercator.Groups["latitude"].Value);
                    var  Lon = Double.Parse(matchMercator.Groups["longitude"].Value);
                    IMap map = ((IMxDocument)ArcMap.Application.Document).FocusMap;
                    var  sr  = map.SpatialReference != null ? map.SpatialReference : ArcMapHelpers.GetSR((int)esriSRProjCS3Type.esriSRProjCS_WGS1984WebMercatorMajorAuxSphere);
                    point.X = Lon;
                    point.Y = Lat;
                    point.SpatialReference = sr;
                    return(CoordinateType.DD);
                }
                catch (Exception ex)
                {
                    // do nothing
                }
            }

            return(CoordinateType.Unknown);
        }
Example #38
0
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            DF2DApplication app = DF2DApplication.Application;

            this._dict.Clear();
            bool ready = true;

            if (app == null || app.Current2DMapControl == null || app.Workbench == null)
            {
                return;
            }
            app.Workbench.SetMenuEnable(true);
            m_ActiveView = app.Current2DMapControl.ActiveView;
            IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay;

            try
            {
                if (button == 1)
                {
                    ISimpleLineSymbol pLineSym = new SimpleLineSymbol();
                    IRgbColor         pColor   = new RgbColorClass();
                    pColor.Red     = 255;
                    pColor.Green   = 255;
                    pColor.Blue    = 0;
                    pLineSym.Color = pColor;
                    pLineSym.Style = esriSimpleLineStyle.esriSLSSolid;
                    pLineSym.Width = 2;

                    ISimpleFillSymbol pFillSym = new SimpleFillSymbol();

                    pFillSym.Color   = pColor;
                    pFillSym.Style   = esriSimpleFillStyle.esriSFSDiagonalCross;
                    pFillSym.Outline = pLineSym;

                    object      symbol = pFillSym as object;
                    IRubberBand band   = new RubberRectangularPolygonClass();
                    IGeometry   pGeo   = band.TrackNew(m_Display, null);
                    app.Current2DMapControl.DrawShape(pGeo, ref symbol);
                    WaitForm.Start("正在查询...", "请稍后");
                    if (pGeo.IsEmpty)
                    {
                        IPoint searchPoint = new PointClass();
                        searchPoint.PutCoords(mapX, mapY);
                        pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate));
                        //m_ActiveView.FocusMap.SelectByShape(geo, s, false);
                    }
                    if (ready)
                    {
                        //foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups)
                        //{
                        foreach (MajorClass mc in FrmMajorClass.Instance.MajorClasses)
                        {
                            foreach (SubClass sc in mc.SubClasses)
                            {
                                if (!sc.Visible2D)
                                {
                                    continue;
                                }
                                string[] arrFc2DId = mc.Fc2D.Split(';');
                                if (arrFc2DId == null)
                                {
                                    continue;
                                }
                                IFeatureCursor pFeatureCursor = null;
                                IFeature       pFeature       = null;
                                foreach (string fc2DId in arrFc2DId)
                                {
                                    DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                                    if (dffc == null)
                                    {
                                        continue;
                                    }
                                    IFeatureClass fc   = dffc.GetFeatureClass();
                                    FacilityClass facc = dffc.GetFacilityClass();
                                    if (facc.Name != "PipeLine")
                                    {
                                        continue;
                                    }
                                    if (fc == null || pGeo == null)
                                    {
                                        continue;
                                    }
                                    ISpatialFilter pSpatialFilter = new SpatialFilter();
                                    pSpatialFilter.Geometry   = pGeo;
                                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                    string whereClause = UpOrDown.DecorateWhereClasuse(fc) + mc.ClassifyField + " =  '" + sc.Name + "'";

                                    pSpatialFilter.WhereClause = whereClause;
                                    pFeatureCursor             = fc.Search(pSpatialFilter, false);
                                    if (pFeatureCursor == null)
                                    {
                                        continue;
                                    }
                                    DataTable dt = new DataTable();
                                    dt.TableName = facc.Name;
                                    DataColumn oidcol = new DataColumn();
                                    oidcol.ColumnName = "oid";
                                    oidcol.Caption    = "ID";
                                    dt.Columns.Add(oidcol);
                                    foreach (DFDataConfig.Class.FieldInfo fitemp in facc.FieldInfoCollection)
                                    {
                                        if (!fitemp.CanQuery)
                                        {
                                            continue;
                                        }
                                        DataColumn col = new DataColumn();
                                        col.ColumnName = fitemp.Name;
                                        col.Caption    = fitemp.Alias;
                                        dt.Columns.Add(col);
                                    }
                                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                                    {
                                        DataRow dtRow = dt.NewRow();
                                        dtRow["oid"] = pFeature.get_Value(pFeature.Fields.FindField("OBJECTID"));
                                        foreach (DataColumn col in dt.Columns)
                                        {
                                            int index1 = pFeature.Fields.FindField(col.ColumnName);
                                            if (index1 < 0)
                                            {
                                                continue;
                                            }
                                            object obj1 = pFeature.get_Value(index1);
                                            string str  = "";
                                            if (obj1 != null)
                                            {
                                                IField field = pFeature.Fields.get_Field(index1);
                                                switch (field.Type)
                                                {
                                                case esriFieldType.esriFieldTypeBlob:
                                                case esriFieldType.esriFieldTypeGeometry:
                                                case esriFieldType.esriFieldTypeRaster:
                                                    continue;

                                                case esriFieldType.esriFieldTypeDouble:

                                                    double d;
                                                    if (double.TryParse(obj1.ToString(), out d))
                                                    {
                                                        str = d.ToString("0.00");
                                                    }
                                                    break;

                                                default:
                                                    str = obj1.ToString();
                                                    break;
                                                }
                                            }
                                            dtRow[col.ColumnName] = str;
                                        }
                                        dt.Rows.Add(dtRow);
                                    }
                                    if (dt.Rows.Count > 0)
                                    {
                                        this._dict.Add(sc.Name, dt);
                                    }
                                }
                            }
                        }
                    }
                    WaitForm.Stop();
                    try
                    {
                        this._uPanel               = new UIDockPanel("查询结果", "查询结果", this.Location, this._width, this._height);
                        this._dockPanel            = FloatPanelManager.Instance.Add(ref this._uPanel, DockingStyle.Right);
                        this._dockPanel.Visibility = DockVisibility.Visible;
                        this._dockPanel.FloatSize  = new System.Drawing.Size(this._width, this._height);
                        this._dockPanel.Width      = this._width;
                        this._dockPanel.Height     = this._height;
                        if (this._ucPropInfo2D == null)
                        {
                            this._ucPropInfo2D = new UCPropertyInfo2D();
                        }
                        this._ucPropInfo2D.Dock = System.Windows.Forms.DockStyle.Fill;
                        this._uPanel.RegisterEvent(new PanelClose(this.Close));
                        this._dockPanel.Controls.Add(this._ucPropInfo2D);
                        this._ucPropInfo2D.Init();
                        this._ucPropInfo2D.SetPropertyInfo(this._dict);
                    }
                    catch
                    {
                    }
                }
                //}
            }
            catch
            {
            }
            finally
            {
                WaitForm.Stop();
            }
        }
Example #39
0
        public void FlashFeature(IFeature pFeature, IMapControlDefault pMapControl)
        {
            IActiveView pActiveView = pMapControl.ActiveView;

            IEnvelope pEnvSmall  = pFeature.Shape.Envelope;
            IEnvelope pEnvScreen = pActiveView.Extent;

            IPoint pPointCenter = new PointClass();

            pPointCenter.PutCoords((pEnvSmall.XMax + pEnvSmall.XMin) / 2, (pEnvSmall.YMax + pEnvSmall.YMin) / 2);

            IPoint pPointXMax = new PointClass();

            pPointXMax.PutCoords(pEnvScreen.XMax, pPointCenter.Y);


            IPoint pPointXMaxSmall = new PointClass();

            pPointXMaxSmall.PutCoords(pEnvSmall.XMax, pPointCenter.Y);


            IPoint pPointXMin = new PointClass();

            pPointXMin.PutCoords(pEnvScreen.XMin, pPointCenter.Y);
            IPoint pPointXMinSmall = new PointClass();

            pPointXMinSmall.PutCoords(pEnvSmall.XMin, pPointCenter.Y);

            IPoint pPointYMax = new PointClass();

            pPointYMax.PutCoords(pPointCenter.X, pEnvScreen.YMax);
            IPoint pPointYMaxSmall = new PointClass();

            pPointYMaxSmall.PutCoords(pPointCenter.Y, pEnvSmall.YMax);

            IPoint pPointYMin = new PointClass();

            pPointYMin.PutCoords(pPointCenter.X, pEnvScreen.YMin);
            IPoint pPointYMinSmall = new PointClass();

            pPointYMinSmall.PutCoords(pPointCenter.Y, pEnvSmall.YMin);

            for (int i = 0; i < 13; i++)
            {
                IPolyline pLineXMax = new PolylineClass();
                pLineXMax.FromPoint = pPointXMax;
                IPoint pPointTo = new PointClass();
                double xMax     = pPointXMax.X + Convert.ToInt32((pPointXMaxSmall.X - pPointXMax.X) * i / 13);

                pPointTo.PutCoords(xMax, pPointCenter.Y);
                pLineXMax.ToPoint = pPointTo;

                IPolyline pLineXMin = new PolylineClass();
                pLineXMin.FromPoint = pPointXMin;
                double xMin = pPointXMin.X + (pPointXMinSmall.X - pPointXMin.X) * i / 13;

                pPointTo.PutCoords(xMin, pPointCenter.Y);
                pLineXMin.ToPoint = pPointTo;

                IPolyline pLineYMin = new PolylineClass();
                pLineYMin.FromPoint = pPointYMin;
                double yMin = pPointYMin.Y + (pPointYMinSmall.Y - pPointYMin.Y) * i / 13;
                pPointTo.PutCoords(pPointYMin.X, yMin);
                pLineYMin.ToPoint = pPointTo;

                IPolyline pLineYMax = new PolylineClass();
                pLineYMax.FromPoint = pPointYMax;
                double yMax = pPointYMax.Y + (pPointYMaxSmall.Y - pPointYMax.Y) * i / 13;
                pPointTo.PutCoords(pPointYMax.X, yMax);
                pLineYMax.ToPoint = pPointTo;

                IGeometryCollection pGeoColl = new PolylineClass();
                object obj = Type.Missing;

                IPath pPath = new PathClass();
                pPath.FromPoint = pLineXMax.FromPoint;
                pPath.ToPoint   = pLineXMax.ToPoint;
                pGeoColl.AddGeometry(pPath, ref obj, ref obj);

                pPath           = new PathClass();
                pPath.FromPoint = pLineXMin.FromPoint;
                pPath.ToPoint   = pLineXMin.ToPoint;
                pGeoColl.AddGeometry(pPath, ref obj, ref obj);

                pPath           = new PathClass();
                pPath.FromPoint = pLineYMax.FromPoint;
                pPath.ToPoint   = pLineYMax.ToPoint;
                pGeoColl.AddGeometry(pPath, ref obj, ref obj);

                pPath           = new PathClass();
                pPath.FromPoint = pLineYMin.FromPoint;
                pPath.ToPoint   = pLineYMin.ToPoint;
                pGeoColl.AddGeometry(pPath, ref obj, ref obj);

                FlashFeature(pGeoColl as IGeometry, pActiveView, 5);
            }

            pMapControl.FlashShape(pFeature.Shape, 2, 500, null);
        }
Example #40
0
        public override void OnMouseMove(int button, int shift, int x, int y, double mapX, double mapY)
        {
            // TODO:  添加 DrawArcCenRadFATA.OnMouseMove 实现
            base.OnMouseMove(button, shift, x, y, mapX, mapY);


            m_pPoint = m_pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            m_pAnchorPoint = m_pPoint;

            //+++++++++++++开始捕捉+++++++++++++++++++++
            bool flag = CommonFunction.Snap(m_MapControl, m_App.CurrentConfig.cfgSnapEnvironmentSet, null, m_pAnchorPoint);

            if (m_pLastPoint != null)
            {
                //########################平行尺########################
                CommonFunction.ParallelRule(ref m_bKeyCodeP, m_pActiveView, m_dblTolerance, ref m_pSegment, m_pLastPoint, m_pPoint, ref m_pAnchorPoint);

                //&&&&&&&&&&&&&&&&&&&&&&&& 正 交 &&&&&&&&&&&&&&&&&&&&&&&
                CommonFunction.PositiveCross(m_pLastPoint, ref m_pAnchorPoint, m_App.CurrentConfig.cfgPositiveCross.IsPositiveCross);
            }

            if (pLineArray.Count >= 1)
            {
                if (m_pFeedback != null)
                {
                    m_pFeedback.Display = m_pActiveView.ScreenDisplay;
                }
                m_pFeedback.MoveTo(m_pAnchorPoint);
            }

            if (m_bInUse)
            {
                pLineArray.Add(m_pAnchorPoint);

                if (pLineArray.Count >= 3)
                {
                    IPoint pPoint1 = (IPoint)pLineArray.get_Element(1);
                    IPoint p0      = (IPoint)pLineArray.get_Element(0);
                    IPoint pPoint3 = (IPoint)pLineArray.get_Element(pLineArray.Count - 1);

                    //计算半径
                    m_R = CommonFunction.GetDistance_P12(pPoint1, p0);

                    //计算p0到起点p1的方位角和到端点的方位角
                    double Ap01;
                    double Ap03;

                    Ap01 = CommonFunction.GetAzimuth_P12(p0, pPoint1);
                    Ap03 = CommonFunction.GetAzimuth_P12(p0, pPoint3);
                    //计算端点坐标
                    pPoint3.X = p0.X + m_R * Math.Cos(Ap03);
                    pPoint3.Y = p0.Y + m_R * Math.Sin(Ap03);

                    //计算圆心角
                    m_Ca = Ap03 - Ap01;

                    if (m_Ca < 0)
                    {
                        m_Ca = m_Ca + 2 * Math.PI;
                    }

                    m_pLineFeed.Stop();
                    m_pLineFeed.Start(pPoint1);
                    IPoint pm = new PointClass();
                    for (int i = 0; i <= m_Ca / CommonFunction.DegToRad(5) - 1; i++)
                    {
                        pm.X = p0.X + m_R * Math.Cos(Ap01 + CommonFunction.DegToRad(5 * (i + 1)));
                        pm.Y = p0.Y + m_R * Math.Sin(Ap01 + CommonFunction.DegToRad(5 * (i + 1)));
                        m_pLineFeed.AddPoint(pm);
                    }

                    m_pLineFeed.AddPoint(pPoint3);
                }
            }
        }
Example #41
0
        //地图控件鼠标点击事件;;
        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            switch (index._tool_lable)
            {
            //漫游
            case PublicMark.ButtonFunction.roam: axMapControl1.Pan(); break;

            //   测量
            case PublicMark.ButtonFunction.measure:
                MessageBox.Show("测量功能尚未完善!"); break;

            //识别
            case PublicMark.ButtonFunction.distinguish:
                if (e.button == 1)
                {
                    IPoint pt = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

                    IGeometry Geometry = pt as IGeometry;

                    IMap map = axMapControl1.Map;

                    ISelectionEnvironment SelectionEnvironment = new SelectionEnvironment();
                    IRgbColor             color = new RgbColor();
                    color.Red = 233;
                    SelectionEnvironment.DefaultColor = color;
                    map.SelectByShape(Geometry, SelectionEnvironment, false);
                    axMapControl1.ActiveView.Refresh();

                    if (axMapControl1.Map.SelectionCount <= 0)
                    {
                        return;
                    }
                    Form distinguish = new Distinguish(CreateDataTable(axMapControl1)); //显示识别窗体,并把选择属性创建成表;
                    distinguish.Location = Control.MousePosition;                       //;窗体位置
                    distinguish.ShowDialog();
                }
                break;

            //按位置选择
            case PublicMark.ButtonFunction.TrackCircle: HightRight(axMapControl1, axMapControl1.TrackCircle());
                break;

            //按位置选择
            case PublicMark.ButtonFunction.TrackLine: HightRight(axMapControl1, axMapControl1.TrackLine());
                break;

            //按位置选择
            case PublicMark.ButtonFunction.TrackRectangle: HightRight(axMapControl1, axMapControl1.TrackRectangle());
                break;

            //按位置选择
            case PublicMark.ButtonFunction.TrackPolygon: HightRight(axMapControl1, axMapControl1.TrackPolygon());
                break;

            //局部放大功能;
            case PublicMark.ButtonFunction.enlarge:
                IEnvelope envelope = axMapControl1.TrackRectangle();
                axMapControl1.ActiveView.Extent = envelope;
                axMapControl1.ActiveView.Refresh();
                break;

            case PublicMark.ButtonFunction.narrow:
                IEnvelope envelope_1 = axMapControl1.TrackRectangle();
                double    dWidth     = Math.Pow(axMapControl1.ActiveView.Extent.Width, 2) / envelope_1.Width;
                double    dHeight    = Math.Pow(axMapControl1.ActiveView.Extent.Height, 2) / envelope_1.Height;
                double    dXmin      = axMapControl1.ActiveView.Extent.XMin - ((envelope_1.XMin - axMapControl1.ActiveView.Extent.XMin) * axMapControl1.ActiveView.Extent.Width / envelope_1.Width);
                double    dYmin      = axMapControl1.ActiveView.Extent.YMin - ((envelope_1.YMin - axMapControl1.ActiveView.Extent.YMin) * axMapControl1.ActiveView.Extent.Height / envelope_1.Height);
                double    dXMax      = dWidth + dXmin;
                double    dYMax      = dHeight + dYmin;
                envelope_1.PutCoords(dXmin, dYmin, dXMax, dYMax);
                axMapControl1.Extent = envelope_1;
                axMapControl1.ActiveView.Refresh();
                break;

            case PublicMark.ButtonFunction.DrawPoint:
                IPoint pIPoint = new PointClass();
                pIPoint.X = e.mapX;
                pIPoint.Y = e.mapY;
                if (SelectLayer != null)
                {
                    IFeatureLayer pIFeatureLayer = SelectLayer as IFeatureLayer;
                    IFeatureClass pIFeatureClass = pIFeatureLayer.FeatureClass;
                    IFeature      pIFeature      = pIFeatureClass.CreateFeature();
                    pIFeature.Shape = pIPoint as IGeometry;
                    pIFeature.Store();
                    axMapControl1.Refresh();
                }
                break;

            case HmMap.PublicMark.ButtonFunction.Drawpolyline:
                IGeometry pIGeometry = axMapControl1.TrackLine();
                if (SelectLayer != null)
                {
                    IFeatureLayer pIFeatureLayer = SelectLayer as IFeatureLayer;
                    IFeatureClass pIFeatureClass = pIFeatureLayer.FeatureClass;
                    IFeature      pIFeature      = pIFeatureClass.CreateFeature();
                    pIFeature.Shape = pIGeometry;
                    pIFeature.Store();
                    axMapControl1.Refresh();
                }
                break;

            case HmMap.PublicMark.ButtonFunction.DrawPolygon:
                IGeometry pIGeometr = axMapControl1.TrackPolygon();
                if (SelectLayer != null)
                {
                    IFeatureLayer pIFeatureLayer = SelectLayer as IFeatureLayer;
                    IFeatureClass pIFeatureClass = pIFeatureLayer.FeatureClass;
                    IFeature      pIFeature      = pIFeatureClass.CreateFeature();
                    pIFeature.Shape = pIGeometr;
                    pIFeature.Store();
                    axMapControl1.Refresh();
                }
                break;
            }
        }
        /// <summary>
        /// 鼠标点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            try
            {
                if (e.button == 1)                    //按左键的话
                {
                    IPoint pPoint = new PointClass(); //在鼠标点击的位置生成一个点
                    pPoint.PutCoords(e.mapX, e.mapY);

                    if (this.btnNewPolyline.Checked)       //画多义线
                    {
                        if (this.pDisplayFeedback == null) //如果是第一次点击,就建立第一个节点
                        {
                            this.pDisplayFeedback         = new NewLineFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((INewLineFeedback)this.pDisplayFeedback).Start(pPoint);
                        }
                        else//如果不是第一次点击,就添加节点
                        {
                            ((INewLineFeedback)this.pDisplayFeedback).AddPoint(pPoint);
                        }
                    }
                    else if (this.btnLineMovePoint.Checked)//移动多义线节点
                    {
                        IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolyline);
                        if (pElement != null)
                        {
                            IPolyline pPolyline       = pElement.Geometry as IPolyline;
                            IHitTest  pHitTest        = pPolyline as IHitTest;
                            IPoint    hitPoint        = new PointClass();
                            double    distance        = 0;
                            bool      isOnRightSide   = false;
                            int       hitPartIndex    = 0;
                            int       hitSegmentIndex = 0;
                            bool      isHit           = pHitTest.HitTest(pPoint, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref distance, ref hitPartIndex, ref hitSegmentIndex, ref isOnRightSide);
                            if (isHit)
                            {
                                this.pDisplayFeedback         = new LineMovePointFeedbackClass();
                                this.pDisplayFeedback.Display = this.pScreenDisplay;
                                ((ILineMovePointFeedback)this.pDisplayFeedback).Start(pPolyline, hitSegmentIndex, pPoint);
                            }
                        }
                    }
                    else if (this.btnNewCircle.Checked)//画圆
                    {
                        this.pDisplayFeedback         = new NewCircleFeedbackClass();
                        this.pDisplayFeedback.Display = this.pScreenDisplay;
                        ((INewCircleFeedback)this.pDisplayFeedback).Start(pPoint);
                    }
                    else if (this.btnNewEnvelope.Checked)//画矩形
                    {
                        this.pDisplayFeedback         = new NewEnvelopeFeedbackClass();
                        this.pDisplayFeedback.Display = this.pScreenDisplay;
                        ((INewEnvelopeFeedback)this.pDisplayFeedback).Constraint = esriEnvelopeConstraints.esriEnvelopeConstraintsNone;
                        ((INewEnvelopeFeedback)this.pDisplayFeedback).Start(pPoint);
                    }
                    else if (this.btnNewPolygon.Checked)   //画多边形
                    {
                        if (this.pDisplayFeedback == null) //如果是第一次点击,就建立第一个节点
                        {
                            this.pDisplayFeedback         = new NewPolygonFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((INewPolygonFeedback)this.pDisplayFeedback).Start(pPoint);
                        }
                        else//如果不是第一次点击,就添加节点
                        {
                            ((INewPolygonFeedback)this.pDisplayFeedback).AddPoint(pPoint);
                        }
                    }
                    else if (this.btnPolygonMovePoint.Checked)//移动多边形节点
                    {
                        IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolygon);
                        if (pElement != null)
                        {
                            IPolygon pPolygon        = pElement.Geometry as IPolygon;
                            IHitTest pHitTest        = pPolygon as IHitTest;
                            IPoint   hitPoint        = new PointClass();
                            double   distance        = 0;
                            bool     isOnRightSide   = true;
                            int      hitPartIndex    = 0;
                            int      hitSegmentIndex = 0;
                            bool     isHit           = pHitTest.HitTest(pPoint, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref distance, ref hitPartIndex, ref hitSegmentIndex, ref isOnRightSide);
                            if (isHit)
                            {
                                this.pDisplayFeedback         = new PolygonMovePointFeedbackClass();
                                this.pDisplayFeedback.Display = this.pScreenDisplay;
                                ((IPolygonMovePointFeedback)this.pDisplayFeedback).Start(pPolygon, hitSegmentIndex, pPoint);
                            }
                        }
                    }
                    else if (this.btnNewBezierCurve.Checked) //新建Bezier曲线
                    {
                        if (this.pDisplayFeedback == null)   //如果是第一次点击
                        {
                            this.pDisplayFeedback         = new NewBezierCurveFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((INewBezierCurveFeedback)this.pDisplayFeedback).Start(pPoint);
                        }
                        else//如果不是第一次点击
                        {
                            ((INewBezierCurveFeedback)this.pDisplayFeedback).AddPoint(pPoint);
                        }
                    }
                    else if (this.btnMoveGeometry.Checked)//移动几何对象
                    {
                        this.pEnumElement = this.pGraphicContainer.LocateElements(pPoint, this.pActiveView.Extent.Width / 100);
                        if (this.pEnumElement != null)
                        {
                            this.pDisplayFeedback         = new MoveGeometryFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;

                            IElement pElement;
                            this.pEnumElement.Reset();
                            //需要逐个逐个添加Geometry
                            for (pElement = this.pEnumElement.Next(); pElement != null; pElement = this.pEnumElement.Next())
                            {
                                ((IMoveGeometryFeedback)this.pDisplayFeedback).AddGeometry(pElement.Geometry);
                            }
                            ((IMoveGeometryFeedback)this.pDisplayFeedback).Start(pPoint);
                            this.moveGeometryStartPoint = pPoint;
                        }
                    }
                    else if (this.btnStretchLine.Checked)//拉伸多义线
                    {
                        IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolyline);
                        if (pElement != null)
                        {
                            IPolyline pPolyline = pElement.Geometry as IPolyline;
                            this.pDisplayFeedback         = new StretchLineFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((IStretchLineFeedback)this.pDisplayFeedback).Anchor = pPolyline.FromPoint;
                            ((IStretchLineFeedback)this.pDisplayFeedback).Start(pPolyline, pPoint);
                        }
                    }
                }
                else if (e.button == 2)//按右键的就把画面清空
                {
                    if (this.pDisplayFeedback == null)
                    {
                        this.pGraphicContainer.DeleteAllElements();
                        this.axMapControl1.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #43
0
 public DeadbandRecord(System.UInt16 index, PointClass pointClass, T deadband) : base(index, pointClass)
 {
     this.deadband = deadband;
 }
Example #44
0
 public PickProfileCoordinates()
 {
     Point = new PointClass();
     Point.PutCoords(0, 0);
 }
        //to be improved, a vertical cutter may cause unexpected problems
        //
        public void CreateBufferWithoutEnds(IGeometry fBufferGeo, double dblBuffer)
        {
            //StartCutPolyline
            ILine pStartNormal = new LineClass();

            this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 0, true, dblBuffer, pStartNormal);
            IPoint StartFrPt = new PointClass();

            pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, StartFrPt);
            IPoint StartToPt = new PointClass();

            pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, StartToPt);

            IPointCollection4 pStartCutterCol = new PolylineClass();

            pStartCutterCol.AddPoint(StartFrPt);
            pStartCutterCol.AddPoint(StartToPt);
            IPolyline5 pStartCutter = pStartCutterCol as IPolyline5;

            //EndCutPolyline
            ILine pEndNormal = new LineClass();

            this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 1, true, dblBuffer, pEndNormal);
            IPoint EndFrPt = new PointClass();

            pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, EndFrPt);
            IPoint EndToPt = new PointClass();

            pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, EndToPt);

            IPointCollection4 pEndCutterCol = new PolylineClass();

            pEndCutterCol.AddPoint(EndFrPt);
            pEndCutterCol.AddPoint(EndToPt);
            IPolyline5 pEndCutter = pEndCutterCol as IPolyline5;

            //TopologicalOperators
            ITopologicalOperator pStartPtTop    = this.pPolyline.FromPoint as ITopologicalOperator;
            IGeometry            pStartPtBuffer = pStartPtTop.Buffer(dblBuffer);

            ITopologicalOperator pEndPtTop    = this.pPolyline.ToPoint as ITopologicalOperator;
            IGeometry            pEndPtBuffer = pEndPtTop.Buffer(dblBuffer);

            //Cut
            ITopologicalOperator pStartPtBufferTop = pStartPtBuffer as ITopologicalOperator;
            IGeometry            StartLeftOutGeometry;
            IGeometry            StartRightOutGeometry;

            pStartPtBufferTop.Cut(pStartCutter, out StartLeftOutGeometry, out StartRightOutGeometry);

            ITopologicalOperator pEndPtBufferTop = pEndPtBuffer as ITopologicalOperator;
            IGeometry            EndLeftOutGeometry;
            IGeometry            EndRightOutGeometry;

            pEndPtBufferTop.Cut(pEndCutter, out EndLeftOutGeometry, out EndRightOutGeometry);

            //Difference
            ITopologicalOperator pBufferTop    = fBufferGeo as ITopologicalOperator;
            IGeometry            pDiffStart    = pBufferTop.Difference(StartRightOutGeometry);
            ITopologicalOperator pDiffStartTop = pDiffStart as ITopologicalOperator;
            IGeometry            pDiffEnd      = pDiffStartTop.Difference(EndLeftOutGeometry);

            _pBufferGeoWithoutEnds = pDiffEnd;
        }
Example #46
0
        private static void DrawMapUnits(IEnvelope Envelope, bool showText, double ColumnX)
        {
            // BOX DIMENSIONS AND UNIFORM SYMBOL ITEMS
            double Text2BoxY = 0.2; //Y distance between the bottom of text and the next box
            double Text2BoxX = 0.1; //X distance between a box and the text that describes it
            double BoxX      = 0.4; //Width
            double BoxY      = 0.3; //Height

            // Setup a black color object, black outline
            IRgbColor BlackInsides = new ESRI.ArcGIS.Display.RgbColorClass();

            BlackInsides.Blue  = 0;
            BlackInsides.Red   = 0;
            BlackInsides.Green = 0;

            ILineSymbol BlackOutsides = new SimpleLineSymbolClass();

            BlackOutsides.Width = 1;
            BlackOutsides.Color = BlackInsides;

            // Whole bunch of variables to use while going through the loop below...
            #region Variables Galore!!!
            IMxDocument  Doc        = ArcMap.Document;
            IPageLayout  pageLayout = Doc.ActiveView as IPageLayout;
            IPageLayout3 pl3        = Doc.ActivatedView as IPageLayout3;

            IGraphicsContainer       GraphicsContainer = pageLayout as IGraphicsContainer;
            IGraphicsContainerSelect gCS;
            gCS = (IGraphicsContainerSelect)GraphicsContainer;

            double Xcoord, Ycoord;
            Xcoord = Envelope.XMin;
            Ycoord = Envelope.YMax;
            double IndentTerm   = 0;
            IPoint Point        = null;
            double StringLength = 0;
            string LegendText   = "";
            string ItemName     = "";
            //string ItemDesc = "";
            IElement                    Ele        = null;
            IEnvelope                   TempEnv    = null;
            IRgbColor                   BoxColr    = null;
            ISimpleFillSymbol           FillSym    = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
            IFillShapeElement           FillEle    = null;
            IEnvelope                   FillEnv    = new EnvelopeClass();
            WKSEnvelope                 Patch      = new WKSEnvelope();
            IGeometry                   Geo        = null;
            string                      LabelText  = "";
            ESRI.ArcGIS.Geometry.IPoint LabelPoint = new ESRI.ArcGIS.Geometry.PointClass();

            // Get the transparency of the MapUnitPolys Layer
            double transparency = 100;
            try
            {
                IFeatureLayer polyLayer    = commonFunctions.FindFeatureLayer(ArcMap.Editor.EditWorkspace, "MapUnitPolys");
                ILayerEffects layerEffects = polyLayer as ILayerEffects;
                transparency = layerEffects.Transparency;
            }
            catch { }

            #endregion

            pl3.DelayEvents = true;

            // Get a reference to the DescriptionOfMapUnits entries
            var sortedDmuEntries = GetDmuSortedByHierarchy();

            try
            {
                // Loop through legend records
                foreach (KeyValuePair <string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> aDictionaryEntry in sortedDmuEntries)
                {
                    // Grab the DMU entry itself
                    DescriptionOfMapUnitsAccess.DescriptionOfMapUnit aDescription = aDictionaryEntry.Value;
                    bool isHeading = (aDescription.ParagraphStyle.Contains("Heading"));


                    // Find out how far to indent the legend item
                    // Strip periods from the HierarchyKey, divide by 4, which is the length of a segment of the key
                    IndentTerm = aDescription.HierarchyKey.Replace(".", "").Length / 4;

                    // Get the coordinates of the text for the legend entry - upper left corner
                    // Xcoord starts at Envelope.XMin, Ycoord is Envelope.YMax: Upper left corner
                    Point = new PointClass();
                    double xAdditions = 0;
                    if (isHeading)
                    {
                        // Xcoord plus (indentation), Ycoord
                        xAdditions = 0.2 * (IndentTerm - 1);
                    }
                    else
                    {
                        //Xcoord plus (indentation) + (Box width and margin), Ycoord
                        xAdditions = 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX;
                    }
                    Point.PutCoords(Xcoord + xAdditions, Ycoord);

                    // StringLength is the width remaining in the envelope in which the text has to fit IN PIXELS.
                    StringLength = 72 * (Envelope.Width - xAdditions);

                    // Fix a couple of special characters in the legend string.
                    // Then amalgamate item name and description
                    ItemName = FixLegendTextCharacters(aDescription.Name);
                    if (!isHeading)
                    {
                        LegendText = ItemName + " - " + FixLegendTextCharacters(aDescription.Description);
                    }
                    else
                    {
                        LegendText = ItemName;
                    }



                    // Format the legend text if it is not a heading. If it is, we're fine.
                    if (!isHeading)
                    {
                        LegendText = GetFormattedString(LegendText, "Arial", 8, StringLength, 8);
                    }

                    // Boldify the ItemName
                    LegendText = LegendText.Replace(ItemName, "<bol>" + ItemName + "</bol>");

                    // If the StratCorDiagram is being drawn
                    if (showText == false)
                    {
                        LegendText   = "."; // placeholder
                        StringLength = 1;
                    }

                    // See if this legend item should be placed on a new column
                    Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;

                    TempEnv = new EnvelopeClass();
                    Ele.QueryBounds(Doc.ActiveView.ScreenDisplay, TempEnv);

                    // If the height of the formatted text is larger than the box + space specified
                    if (TempEnv.Height > BoxY + Text2BoxY)
                    {
                        // If the text will spill out below the envelope drawn by the user
                        if (Ycoord - TempEnv.Height < Envelope.YMin)
                        {
                            // Move to a new column - the last number is a fudge factor, looks like it is in inches
                            Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                            // Move to the top
                            Ycoord = Envelope.YMax;
                            // Recreate the text element
                            Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                            Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                        }
                    }
                    else // The height of the formatted text is not larger than the box + space defined
                    {
                        // If the box itself will spill out below the envelope drawn by the user
                        if (Ycoord - (BoxY + Text2BoxY) < Envelope.YMin)
                        {
                            // Move to a new column
                            Xcoord = Xcoord + BoxX + Text2BoxX + StringLength / 72 + ColumnX;
                            // Move to the top
                            Ycoord = Envelope.YMax;
                            // Recreate the text element
                            Point.PutCoords(Xcoord + 0.2 * (IndentTerm - 1) + BoxX + Text2BoxX, Ycoord);
                            Ele = MakeTextElement(Point, LegendText, "Arial") as IElement;
                        }
                    }

                    // Only write the legend text if the legend is being drawn (not the StratCorDiagram)
                    if (showText == true)
                    {
                        GraphicsContainer.AddElement(Ele, 0);
                    }

                    if (!isHeading)
                    {
                        FillEnv = new EnvelopeClass();

                        Patch.XMin = Point.X - BoxX - Text2BoxX;
                        Patch.YMax = Point.Y;
                        Patch.XMax = Point.X - Text2BoxX;
                        Patch.YMin = Point.Y - BoxY;
                        FillEnv.PutCoords(Patch.XMin, Patch.YMin, Patch.XMax, Patch.YMax);
                        Geo = FillEnv as IGeometry;

                        // Get the color of the box
                        BoxColr = new RgbColorClass();
                        if (aDescription.AreaFillRGB == null)
                        {
                            BoxColr.Red   = 255;
                            BoxColr.Green = 0;
                            BoxColr.Blue  = 0;
                        }
                        else
                        {
                            BoxColr.Red   = int.Parse(aDescription.AreaFillRGB.Split(';')[0]);
                            BoxColr.Green = int.Parse(aDescription.AreaFillRGB.Split(';')[1]);
                            BoxColr.Blue  = int.Parse(aDescription.AreaFillRGB.Split(';')[2]);
                        }

                        // Set the transparency for the legend color boxes
                        BoxColr.Red   = (int)((255 - BoxColr.Red) * transparency / 100 + BoxColr.Red);
                        BoxColr.Green = (int)((255 - BoxColr.Green) * transparency / 100 + BoxColr.Green);
                        BoxColr.Blue  = (int)((255 - BoxColr.Blue) * transparency / 100 + BoxColr.Blue);

                        // Draw the fill
                        FillSym         = new SimpleFillSymbolClass();
                        FillSym.Color   = BoxColr;
                        FillSym.Style   = esriSimpleFillStyle.esriSFSSolid;
                        FillSym.Outline = BlackOutsides;

                        FillEle = CreateFillElement(Geo, FillSym) as IFillShapeElement;

                        // Label the box
                        LabelText = aDescription.Label;

                        // Subscripting!!

                        for (int i = 0; i < LabelText.Length; i++)
                        {
                            string thisBit = LabelText.Substring(i, 1);
                            int    num;
                            if (int.TryParse(thisBit, out num)) // Checks if the character is numeric
                            {
                                LabelText = LabelText.Replace(thisBit, "<sub>" + thisBit + "</sub>");
                                i         = i + 5;
                            }
                        }
                        LabelText = LabelText.Replace("ir", "i<sub>r</sub>");
                        LabelText = LabelText.Replace("yc", "y<sub>c</sub>");

                        // Center the label
                        LabelPoint   = new PointClass();
                        LabelPoint.X = Point.X - BoxX / 2 - Text2BoxX;
                        LabelPoint.Y = Point.Y - BoxY / 2;

                        //LabelText = GetFormattedString(LabelText, "FGDCGeoAge", 8, StringLength, 0);
                        Ele = MakeTextElement(LabelPoint, LabelText, "FGDCGeoAge", true) as IElement;

                        // Add the box and label
                        IGroupElement3 group = new GroupElementClass();
                        group.AddElement(FillEle as IElement);
                        group.AddElement(Ele);
                        GraphicsContainer.AddElement(group as IElement, 0);
                    }

                    // Do a partial refresh
                    //Doc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                    // Setup the Y coordinates for the next entry
                    // if the height of this item's text is bigger than the minimum distance between text and box
                    if (TempEnv.Height > Text2BoxY)
                    {
                        // Subtract the box height and the text height to get the new ycoord
                        Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                    }
                    else
                    {
                        if (isHeading)
                        {
                            Ycoord = Ycoord - (TempEnv.Height + Text2BoxY);
                        }
                        else
                        {
                            Ycoord = Ycoord - (BoxY + Text2BoxY);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                pl3.DelayEvents = false;
                string errItem = e.StackTrace + " " + ItemName;
                MessageBox.Show("Legend Draw Map Unit Error: " + errItem);
            }

            pl3.DelayEvents = false;
            gCS.UnselectAllElements();
            // Done, refresh, turn off the tool
            Doc.ActiveView.Refresh();
            ArcMap.Application.CurrentTool = null;
        }
        private IPolygon GetMGRSPolygon(IPoint point)
        {
            CoordinateMGRS mgrs;

            IPointCollection pc = new RingClass();

            // bottom left
            CoordinateMGRS.TryParse(InputCoordinate, out mgrs);

            // don't create a polygon for 1m resolution
            if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4)
            {
                return(null);
            }

            var tempPoint = new PointClass() as IConversionNotation;

            (tempPoint as IPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR();//GetSR();
            var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter());

            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top left
            var tempMGRS    = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing);
            var tempEasting = mgrs.Easting.ToString().PadRight(5, '0');

            tempMGRS.Easting = Convert.ToInt32(tempEasting);
            var tempNorthing = mgrs.Northing.ToString().PadRight(5, '9');

            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR();
            anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // bottom right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '0');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing);

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // create polygon
            var poly = new PolygonClass();

            poly.SpatialReference = ArcMapHelpers.GetGCS_WGS_1984_SR();
            poly.AddPointCollection(pc);
            poly.Close();

            return(poly);
        }
Example #48
0
        /// <summary>
        /// Here we need to create the lines of sight and determine is a target can be seen or not
        /// Visualize the visible targets with GREEN circles
        /// Visualize the non visible targets with RED circles
        /// Visualize the number of observers that can see a target with a label #
        /// Visualize an observer that can see no targets with a RED circle on top of a BLUE circle
        /// Visualize an observer that can see at least one target with a GREEN circle on top of a BLUE circle
        /// </summary>
        internal override void CreateMapElement()
        {
            try
            {
                IsRunning = true;
                IPolyline longestLine = new PolylineClass();

                ReadSelectedLayerPoints();
                if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
                {
                    return;
                }

                if ((LLOS_ObserversInExtent.Any() || ObserverAddInPoints.Any()) &&
                    LLOS_TargetsInExtent.Any() || TargetAddInPoints.Any())
                {
                    // take your observer and target points and get lines of sight
                    var observerPoints = new ObservableCollection <AddInPoint>(LLOS_ObserversInExtent.Select(x => x.AddInPoint).Union(ObserverInExtentPoints));
                    var targetPoints   = new ObservableCollection <AddInPoint>(LLOS_TargetsInExtent.Select(x => x.AddInPoint).Union(TargetInExtentPoints));
                    var surface        = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                    if (surface == null)
                    {
                        return;
                    }

                    ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

                    // Issue warning if layer is ImageServerLayer
                    if (surfaceLayer is IImageServerLayer)
                    {
                        MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
                                                               VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);

                        if (mbr == MessageBoxResult.No)
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }
                    }

                    // Determine if selected surface is projected or geographic
                    var geoDataset = surfaceLayer as IGeoDataset;
                    if (geoDataset == null)
                    {
                        System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
                        return;
                    }

                    SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                    if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
                    {
                        MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
                        return;
                    }

                    if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
                    {
                        MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
                        return;
                    }

                    SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

                    var geoBridge = (IGeoDatabaseBridge2) new GeoDatabaseHelperClass();

                    IPoint    pointObstruction = null;
                    IPolyline polyVisible      = null;
                    IPolyline polyInvisible    = null;
                    bool      targetIsVisible  = false;

                    double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
                    double finalTargetOffset   = GetOffsetInZUnits(TargetOffset.Value, surface.ZFactor, OffsetUnitType);

                    var DictionaryTargetObserverCount = new Dictionary <IPoint, int>();

                    foreach (var observerPoint in observerPoints)
                    {
                        // keep track of visible targets for this observer
                        var CanSeeAtLeastOneTarget = false;

                        var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;

                        if (double.IsNaN(z1))
                        {
                            System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                            return;
                        }

                        foreach (var targetPoint in targetPoints)
                        {
                            var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;

                            if (double.IsNaN(z2))
                            {
                                System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
                                return;
                            }

                            var fromPoint = new PointClass()
                            {
                                Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true
                            } as IPoint;
                            var toPoint = new PointClass()
                            {
                                Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true
                            } as IPoint;

                            geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
                                                     out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);

                            var pcol = new PolylineClass() as IPointCollection;
                            pcol.AddPoint(fromPoint);
                            pcol.AddPoint(toPoint);
                            IPolyline pcolPolyline = pcol as IPolyline;

                            longestLine = (longestLine != null && longestLine.Length < pcolPolyline.Length) ? pcolPolyline : longestLine;

                            // set the flag if we can see at least one target
                            if (targetIsVisible)
                            {
                                CanSeeAtLeastOneTarget = true;

                                // update target observer count
                                UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
                            }

                            // First Add "SightLine" so it appears behind others
                            // Black = Not visible -or- White = Visible
                            if (targetIsVisible)
                            {
                                AddGraphicToMap(pcolPolyline, new RgbColorClass()
                                {
                                    RGB = 0xFFFFFF
                                }, false,
                                                size: 6); //  white line
                            }
                            else
                            {
                                AddGraphicToMap(pcolPolyline, new RgbColorClass()
                                {
                                    RGB = 0x000000
                                }, false,
                                                size: 6); //  black line
                            }
                            if (polyVisible != null)
                            {
                                AddGraphicToMap(polyVisible, new RgbColorClass()
                                {
                                    Green = 255
                                }, size: 5);
                            }

                            if (polyInvisible != null)
                            {
                                AddGraphicToMap(polyInvisible, new RgbColorClass()
                                {
                                    Red = 255
                                }, size: 3);
                            }

                            if (polyVisible == null && polyInvisible == null)
                            {
                                if (targetIsVisible)
                                {
                                    AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                    {
                                        Green = 255
                                    }, size: 3);
                                }
                                else
                                {
                                    AddGraphicToMap(pcol as IPolyline, new RgbColorClass()
                                    {
                                        Red = 255
                                    }, size: 3);
                                }
                            }
                        }

                        // visualize observer

                        // add blue dot
                        AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                        {
                            Blue = 255
                        }, size: 10);

                        if (CanSeeAtLeastOneTarget)
                        {
                            // add green dot
                            AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                            {
                                Green = 255
                            });
                        }
                        else
                        {
                            // add red dot
                            AddGraphicToMap(observerPoint.Point, new RgbColorClass()
                            {
                                Red = 255
                            });
                        }
                    }

                    VisualizeTargets(DictionaryTargetObserverCount, targetPoints);

                    if ((ObserverInExtentPoints.Any() || LLOS_ObserversInExtent.Any()) &&
                        (TargetInExtentPoints.Any() || LLOS_TargetsInExtent.Any()))
                    {
                        ZoomToExtent(longestLine);
                    }

                    DisplayOutOfExtentMsg();

                    //display points present out of extent
                    var colorObserver = new RgbColorClass()
                    {
                        Blue = 255
                    };
                    var colorTarget = new RgbColorClass()
                    {
                        Red = 255
                    };
                    var colorObserverBorder = new RgbColorClass()
                    {
                        Red = 255, Blue = 255, Green = 255
                    };
                    var colorTargetBorder = new RgbColorClass()
                    {
                        Red = 0, Blue = 0, Green = 0
                    };
                    var observerOutOfExtent = new ObservableCollection <AddInPoint>(LLOS_ObserversOutOfExtent.Select(x => x.AddInPoint).Union(ObserverOutExtentPoints));
                    foreach (var point in observerOutOfExtent)
                    {
                        AddGraphicToMap(point.Point, colorObserver, markerStyle: esriSimpleMarkerStyle.esriSMSX, size: 10, borderColor: colorObserverBorder);
                    }
                    var targetOutOfExtent = new ObservableCollection <AddInPoint>(LLOS_TargetsOutOfExtent.Select(x => x.AddInPoint).Union(TargetOutExtentPoints));
                    foreach (var point in targetOutOfExtent)
                    {
                        AddGraphicToMap(point.Point, colorTarget, markerStyle: esriSimpleMarkerStyle.esriSMSX, size: 10, borderColor: colorTargetBorder);
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.OutOfExtentMsg, VisibilityLibrary.Properties.Resources.OutOfExtentHeader);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong,
                                                     VisibilityLibrary.Properties.Resources.CaptionError);
            }
            finally
            {
                IsRunning = false;
                ClearLLOSCollections();
                ValidateLLOS_LayerSelection();
            }
        }
        protected override void OnMouseUp(MouseEventArgs arg)
        {
            // Did they click the left mouse button?
            if (arg.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // Get some application environment variables set
                IMxApplication mxApp = (IMxApplication)ArcMap.Application;

                // Get the clicked location in map units
                IPoint clickedPoint = mxApp.Display.DisplayTransformation.ToMapPoint(arg.Location.X, arg.Location.Y);

                // If this is the first click on the map...
                switch (numberOfClicks)
                {
                case 0:
                    // This is the first click, giving the location of the measurement.
                    measurementLocationX = clickedPoint.X;
                    measurementLocationY = clickedPoint.Y;

                    // Increment the click counter
                    numberOfClicks = 1;

                    // Change the cursor
                    System.Windows.Forms.Cursor firstCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.firstPointCursor.cur");
                    Cursor = firstCursor;

                    break;

                case 1:
                    // This is the second click, giving the first end of the strike line, according to right-hand rule.
                    firstEndX = clickedPoint.X;
                    firstEndY = clickedPoint.Y;

                    // Increment the click counter
                    numberOfClicks = 2;

                    // Change the cursor
                    System.Windows.Forms.Cursor secondCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.SecondPointCursor.cur");
                    Cursor = secondCursor;

                    break;

                case 2:
                    // This is the third click, giving the second end of the strike line, according to right-hand rule.
                    secondEndX = clickedPoint.X;
                    secondEndY = clickedPoint.Y;

                    // Increment the click counter
                    numberOfClicks = 3;

                    // Change the cursor
                    //base.m_cursor = Properties.Resources.GetDipCursor;

                    // Calculate the Strike from the two collected points
                    int theStrike = GetStrike(firstEndX, firstEndY, secondEndX, secondEndY);

                    // Get the dip input
                    int    theDip;
                    string inputValue = "";

getDipValue:
                    if (genericForms.InputBox("Digitize Structure Points", "Please enter the dip value", ref inputValue) == DialogResult.OK)
                    {
                        // Make sure they entered a valid dip value
                        int  dipValue;
                        bool result = int.TryParse(inputValue, out dipValue);

                        if (result == true)
                        {
                            // inputValue is an integer
                            if (dipValue >= -90)
                            {
                                if (dipValue <= 90)
                                {
                                    // inputValue is in the appropriate range
                                    theDip = int.Parse(inputValue);
                                }
                                else
                                {
                                    goto getDipValue;
                                }
                            }
                            else
                            {
                                goto getDipValue;
                            }
                        }
                        else
                        {
                            goto getDipValue;
                        }
                    }
                    else
                    {
                        // In this case, the action was canceled during the dip input. Reset the counter, cursor, and exit the routine.
                        numberOfClicks = 0;
                        //base.m_cursor = Properties.Resources.firstPointCursor;
                        return;
                    }

                    // Now we need to create the feature. First we'll find the current FeatureTemplate
                    IEditor3      templateEditor     = (IEditor3)ArcMap.Editor;
                    IEditTemplate theCurrentTemplate = templateEditor.CurrentTemplate;

                    // If they didn't select a template, they'll need to
                    if (theCurrentTemplate == null)
                    {
                        MessageBox.Show("Please select a feature template for the type of measurement that you're digitizing", "NCGMP Tools");
                        numberOfClicks = 0;
                        System.Windows.Forms.Cursor locCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.StationLocCursor.cur");
                        Cursor = locCursor;
                        return;
                    }

                    // Make sure that the template puts features into the OrientationPoints FeatureClass
                    IFeatureClass templateFC = ((IFeatureLayer)theCurrentTemplate.Layer).FeatureClass;
                    if (templateFC.Equals(commonFunctions.OpenFeatureClass(ArcMap.Editor.EditWorkspace, "OrientationPoints")))
                    {
                        try
                        {
                            // Create a dummy feature and read in values from the feature template
                            IFeature tempFeature = templateFC.CreateFeature();
                            theCurrentTemplate.SetDefaultValues(tempFeature);

                            // Grab values from the dummy feature - the code is actually cleaner than grabbing the values from the FeatureTemplate
                            string StationID = "";
                            string Type      = tempFeature.get_Value(templateFC.FindField("Type")).ToString();
                            string IDConf    = tempFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString();
                            string Label     = tempFeature.get_Value(templateFC.FindField("Label")).ToString();
                            string Notes     = tempFeature.get_Value(templateFC.FindField("Notes")).ToString();

                            int  Plot;
                            bool result = int.TryParse(tempFeature.get_Value(templateFC.FindField("PlotAtScale")).ToString(), out Plot);

                            double OrientConf;
                            result = double.TryParse(tempFeature.get_Value(templateFC.FindField("OrientationConfidenceDegrees")).ToString(), out OrientConf);

                            int RuleID;
                            result = int.TryParse(tempFeature.get_Value(templateFC.FindField("RuleID")).ToString(), out RuleID);

                            string DataSourceID = commonFunctions.GetCurrentDataSourceID();

                            int SymbolRot = 360 - theStrike;

                            IPoint Shape = new PointClass();
                            Shape.X = measurementLocationX;
                            Shape.Y = measurementLocationY;

                            // Remove the temporary Feature
                            tempFeature.Delete();

                            // Create the new feature
                            OrientationPointsAccess OdpAccess = new OrientationPointsAccess(ArcMap.Editor.EditWorkspace);
                            OdpAccess.NewOrientationPoint(StationID, Type, IDConf, Label, Plot, (double)theStrike, (double)theDip, OrientConf, Notes, DataSourceID, SymbolRot, RuleID, Shape);
                            OdpAccess.SaveOrientationPoints();

                            // Refresh the Active View
                            ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, theCurrentTemplate.Layer, null);
                        }
                        catch
                        {
                            MessageBox.Show("Create feature didn't work.", "NCGMP Tools");
                            numberOfClicks = 0;
                            System.Windows.Forms.Cursor locCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.StationLocCursor.cur");
                            Cursor = locCursor;
                            return;
                        }
                    }
                    else
                    {
                        // User needs to select a relevant feature template
                        MessageBox.Show("Please select a valid feature template to digitize structural measurements.", "NCGMP Tools");
                    }

                    // Finished successfully, reset the counter and cursor
                    numberOfClicks = 0;
                    System.Windows.Forms.Cursor theLocCursor = new System.Windows.Forms.Cursor(GetType(), "Cursors.StationLocCursor.cur");
                    Cursor = theLocCursor;
                    break;

                default:
                    // Don't do anything here, preventing any more input before the dip is entered and the counter resets
                    break;
                }
            }
        }
Example #50
0
        /// <summary>
        ///     删除GIS回采进尺图形信息
        /// </summary>
        /// <param name="hd1">主运顺槽id</param>
        /// <param name="hd2">辅运顺槽id</param>
        /// <param name="qy">切眼id</param>
        /// <param name="bid">回采进尺的BindingID</param>
        /// <param name="wfEntity">回采面实体</param>
        /// <param name="zywid"></param>
        /// <param name="fywid"></param>
        private void DelHcjc(int hd1, int hd2, int qy, string bid, WorkingFace wfEntity, double zywid, double fywid)
        {
            //删除对应的回采进尺图形和数据表中的记录信息
            var results = Global.cons.DelHCCD(hd1.ToString(CultureInfo.InvariantCulture),
                                              hd2.ToString(CultureInfo.InvariantCulture), qy.ToString(CultureInfo.InvariantCulture), bid, zywid, fywid,
                                              Global.searchlen);

            if (results == null)
            {
                return;
            }

            //更新当前回采进尺后的回采进尺记录表信息
            var    count  = results.Keys.Count;
            var    index  = 0;
            IPoint posnew = null;

            foreach (var key in results.Keys)
            {
                var x = results[key].X;
                var y = results[key].Y;
                var z = results[key].Z;
                wfEntity.SetCoordinate(x, y, z);
                wfEntity.Save();

                index += 1;
                if (index == count - 1)
                {
                    posnew = new PointClass {
                        X = x, Y = y, Z = z
                    };
                }
            }
            //更新回采进尺表,将isdel设置0
            var entity = DayReportHc.FindByBid(bid);

            entity.IsDel = 0;
            entity.SaveAndFlush();


            //更新地质构造表中的信息
            if (posnew == null)
            {
                return;
            }
            var hdIds = new List <int> {
                hd1, hd2, qy
            };
            var dzxlist = Global.commonclss.GetStructsInfos(posnew, hdIds);

            if (dzxlist.Count > 0)
            {
                GeologySpaceBll.DeleteGeologySpaceEntityInfos(wfEntity.WorkingFaceId); //删除工作面ID对应的地质构造信息
                foreach (var key in dzxlist.Keys)
                {
                    var geoinfos = dzxlist[key];
                    foreach (var tmp in geoinfos)
                    {
                        var geologyspaceEntity = new GeologySpace
                        {
                            WorkingFace  = wfEntity,
                            TectonicType = Convert.ToInt32(key),
                            TectonicId   = tmp.geoinfos[GIS_Const.FIELD_BID],
                            Distance     = tmp.dist,
                            OnDateTime   = DateTime.Now.ToShortDateString()
                        };

                        geologyspaceEntity.Save();
                    }
                }
            }
        }
Example #51
0
        /// <summary>
        ///     提交
        /// </summary>
        /// <params name="sender"></params>
        /// <params name="e"></params>
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;

            // 创建勘探线实体
            var prospectingLineEntity = new ProspectingLine();

            // 勘探线名称
            prospectingLineEntity.prospecting_line_name = txtProspectingLineName.Text.Trim();
            // 勘探线钻孔
            var cnt = lstProspectingBoreholeSelected.Items.Count;
            var lstProspectingBoreholePts = new List <IPoint>(); //20140505 lyf 存储选择的钻孔点要素

            for (var i = 0; i < cnt; i++)
            {
                var strDisplayName = lstProspectingBoreholeSelected.Items[i].ToString();
                if (String.IsNullOrWhiteSpace(prospectingLineEntity.prospecting_borehole))
                {
                    prospectingLineEntity.prospecting_borehole = strDisplayName;
                }
                else
                {
                    prospectingLineEntity.prospecting_borehole = prospectingLineEntity.prospecting_borehole + "," +
                                                                 strDisplayName;
                }

                IPoint pt = new PointClass();
                pt = GetProspectingBoreholePointSelected(strDisplayName);
                if (pt != null && !lstProspectingBoreholePts.Contains(pt))
                {
                    lstProspectingBoreholePts.Add(pt);
                }
            }

            var bResult = false;

            if (_bllType == "add")
            {
                // BIDID
                prospectingLineEntity.binding_id = IdGenerator.NewBindingId();

                // 勘探线信息登录
                prospectingLineEntity.Save();

                ///20140505 lyf
                ///绘制勘探线图形
                DrawProspectingLine(prospectingLineEntity, lstProspectingBoreholePts);
            }
            else
            {
                // 主键
                prospectingLineEntity.prospecting_line_id = _iPK;
                // 勘探线信息修改
                prospectingLineEntity.Save();
                //20140506 lyf
                //获取勘探线的BID
                var sBid = ProspectingLine.Find(_iPK).binding_id;
                if (sBid != "")
                {
                    prospectingLineEntity.binding_id = sBid;
                    ModifyProspectingLine(prospectingLineEntity, lstProspectingBoreholePts); //修改图元
                }
            }

            // 添加/修改成功的场合
            if (bResult)
            {
            }
        }
Example #52
0
        public IFeatureClass CreatePointFeatureClass(IFeatureDataset pFeatureDataset, CGmpPoint xml)
        {
            try
            {
                //建立shape字段
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //设置Geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGeometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint; //点、线、面
                pGeometryDefEdit.SpatialReference_2 = ClsGDBDataCommon.CreateProjectedCoordinateSystem();
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //新建字段
                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "PointType";       //点类型
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                //新建字段
                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "类型";       //点类型
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "speed";       //行驶速度
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "规划开始时间";    //规划开始时间
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "规划时长";       //规划时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "行走开始时间";       //行走开始时间
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "行走时长";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "探测开始时间";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "探测时长";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "探测结束时间";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "太阳方位角";       //太阳方位角
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "地球方位角";       //地球方位角
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);


                IFeatureClass pFeatureClass = pFeatureDataset.CreateFeatureClass(textBoxX3.Text + "_Gmppoint", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                for (int j = 0; j < xml.GmpPointS.Count; j++)
                {
                    IPoint pPoint = new PointClass();
                    pPoint.X = xml.GmpPointS[j].dPointX;
                    pPoint.Y = xml.GmpPointS[j].dPointY;
                    IFeature pFeature = pFeatureClass.CreateFeature();
                    pFeature.Shape = pPoint;
                    pFeature.Store();
                    AddAttributeTable(pFeature, xml.GmpPointS[j], j);
                }

                return(pFeatureClass);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(null);
            }
        }
Example #53
0
        /// <summary>
        /// 裁切一个几何对象,不需要传出
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="geometryType"></param>
        /// <param name="ply"></param>
        /// <param name="geoObjNum"></param>
        /// <returns></returns>
        private bool ClipGeometry(ref IGeometry inGeometry, esriGeometryType geometryType, IPolygon clipPolygon, string GeoObjNum)
        {
            IPolycurve pPolyCurve;

            bool                 returnValue   = false;
            IGeometry            tempGeometry  = null;
            IGeometry            tempGeometry1 = null;
            ITopologicalOperator topologyOper  = clipPolygon as ITopologicalOperator;

            topologyOper.Simplify();
            IRelationalOperator relationOper = clipPolygon as IRelationalOperator;

            IZAware             zIn = inGeometry as IZAware;
            IMAware             mAware;
            IPoint              pPoint, pPoint1;
            IPointCollection    pPtC;
            ICurve              pCurve;
            IGeometryCollection pGeoC;
            bool HasM = true;

            IHitTest         pHitTest;
            double           dblHitDist   = 0;
            int              partIndex    = 0;
            int              segmentIndex = 0;
            bool             bRightSide   = true;
            IPoint           hitPoint     = new PointClass(); //返回击中位置
            IPath            pPath;
            IPointCollection pPointC;
            IPoint           P1, P2;

            switch (geometryType)
            {
            case esriGeometryType.esriGeometryPoint:
                //如果点包含在多边形中
                if (relationOper.Contains(inGeometry))
                {
                    //tempGeometry = inGeometry;
                    returnValue = true;
                }
                break;

            case esriGeometryType.esriGeometryPolyline:
                //'如果多义线穿越多边形或包含在多边形中
                if (relationOper.Contains(inGeometry))
                {
                    returnValue = true;
                    //tempGeometry = inGeometry;
                }
                else     //if(relationOper.Crosses(inGeometry))    2008.1.29 TianK 注释掉  解决了裁切丢数据的问题
                {
                    pPolyCurve = inGeometry as IPolycurve;
                    pPolyCurve.Generalize(0.03);

                    if (DIRECTIONLINE.IndexOf(GeoObjNum) != -1)         //如果是有方向的线性地物
                    {
                        pHitTest = (IHitTest)inGeometry;

                        mAware = inGeometry as IMAware;                       ////2008.1.27TianK 修改 确保裁切后的线不反向
                        if (mAware.MAware == true)
                        {
                            HasM = true;
                            pPtC = inGeometry as IPointCollection;
                            for (int i = 0; i < pPtC.PointCount; i++)
                            {
                                pPoint   = pPtC.get_Point(i);
                                pPoint.M = i;
                                pPtC.UpdatePoint(i, pPoint);
                            }
                        }
                        else
                        {
                            HasM          = false;
                            mAware.MAware = true;
                            pPtC          = inGeometry as IPointCollection;
                            for (int i = 0; i < pPtC.PointCount; i++)
                            {
                                pPoint   = pPtC.get_Point(i);
                                pPoint.M = i;
                                pPtC.UpdatePoint(i, pPoint);
                            }
                        }
                        tempGeometry1 = topologyOper.Intersect(inGeometry, esriGeometryDimension.esriGeometry1Dimension);
                        tempGeometry  = (inGeometry as ITopologicalOperator).Difference(tempGeometry1);
                        ////2008.1.27TianK 修改 确保裁切后的线不反向
                        mAware        = tempGeometry as IMAware;
                        mAware.MAware = true;
                        pGeoC         = tempGeometry as IGeometryCollection;
                        for (int j = 0; j < pGeoC.GeometryCount; j++)
                        {
                            pPtC    = pGeoC.get_Geometry(j) as IPointCollection;
                            pPoint  = pPtC.get_Point(0);
                            pPoint1 = pPtC.get_Point(pPtC.PointCount - 1);
                            if (double.IsNaN(pPoint.M))
                            {
                                if (pHitTest.HitTest(pPoint, 0.01, esriGeometryHitPartType.esriGeometryPartBoundary,
                                                     hitPoint, ref dblHitDist, ref partIndex, ref segmentIndex, ref bRightSide)) //如果击中该要素
                                {
                                    pPath   = (IPath)(inGeometry as IGeometryCollection).get_Geometry(partIndex);
                                    pPointC = (IPointCollection)pPath;    //接口跳转

                                    P1 = pPointC.get_Point(segmentIndex);
                                    P2 = pPointC.get_Point(segmentIndex + 1);
                                    AddM_P1_P2(P1, P2, ref pPoint);
                                    pPtC.UpdatePoint(0, pPoint);
                                }
                            }
                            if (double.IsNaN(pPoint1.M))
                            {
                                if (pHitTest.HitTest(pPoint1, 0.01, esriGeometryHitPartType.esriGeometryPartBoundary,
                                                     hitPoint, ref dblHitDist, ref partIndex, ref segmentIndex, ref bRightSide)) //如果击中该要素
                                {
                                    pPath   = (IPath)(inGeometry as IGeometryCollection).get_Geometry(partIndex);
                                    pPointC = (IPointCollection)pPath;    //接口跳转

                                    P1 = pPointC.get_Point(segmentIndex);
                                    P2 = pPointC.get_Point(segmentIndex + 1);
                                    AddM_P1_P2(P1, P2, ref pPoint1);
                                    pPtC.UpdatePoint(pPtC.PointCount - 1, pPoint1);
                                }
                            }
                            pPoint  = pPtC.get_Point(0);
                            pPoint1 = pPtC.get_Point(pPtC.PointCount - 1);
                            if (pPoint.M >= pPoint1.M)
                            {
                                pCurve = pGeoC.get_Geometry(j) as ICurve;
                                pCurve.ReverseOrientation();
                            }
                            if (HasM)
                            {
                                for (int i = 0; i < pPtC.PointCount; i++)
                                {
                                    pPoint   = pPtC.get_Point(i);
                                    pPoint.M = 0;
                                    pPtC.UpdatePoint(i, pPoint);
                                }
                            }
                            else
                            {
                                mAware.MAware = false;
                            }
                        }
                    }
                    else
                    {
                        int    i;
                        IPoint p;
                        tempGeometry1 = topologyOper.Intersect(inGeometry, esriGeometryDimension.esriGeometry1Dimension);
                        tempGeometry  = (inGeometry as ITopologicalOperator).Difference(tempGeometry1);
                    }

                    if (zIn.ZAware)
                    {
                        IZAware zOut = tempGeometry as IZAware;
                        zOut.ZAware = zIn.ZAware;

                        IZ iz = tempGeometry as IZ;
                        try
                        {
                            iz.CalculateNonSimpleZs();
                        }
                        catch
                        {
                            //该值应该传入,表示如果栽得的线如果不能插值出Z值赋一个默认值,或再次计算
                            //可以根据inGeometry计算
                            iz.SetConstantZ(0);
                        }
                    }
                }
                break;

            case esriGeometryType.esriGeometryMultipoint:
            case esriGeometryType.esriGeometryPolygon:
                //如果多边形与裁剪多边形相交或在裁剪多边形中
                if (relationOper.Contains(inGeometry))
                {
                    //tempGeometry = inGeometry;
                    returnValue = true;
                }
                else     //if( relationOper.Overlaps(inGeometry))     2008.1.29 TianK 注释掉
                {
                    pPolyCurve = inGeometry as IPolycurve;
                    pPolyCurve.Generalize(0.03);
                    tempGeometry1 = topologyOper.Intersect(inGeometry, esriGeometryDimension.esriGeometry2Dimension);
                    tempGeometry  = (inGeometry as ITopologicalOperator).Difference(tempGeometry1);

                    if (zIn.ZAware)
                    {
                        IZAware zOut = tempGeometry as IZAware;
                        zOut.ZAware = zIn.ZAware;
                        IZ iz = tempGeometry as IZ;
                        try
                        {
                            iz.CalculateNonSimpleZs();
                        }
                        catch
                        {
                            //该值应该传入,表示如果栽得的线如果不能插值出Z值赋一个默认值,或再次计算
                            //可以根据inGeometry计算
                            iz.SetConstantZ(0);
                        }
                    }
                }
                break;
            }
            if (tempGeometry != null && !tempGeometry.IsEmpty)
            {
                inGeometry = tempGeometry;
            }
            return(returnValue);
        }
Example #54
0
        public static void WriteAttribute(DataTable exDt, IFeatureClass ptFeclass, string Lon, string Lat)
        {
            //首先将datatable里面的字段名称进行添加到属性表里面
            for (int i = 1; i < exDt.Columns.Count; i++)
            {
                string     clname = exDt.Columns[i].ColumnName;
                IField     fd     = new FieldClass();
                IFieldEdit fdedit = fd as IFieldEdit;
                fdedit.Name_2 = clname;
                //fdedit.Type_2 = esriFieldType.esriFieldTypeDouble;
                if (clname == "Lat" || clname == "Lon")
                {
                    fdedit.Type_2 = esriFieldType.esriFieldTypeDouble;
                }
                else
                {
                    fdedit.Type_2 = esriFieldType.esriFieldTypeString;
                }


                ptFeclass.AddField(fd);
            }
            MessageBox.Show("添加表头完成");


            //添加字段的操作
            DataRow dtrw = exDt.Rows[0];

            for (int j = 0; j < exDt.Rows.Count; j++)
            {
                //第一次循环创建空的feature
                IFeature fea   = ptFeclass.CreateFeature();
                DataRow  dtrow = exDt.Rows[j];
                //往每一格进行赋值,前三个自动生成
                //注意:此时数据已经有表头了,找表头与datatable表头相对应的字段
                //dtfdname内存表中的数据
                //fdname新建的已有表头的数据
                for (int p = 0; p < fea.Fields.FieldCount; p++)
                {
                    string fdname = fea.Fields.get_Field(p).Name;

                    for (int z = 0; z < dtrw.Table.Columns.Count; z++)
                    {
                        string dtfdname = dtrw.Table.Columns[z].ColumnName;
                        //fdname是已经建立好的空矢量的表头
                        if (fdname == dtfdname)
                        {
                            try
                            {
                                //Console.WriteLine(dtrow[z]);
                                fea.set_Value(p, dtrow[z]);
                                fea.Store();
                            }
                            catch (Exception ex)
                            {
                                // Print a generic exception message.
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }

            IFeatureCursor curor = ptFeclass.Search(null, false);
            IFeature       fea1  = curor.NextFeature();

            while (fea1 != null)
            {
                IPoint pt     = new PointClass();
                int    xindex = fea1.Fields.FindField(Lon);
                int    yindex = fea1.Fields.FindField(Lat);

                double x = Convert.ToDouble(fea1.get_Value(xindex));
                double y = Convert.ToDouble(fea1.get_Value(yindex));
                pt.X = x;
                pt.Y = y;

                fea1.Shape = pt as IGeometry;
                fea1.Store();
                fea1 = curor.NextFeature();
            }
            MessageBox.Show("填写表完成");
        }
Example #55
0
        private static void TestMultiTables(IFeatureWorkspace ws)
        {
            IFieldsEdit lineFields = new FieldsClass();

            lineFields.AddField(FieldUtils.CreateOIDField());
            lineFields.AddField(FieldUtils.CreateTextField("FromVal1", 50));
            lineFields.AddField(FieldUtils.CreateTextField("ToVal1", 50));
            lineFields.AddField(FieldUtils.CreateShapeField(
                                    "Shape", esriGeometryType.esriGeometryPolyline,
                                    SpatialReferenceUtils.CreateSpatialReference
                                        ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                        true), 1000));

            IFeatureClass lineFc1 = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestMultiTablesLineFc1", lineFields);

            lineFields = new FieldsClass();
            lineFields.AddField(FieldUtils.CreateOIDField());
            lineFields.AddField(FieldUtils.CreateTextField("FromVal2", 50));
            lineFields.AddField(FieldUtils.CreateTextField("ToVal2", 50));
            lineFields.AddField(FieldUtils.CreateShapeField(
                                    "Shape", esriGeometryType.esriGeometryPolyline,
                                    SpatialReferenceUtils.CreateSpatialReference
                                        ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                        true), 1000));

            IFeatureClass lineFc2 = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestMultiTablesLineFc2", lineFields);

            IFieldsEdit pointFields = new FieldsClass();

            pointFields.AddField(FieldUtils.CreateOIDField());
            pointFields.AddField(FieldUtils.CreateTextField("Name1", 50));
            pointFields.AddField(FieldUtils.CreateShapeField(
                                     "Shape", esriGeometryType.esriGeometryPoint,
                                     SpatialReferenceUtils.CreateSpatialReference
                                         ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                         true), 1000));

            IFeatureClass pointFc1 = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestMultiTablesPointFc1", pointFields);

            pointFields = new FieldsClass();
            pointFields.AddField(FieldUtils.CreateOIDField());
            pointFields.AddField(FieldUtils.CreateTextField("Name2", 50));
            pointFields.AddField(FieldUtils.CreateShapeField(
                                     "Shape", esriGeometryType.esriGeometryPoint,
                                     SpatialReferenceUtils.CreateSpatialReference
                                         ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                         true), 1000));

            IFeatureClass pointFc2 = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestMultiTablesPointFc2", pointFields);

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            IPoint center = new PointClass();

            center.PutCoords(200, 200);

            IFeature row1 = lineFc1.CreateFeature();

            row1.set_Value(1, "Name");
            row1.set_Value(2, "AndererName");
            row1.Shape = CurveConstruction.StartLine(100, 100).LineTo(center).Curve;
            row1.Store();

            IFeature row2 = lineFc1.CreateFeature();

            row2.set_Value(1, "Name");
            row2.Shape = CurveConstruction.StartLine(200, 100).LineTo(center).Curve;
            row2.Store();

            IFeature row3 = lineFc2.CreateFeature();

            row3.set_Value(1, "Name");
            row3.Shape = CurveConstruction.StartLine(300, 100).LineTo(center).Curve;
            row3.Store();

            IFeature row4 = pointFc1.CreateFeature();

            row4.set_Value(1, "AndererName");
            row4.Shape = center;
            row4.Store();

            IFeature row5 = pointFc2.CreateFeature();

            row5.set_Value(1, "AndererName");
            row5.Shape = center;
            row5.Store();

            IFeature row6 = pointFc2.CreateFeature();

            row6.set_Value(1, "Ignore2");
            row6.Shape = center;
            row6.Store();

            string lineField = string.Format("IIF({0}, FromVal1, ToVal1)",
                                             QaConnections.StartsIn);
            var test = new QaLineConnectionFieldValues(
                new[] { lineFc1, lineFc2 }, new[] { lineField, "FromVal2" },
                LineFieldValuesConstraint.AllEqualOrValidPointExists,
                new[] { pointFc1, pointFc2 }, new[] { "Name1", "Name2" },
                PointFieldValuesConstraint.AllEqualAndMatchAnyLineValue,
                new[] { null, "Name2 = 'Ignore2'" });

            var runner = new QaTestRunner(test);

            runner.Execute();
            Assert.AreEqual(0, runner.Errors.Count);

            var containerRunner = new QaContainerTestRunner(500, test);

            containerRunner.Execute();
            Assert.AreEqual(0, containerRunner.Errors.Count);
        }
        public static void CreateMapGraphicTrack(ICreateGraphicTrackOptions pOptions, IAGAnimationTracks tracks, IAGAnimationContainer pContainer)
        {
            pOptions.PathGeometry = SimplifyPath2D(pOptions.PathGeometry, pOptions.ReverseOrder, pOptions.SimplificationFactor);
            IAGAnimationType animType = new AnimationTypeMapGraphic();

            //remove tracks with the same name if overwrite is true
            if (pOptions.OverwriteTrack == true)
            {
                IArray trackArray = new ArrayClass();
                trackArray = tracks.get_TracksOfType(animType);
                int count = trackArray.Count;
                for (int i = 0; i < count; i++)
                {
                    IAGAnimationTrack temp = (IAGAnimationTrack)trackArray.get_Element(i);
                    if (temp.Name == pOptions.TrackName)
                    {
                        tracks.RemoveTrack(temp);
                    }
                }
            }

            //create the new track
            IAGAnimationTrack          animTrack          = tracks.CreateTrack(animType);
            IAGAnimationTrackKeyframes animTrackKeyframes = (IAGAnimationTrackKeyframes)animTrack;

            animTrackKeyframes.EvenTimeStamps = false;

            animTrack.Name = pOptions.TrackName;

            IGeometry        path            = pOptions.PathGeometry;
            IPointCollection pointCollection = (IPointCollection)path;

            ICurve curve      = (ICurve)path;
            double length     = curve.Length;
            double accuLength = 0;

            //loop through all points to create the keyframes
            int pointCount = pointCollection.PointCount;

            if (pointCount <= 1)
            {
                return;
            }
            for (int i = 0; i < pointCount; i++)
            {
                IPoint currentPoint = pointCollection.get_Point(i);

                IPoint nextPoint = new PointClass();
                if (i < pointCount - 1)
                {
                    nextPoint = pointCollection.get_Point(i + 1);
                }

                IPoint lastPoint = new PointClass();
                if (i == 0)
                {
                    lastPoint = currentPoint;
                }
                else
                {
                    lastPoint = pointCollection.get_Point(i - 1);
                }

                IAGKeyframe tempKeyframe = animTrackKeyframes.CreateKeyframe(i);

                //set keyframe properties
                double x;
                double y;
                currentPoint.QueryCoords(out x, out y);
                tempKeyframe.set_PropertyValue(0, currentPoint);
                tempKeyframe.Name = "Map Graphic keyframe " + i.ToString();

                //set keyframe timestamp
                accuLength += CalculateDistance(lastPoint, currentPoint);
                double timeStamp = accuLength / length;
                tempKeyframe.TimeStamp = timeStamp;

                double x1;
                double y1;
                double angle;
                if (i < pointCount - 1)
                {
                    nextPoint.QueryCoords(out x1, out y1);
                    if ((y1 - y) > 0)
                    {
                        angle = Math.Acos((x1 - x) / Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)));
                    }
                    else
                    {
                        angle = 6.2832 - Math.Acos((x1 - x) / Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)));
                    }
                    tempKeyframe.set_PropertyValue(1, angle);
                }
                else
                {
                    IAGKeyframe lastKeyframe = animTrackKeyframes.get_Keyframe(i - 1);
                    tempKeyframe.set_PropertyValue(1, lastKeyframe.get_PropertyValue(1));
                }
            }

            //attach the point element
            if (pOptions.PointElement != null)
            {
                animTrack.AttachObject(pOptions.PointElement);
            }

            //attach the track extension, which contains a line element for trace
            IMapGraphicTrackExtension graphicTrackExtension = new MapGraphicTrackExtension();

            graphicTrackExtension.ShowTrace = pOptions.AnimatePath;
            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)animTrack;

            trackExtensions.AddExtension(graphicTrackExtension);
        }
Example #57
0
        private static void TestFieldValues(IFeatureWorkspace ws)
        {
            IFieldsEdit lineFields = new FieldsClass();

            lineFields.AddField(FieldUtils.CreateOIDField());
            lineFields.AddField(FieldUtils.CreateTextField("FromVal", 50));
            lineFields.AddField(FieldUtils.CreateTextField("ToVal", 50));
            lineFields.AddField(FieldUtils.CreateShapeField(
                                    "Shape", esriGeometryType.esriGeometryPolyline,
                                    SpatialReferenceUtils.CreateSpatialReference
                                        ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                        true), 1000));

            IFeatureClass lineFc = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestFieldValues1", lineFields);

            IFieldsEdit fields = new FieldsClass();

            fields.AddField(FieldUtils.CreateOIDField());
            fields.AddField(FieldUtils.CreateTextField("Name", 50));
            fields.AddField(FieldUtils.CreateShapeField(
                                "Shape", esriGeometryType.esriGeometryPoint,
                                SpatialReferenceUtils.CreateSpatialReference
                                    ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                    true), 1000));

            IFeatureClass pointFc = DatasetUtils.CreateSimpleFeatureClass(
                ws, "TestFieldValues2", fields);

            // make sure the table is known by the workspace
            ((IWorkspaceEdit)ws).StartEditing(false);
            ((IWorkspaceEdit)ws).StopEditing(true);

            IPoint center = new PointClass();

            center.PutCoords(200, 200);

            IFeature row1 = lineFc.CreateFeature();

            row1.set_Value(1, "Name");
            row1.Shape = CurveConstruction.StartLine(100, 100).LineTo(center).Curve;
            row1.Store();

            IFeature row2 = lineFc.CreateFeature();

            row2.set_Value(1, "Name");
            row2.Shape = CurveConstruction.StartLine(200, 100).LineTo(center).Curve;
            row2.Store();

            IFeature row3 = lineFc.CreateFeature();

            row3.set_Value(1, "Name");
            row3.Shape = CurveConstruction.StartLine(300, 100).LineTo(center).Curve;
            row3.Store();

            IFeature row4 = lineFc.CreateFeature();

            row4.set_Value(1, "Name");
            row4.Shape = CurveConstruction.StartLine(300, 100).LineTo(400, 100).Curve;
            row4.Store();

            IFeature row5 = pointFc.CreateFeature();

            row5.set_Value(1, "Name");
            row5.Shape = center;
            row5.Store();

            // configure and run the test
            var test = new QaLineConnectionFieldValues(
                lineFc, "FromVal",
                LineFieldValuesConstraint.AllEqualOrValidPointExists,
                pointFc, "Name",
                PointFieldValuesConstraint.AllEqualAndMatchAnyLineValue);

            var runner = new QaTestRunner(test);

            runner.Execute();
            Assert.AreEqual(0, runner.Errors.Count);

            var containerRunner = new QaContainerTestRunner(500, test);

            containerRunner.Execute();
            Assert.AreEqual(0, containerRunner.Errors.Count);
        }
        private static IGeometry SimplifyPath2D(IGeometry path, bool bReverse, double simpFactor)
        {
            IGeometry         oldPath            = path;
            IPointCollection  oldPointCollection = oldPath as IPointCollection;
            IPolyline         newPath            = new PolylineClass();
            IPointCollection  newPointCollection = newPath as IPointCollection;
            ISpatialReference sr = oldPath.SpatialReference;

            int pointCount;

            pointCount = oldPointCollection.PointCount;
            double[] lastCoord = new double[2];

            IPoint beginningPoint = new PointClass();

            oldPointCollection.QueryPoint(bReverse ? (pointCount - 1) : 0, beginningPoint);
            beginningPoint.QueryCoords(out lastCoord[0], out lastCoord[1]);

            bool bKeep = true;

            IPolyline oldLine = oldPath as IPolyline;
            double    length  = oldLine.Length;

            object Missing = Type.Missing;

            newPointCollection.AddPoint(beginningPoint, ref Missing, ref Missing);

            for (int i = 1; i < pointCount - 1; i++) //simplify 2D path
            {
                double[] coord        = new double[2];
                IPoint   currentPoint = new PointClass();
                oldPointCollection.QueryPoint(bReverse ? (pointCount - i - 1) : i, currentPoint);
                currentPoint.QueryCoords(out coord[0], out coord[1]);

                double[] d = new double[2];
                d[0] = coord[0] - lastCoord[0];
                d[1] = coord[1] - lastCoord[1];

                double distance;
                distance = Math.Sqrt(d[0] * d[0] + d[1] * d[1]);

                if (distance < (0.25 * simpFactor * length))
                {
                    bKeep = false;
                }
                else
                {
                    bKeep = true;
                }

                if (bKeep)
                {
                    newPointCollection.AddPoint(currentPoint, ref Missing, ref Missing);
                    lastCoord[0] = coord[0];
                    lastCoord[1] = coord[1];
                }
            }

            IPoint finalPoint = new PointClass();

            oldPointCollection.QueryPoint(bReverse ? 0 : (pointCount - 1), finalPoint);
            newPointCollection.AddPoint(finalPoint, ref Missing, ref Missing);

            newPath.SpatialReference = sr;
            return((IGeometry)newPath);
        }
Example #59
0
 void IOutstationApplication.RecordClassAssignment(AssignClassType type, PointClass clazz, UInt16 start, UInt16 stop)
 {
 }
Example #60
0
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            DF2DApplication app   = DF2DApplication.Application;
            bool            ready = true;

            if (app == null || app.Current2DMapControl == null || app.Workbench == null)
            {
                return;
            }
            app.Workbench.SetMenuEnable(true);
            m_ActiveView = app.Current2DMapControl.ActiveView;
            IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay;

            try
            {
                if (button == 1)
                {
                    ISimpleLineSymbol pLineSym = new SimpleLineSymbol();
                    IRgbColor         pColor   = new RgbColorClass();
                    pColor.Red     = 255;
                    pColor.Green   = 255;
                    pColor.Blue    = 0;
                    pLineSym.Color = pColor;
                    pLineSym.Style = esriSimpleLineStyle.esriSLSSolid;
                    pLineSym.Width = 2;

                    ISimpleFillSymbol pFillSym = new SimpleFillSymbol();

                    pFillSym.Color   = pColor;
                    pFillSym.Style   = esriSimpleFillStyle.esriSFSDiagonalCross;
                    pFillSym.Outline = pLineSym;

                    object      symbol = pFillSym as object;
                    IRubberBand band   = new RubberPolygonClass();
                    IGeometry   geo    = band.TrackNew(m_Display, null);
                    app.Current2DMapControl.DrawShape(geo, ref symbol);
                    WaitForm.Start("正在查询...", "请稍后");

                    if (geo.IsEmpty)
                    {
                        IPoint searchPoint = new PointClass();
                        searchPoint.PutCoords(mapX, mapY);
                        geo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate));
                        //m_ActiveView.FocusMap.SelectByShape(geo, s, false);
                    }
                    _geo         = geo;
                    spatialQuery = true;
                    if (spatialQuery)
                    {
                        FrmCompoundConditionQuery dialog = new FrmCompoundConditionQuery();
                        dialog.SetData(LogicDataStructureManage2D.Instance.RootLogicGroups, LogicDataStructureManage2D.Instance.RootMajorClasses, _geo);
                        WaitForm.Stop();
                        IMap2DView mapView = UCService.GetContent(typeof(Map2DView)) as Map2DView;
                        mapView.UnBind(this);
                        if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            return;
                        }
                        this._uPanel               = new UIDockPanel("查询结果", "查询结果", this.Location, this._width, this._height);
                        this._dockPanel            = FloatPanelManager.Instance.Add(ref this._uPanel, DockingStyle.Right);
                        this._dockPanel.Visibility = DockVisibility.Visible;
                        this._dockPanel.FloatSize  = new System.Drawing.Size(this._width, this._height);
                        this._dockPanel.Width      = this._width;
                        this._dockPanel.Height     = this._height;
                        this._uc      = new UCPropertyInfo2D();
                        this._uc.Dock = System.Windows.Forms.DockStyle.Fill;
                        this._uPanel.RegisterEvent(new PanelClose(this.Close));
                        this._dockPanel.Controls.Add(this._uc);
                        this._uc.SetPropertyInfo(dialog.Dict);
                    }
                }
            }


            catch
            {
                this.RestoreEnv();
            }
        }