Example #1
0
        protected override void OnClick()
        {
            try
            {
                string shpFilePath = string.Format(@"C:\temp\contour datas");
                string shpFileName = "contour2.shp"; // height data

                IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
                IWorkspace workspace = workspaceFactory.OpenFromFile(shpFilePath, 0);
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                IFeatureClass pFeatureClass = featureWorkspace.OpenFeatureClass(shpFileName);
                IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = "";

                IEnvelope pEnv = pFeatureLayer.AreaOfInterest;
                IGeoDataset pGDS = (IGeoDataset)pFeatureLayer.FeatureClass;
                ISpatialReference pSR = pGDS.SpatialReference;
                IGeometry pGeom = pEnv;
                pGeom.Project(pSR);
                ITinEdit pTinEdit = new TinClass();
                pTinEdit.InitNew(pEnv);
                IFields pFields = pFeatureClass.Fields;
                IField pFiled = pFields.get_Field(pFields.FindField("HSL"));
                object Missing = Type.Missing;
                esriTinSurfaceType pTinSurface = esriTinSurfaceType.esriTinHardLine;
                pTinEdit.AddFromFeatureClass(pFeatureClass, pQueryFilter, pFiled, pFiled, pTinSurface, ref Missing);
                string outputFolderPath = @"C:\temp\Output\";
                string tinFolderName = "tin_data";
                pTinEdit.SaveAs(outputFolderPath + tinFolderName, ref Missing);
                MessageBox.Show("end");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            ArcMap.Application.CurrentTool = null;
        }
Example #2
0
        /// <summary>
        /// 创建Tin文件
        /// </summary>
        /// <param name="pFeatureClass">要素类</param>
        private void CreateTinFromFeature(IFeatureClass pFeatureClass)
        {
            try
            {
                IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
                ESRI.ArcGIS.Geometry.IEnvelope pExtent = pGeoDataset.Extent;
                pExtent.SpatialReference = pGeoDataset.SpatialReference;

                //获得高程值
                IFields pFields = pFeatureClass.Fields;
                IField pHeightField;
                pHeightField = pFields.get_Field(3);

                ITinEdit pTinEdit = new TinClass();
                pTinEdit.InitNew(pExtent);
                object Missing = Type.Missing;
                object pbUseShapeZ = Missing;
                object pOverWrite = Missing;

                pTinEdit.AddFromFeatureClass(pFeatureClass, null, pHeightField, null, esriTinSurfaceType.esriTinMassPoint, ref pbUseShapeZ);

                pTinEdit.SaveAs(Application.StartupPath + "\\Convert\\TemTIN\\" + this.Random, ref pOverWrite);
                pTinEdit.StopEditing(false);
                CreateContourData(Application.StartupPath + "\\Convert\\TemTIN");
            }
            catch (Exception)
            {

            }
        }
Example #3
0
        /// <summary>
        /// 创建TIN
        /// </summary>
        private void CreateDelaunay()
        {
            //创建TIN
            IFeatureLayer featureLayer = m_dataInfo.GetInputLayer() as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;
            IField pField = featureClass.Fields.get_Field(0);

            if (pField == null)
            {
                MessageBox.Show("创建Delaunay三角网失败");
                return;
            }

            IGeoDataset pGeoDataset = featureClass as IGeoDataset;
            IEnvelope pEnvelope = pGeoDataset.Extent;
            pEnvelope.SpatialReference = pGeoDataset.SpatialReference;

            ITinEdit pTinEdit = new TinClass();
            pTinEdit.InitNew(pEnvelope);
            object obj = Type.Missing;
            pTinEdit.AddFromFeatureClass(featureClass, null, pField, null, esriTinSurfaceType.esriTinMassPoint, ref obj);
            m_DT = pTinEdit as ITin;

            //将所有点标识为噪声点
            ITinAdvanced tinAdvanced = m_DT as ITinAdvanced;
            for (int i = 0; i < tinAdvanced.NodeCount; i++)
            {
                m_nodeFlag.Add(-1);
            }
        }
        public static IGeometry GetExample15()
        {
            const double CircleDegrees = 360.0;
            const int CircleDivisions = 36;
            const double VectorComponentOffset = 0.0000001;
            const double CircleRadius = 9.5;
            const int PointCount = 100;
            const double UpperZMin = 7;
            const double UpperZMax = 10;
            const double LowerZMin = 0;
            const double LowerZMax = 3;

            //Extrusion: Circle Shaped Base Geometry Extruded Between Two Different TIN-Based Functional Surfaces

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            //Base Geometry

            IPointCollection polygonPointCollection = new PolygonClass();

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10);

            IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10);

            lowerAxisVector3D.XComponent += VectorComponentOffset;

            IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D;

            normalVector3D.Magnitude = CircleRadius;

            double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions);

            for (int i = 0; i < CircleDivisions; i++)
            {
                normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D);

                IPoint vertexPoint = GeometryUtilities.ConstructPoint2D(originPoint.X + normalVector3D.XComponent,
                                                                        originPoint.Y + normalVector3D.YComponent);

                polygonPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing);
            }

            IPolygon polygon = polygonPointCollection as IPolygon;
            polygon.Close();

            IGeometry baseGeometry = polygon as IGeometry;

            ITopologicalOperator topologicalOperator = polygon as ITopologicalOperator;
            topologicalOperator.Simplify();

            //Functional Surfaces

            IEnvelope envelope = new EnvelopeClass();
            envelope.XMin = -10;
            envelope.XMax = 10;
            envelope.YMin = -10;
            envelope.YMax = 10;

            Random random = new Random();

            //Upper Functional Surface

            ITinEdit upperTinEdit = new TinClass();
            upperTinEdit.InitNew(envelope);

            for (int i = 0; i < PointCount; i++)
            {
                double x = envelope.XMin + (envelope.XMax - envelope.XMin) * random.NextDouble();
                double y = envelope.YMin + (envelope.YMax - envelope.YMin) * random.NextDouble();
                double z = UpperZMin + (UpperZMax - UpperZMin) * random.NextDouble();

                IPoint point = GeometryUtilities.ConstructPoint3D(x, y, z);

                upperTinEdit.AddPointZ(point, 0);
            }

            IFunctionalSurface upperFunctionalSurface = upperTinEdit as IFunctionalSurface;

            //Lower Functional Surface

            ITinEdit lowerTinEdit = new TinClass();
            lowerTinEdit.InitNew(envelope);

            for (int i = 0; i < PointCount; i++)
            {
                double x = envelope.XMin + (envelope.XMax - envelope.XMin) * random.NextDouble();
                double y = envelope.YMin + (envelope.YMax - envelope.YMin) * random.NextDouble();
                double z = LowerZMin + (LowerZMax - LowerZMin) * random.NextDouble();

                IPoint point = GeometryUtilities.ConstructPoint3D(x, y, z);

                lowerTinEdit.AddPointZ(point, 0);
            }

            IFunctionalSurface lowerFunctionalSurface = lowerTinEdit as IFunctionalSurface;

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeBetween(upperFunctionalSurface, lowerFunctionalSurface, baseGeometry);

            return constructMultiPatch as IGeometry;
        }
        public static IGeometry GetExample14()
        {
            const int PointCount = 100;
            const double ZMin = 0;
            const double ZMax = 4;

            //Extrusion: Square Shaped Base Geometry Extruded Between Single TIN-Based Functional Surface

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            //Base Geometry

            IEnvelope envelope = new EnvelopeClass();
            envelope.XMin = -10;
            envelope.XMax = 10;
            envelope.YMin = -10;
            envelope.YMax = 10;

            IGeometry baseGeometry = envelope as IGeometry;

            //Upper Functional Surface

            ITinEdit tinEdit = new TinClass();
            tinEdit.InitNew(envelope);

            Random random = new Random();

            for (int i = 0; i < PointCount; i++)
            {
                double x = envelope.XMin + (envelope.XMax - envelope.XMin) * random.NextDouble();
                double y = envelope.YMin + (envelope.YMax - envelope.YMin) * random.NextDouble();
                double z = ZMin + (ZMax - ZMin) * random.NextDouble();

                IPoint point = GeometryUtilities.ConstructPoint3D(x, y, z);

                tinEdit.AddPointZ(point, 0);
            }

            IFunctionalSurface functionalSurface = tinEdit as IFunctionalSurface;

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeBetween(functionalSurface, functionalSurface, baseGeometry);

            return constructMultiPatch as IGeometry;
        }
 /// <summary>
 /// 根据生成的featureclass动态生成tin
 /// </summary>
 /// <params name="pFeatureClass"></params>
 /// <params name="pField"></params>
 /// <params name="pPath"></params>
 /// <returns></returns>
 private ITin CreateTin(IFeatureClass pFeatureClass, IField pField, string pPath)
 {
     IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
     ITinEdit pTinEdit = new TinClass();
       pTinEdit.InitNew(pGeoDataset.Extent);
       object pObj = Type.Missing;
       pTinEdit.AddFromFeatureClass(pFeatureClass, null, pField, null, esriTinSurfaceType.esriTinMassPoint, ref pObj);
       pTinEdit.SaveAs(pPath, ref pObj);
       pTinEdit.Refresh();
      return pTinEdit as ITin;
 }
        private void 打开TinToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // ITinLayer pTinLayer = GetTINLayer(@".\data\IDW数据\dvtin");

             ITinAdvanced2 pTin = new TinClass();
             pTin.Init(@".\data\IDW数据\dvtin");

             ITinLayer pTinLayer = new TinLayerClass();

             pTinLayer.Dataset = pTin;
             axMapControl1.Map.AddLayer(pTinLayer as ILayer);
        }