⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convertdxf.cs

📁 arcengine开发的图层输出到dxf
💻 CS
📖 第 1 页 / 共 2 页
字号:
            dct.Add(253, "130|130|130");
            dct.Add(254, "190|190|190");
            dct.Add(255, "255|255|255");

    #endregion Dictionary Color	


		    string[] sColorCAD;  //tutti possibili colori della collection
		    byte bGCAD, bRCAD, bBCAD; //valori RGB di tutti colori
		    byte color=0;
    		
		    //color nearest of collection
		    double dblTemp = Double.MaxValue; 
		    double dblDistance;
    		
		    foreach (byte idx in dct.Keys)
            {
			    sColorCAD = dct[idx].Split('|');
			    bRCAD = byte.Parse(sColorCAD[0]);
			    bGCAD = byte.Parse(sColorCAD[1]);
			    bBCAD = byte.Parse(sColorCAD[2]);

                dblDistance = System.Math.Sqrt((bRCAD - c.Red) ^ 2 + (bGCAD - c.Green) ^ 2 + (bBCAD - c.Blue) ^ 2);
    			
                if (dblDistance < dblTemp)
                {
				    dblTemp = dblDistance;
				    color = idx;
				    if (dblTemp == 0)
					    break;
    				
                }
		    } 

		    //color "0" (not defined) -> color "7" (default of AutoCAD)
		    if (color == 0)
			    color = 7;


            string[] r = dct[color].Split('|');

            return new ColorDXF(byte.Parse(r[0]), byte.Parse(r[1]), byte.Parse(r[2]));
    		
    		
    		
	    }
        static IFormatProvider GetFormatProvider()
        {
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.CurrencyDecimalSeparator = ".";
            return nfi;
        }
        
        void BeginSection(string Tag)
        {
            m_tw.WriteLine(0);
            m_tw.WriteLine("SECTION");
            m_tw.WriteLine(2);
            m_tw.WriteLine(Tag); 
        }
        void EndSection()
        {
            m_tw.WriteLine(0);
            m_tw.WriteLine("ENDSEC");
        }

        void EOF()
        {
            m_tw.WriteLine(0);
            m_tw.WriteLine("EOF");
        }

        void Point(IPointCollection pPoints, string LayerName, byte? Color)
        {
	        for(int i = 0; i<pPoints.PointCount;i++)
		    {

                Point(pPoints.get_Point(i), LayerName,Color);
    			
            }
    	
	    }

        void Blocks()
        {
    	
            BeginSection(TagDXF.BLOCKS);
            EndSection();
    	
	    }
        
        void Tables()
        {

            BeginSection(TagDXF.TABLES);
            EndSection();
    		
        }


        void Point(IPoint pPoint, string LayerName,byte? Color)
        {
            m_tw.WriteLine(0);
            m_tw.WriteLine("POINT");
            m_tw.WriteLine(8);
            m_tw.WriteLine(LayerName);
            m_tw.WriteLine(62);
            if (Color != null)
                m_tw.WriteLine(Color);

            m_tw.WriteLine(10);
            m_tw.WriteLine(pPoint.X.ToString(GetFormatProvider()));
            m_tw.WriteLine(20);
            m_tw.WriteLine(pPoint.Y.ToString(GetFormatProvider()));

            m_tw.WriteLine(39); //Thickness
            m_tw.WriteLine(3);
        }
    	
    	
        void Header(IEnvelope extent)
        {
		    IPoint LLExtents = extent.LowerLeft;
		    IPoint URExtents = extent.UpperRight;

            BeginSection(TagDXF.HEADER);
            
            m_tw.WriteLine(9);
            m_tw.WriteLine("$EXTMIN");
            m_tw.WriteLine(10);
            m_tw.WriteLine(LLExtents.X.ToString(GetFormatProvider()));
            m_tw.WriteLine(20);
            m_tw.WriteLine(LLExtents.Y.ToString(GetFormatProvider()));
            m_tw.WriteLine(30);
            m_tw.WriteLine(0);
            m_tw.WriteLine(9);
            m_tw.WriteLine("$EXTMAX");
            m_tw.WriteLine(10);
            m_tw.WriteLine(URExtents.X.ToString(GetFormatProvider()));
            m_tw.WriteLine(20);
            m_tw.WriteLine(URExtents.Y.ToString(GetFormatProvider()));
            m_tw.WriteLine(30);
            m_tw.WriteLine(0);

            EndSection();
    		
    		
    		
    		
	    }
    	
        

        void Polyline(IGeometry pShape , string LayerName, byte? Color)
	    {

            IGeometryCollection geometryCollection;

            if (pShape is IGeometryCollection)
                geometryCollection = pShape as IGeometryCollection;
            else
            {
                object o = Type.Missing;
                geometryCollection = new Polygon() as IGeometryCollection;
                geometryCollection.AddGeometry(pShape,ref o,ref o);
            }



            for (int j = 0; j < geometryCollection.GeometryCount; j++)
            {
                ISegmentCollection pSegColl = geometryCollection.get_Geometry(j) as ISegmentCollection;

                bool bFirstSeg = true;
                ICircularArc pCA = null;
                ISegment pSeg = null;

                for (int i = 0; i < pSegColl.SegmentCount; i++)
                {
                    pSeg = pSegColl.get_Segment(i);


                    switch (pSeg.GeometryType)
                    {
                        case esriGeometryType.esriGeometryLine:

                            if (bFirstSeg)
                            {

                                m_tw.WriteLine(0);
                                m_tw.WriteLine("POLYLINE");

                                //if (Entity != null)
                                //{
                                //    textWriter.WriteLine(5);
                                //    textWriter.WriteLine(Entity);
                                //}

                                m_tw.WriteLine(8);

                                m_tw.WriteLine(LayerName);

                                m_tw.WriteLine(66);
                                m_tw.WriteLine(1);


                                if (Color != null)
                                {
                                    m_tw.WriteLine(62);
                                    m_tw.WriteLine(Color);
                                }




                                m_tw.WriteLine(6);
                                m_tw.WriteLine("CONTINUOUS");
                                //from point
                                m_tw.WriteLine(0);
                                m_tw.WriteLine("VERTEX");
                                m_tw.WriteLine(8);

                                m_tw.WriteLine(LayerName);

                                m_tw.WriteLine(10);
                                m_tw.WriteLine(pSeg.FromPoint.X.ToString(GetFormatProvider()));
                                m_tw.WriteLine(20);
                                m_tw.WriteLine(pSeg.FromPoint.Y.ToString(GetFormatProvider()));

                                bFirstSeg = !bFirstSeg;
                            }

                            // to point
                            m_tw.WriteLine(0);
                            m_tw.WriteLine("VERTEX");
                            m_tw.WriteLine(8);
                            m_tw.WriteLine(LayerName);

                            m_tw.WriteLine(10);
                            m_tw.WriteLine(pSeg.ToPoint.X.ToString(GetFormatProvider()));
                            m_tw.WriteLine(20);
                            m_tw.WriteLine(pSeg.ToPoint.Y.ToString(GetFormatProvider()));





                            if (i == (pSegColl.SegmentCount - 1))
                            {
                                m_tw.WriteLine(0);
                                m_tw.WriteLine("SEQEND");
                                m_tw.WriteLine(8);
                                m_tw.WriteLine(LayerName);


                            }

                            break;

                        case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryCircularArc:
                            if (!bFirstSeg)
                            {

                                m_tw.WriteLine(0);
                                m_tw.WriteLine("SEQEND");
                                m_tw.WriteLine(8);
                                m_tw.WriteLine(LayerName);
                            }

                            pCA = pSeg as ICircularArc;

                            m_tw.WriteLine(0);
                            m_tw.WriteLine("ARC");
                            m_tw.WriteLine(8);
                            m_tw.WriteLine(LayerName);
                            m_tw.WriteLine(10);
                            m_tw.WriteLine(pCA.CenterPoint.X.ToString(GetFormatProvider()));
                            m_tw.WriteLine(20);
                            m_tw.WriteLine(pCA.CenterPoint.Y.ToString(GetFormatProvider()));
                            m_tw.WriteLine(40);
                            m_tw.WriteLine(pCA.Radius);

                            string sFromAngle = (pCA.FromAngle * 180 / Math.PI).ToString(GetFormatProvider());
                            string sToAngle = (pCA.ToAngle * 180 / Math.PI).ToString(GetFormatProvider());

                            m_tw.WriteLine(50);
                            m_tw.WriteLine(pCA.IsCounterClockwise ? sFromAngle : sToAngle);
                            m_tw.WriteLine(51);
                            m_tw.WriteLine(pCA.IsCounterClockwise ? sToAngle : sFromAngle);

                            bFirstSeg = true;
                            break;


                    }

                }
            }
    		
	    }


        void Polygon(IGeometry pShape, string LayerName, byte? Color)
        {

            IPolygon4 polygon = pShape as IPolygon4;
            IGeometryBag exteriorRings = polygon.ExteriorRingBag;
     
            //For each exterior rings find the interior rings associated with it
            IEnumGeometry exteriorRingsEnum = exteriorRings as IEnumGeometry;
            exteriorRingsEnum.Reset();
            IRing currentExteriorRing = exteriorRingsEnum.Next() as IRing;
              
             
            while(currentExteriorRing != null)
            {
                   Polyline(currentExteriorRing, LayerName, Color);

                   IGeometryBag interiorRings = polygon.get_InteriorRingBag(currentExteriorRing);
                   IEnumGeometry interiorRingsEnum = interiorRings as IEnumGeometry;
                   interiorRingsEnum.Reset();
                   IRing currentInteriorRing = interiorRingsEnum.Next() as IRing;
                   while(currentInteriorRing != null)
                   {
                       Polyline(currentInteriorRing, LayerName, Color);
                       currentInteriorRing = interiorRingsEnum.Next() as IRing;
                   }

               currentExteriorRing = exteriorRingsEnum.Next() as IRing;
             
            }

		
		}

        void Entities()
        {


        BeginSection(TagDXF.ENTITIES);


        byte? Color = 7;
        string LayerName = m_FeatureLayer.Name;

        IFeatureClass featureClass = m_FeatureLayer.FeatureClass;
        IFeatureCursor featureCursor = featureClass.Search(null,true);
        IFeature feature = featureCursor.NextFeature();
        IGeometry shape =null;
        
        while(feature != null)
        {

		    shape = feature.ShapeCopy;
            //int? OID = feature.HasOID ? feature.OID : new Nullable<int>();

			switch( shape.GeometryType)
            {
                case esriGeometryType.esriGeometryPoint:
                    Point(shape as IPoint, LayerName, Color);
                    break;
                case esriGeometryType.esriGeometryMultipoint:
                    Point(shape as IPointCollection, LayerName, Color);
                    break;
                case esriGeometryType.esriGeometryPolyline:
					Polyline(shape,LayerName,Color);
                    break;
                case esriGeometryType.esriGeometryPolygon:
                    Polygon(shape,LayerName,Color);
                    break;
                case esriGeometryType.esriGeometryEnvelope:
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPath:
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny:
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryRing:
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryLine:
                    Polyline(shape,LayerName,Color);
                    break;
				case esriGeometryType.esriGeometryCircularArc:
				case esriGeometryType.esriGeometryBezier3Curve:
				case esriGeometryType.esriGeometryEllipticArc:
                    break;
            }
									
									
            feature = featureCursor.NextFeature();
        }

        EndSection();
        EOF();

		}

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -