/// <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) { } }
/// <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); } }
private ITin Create_TIN(IFeatureClass pFeatureClass, IField pField) { 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.Refresh(); return(pTinEdit as ITin); }
/// <summary> /// 高程点生成TIN /// </summary> /// <param name="featureClass">点要素</param> /// <param name="path">保存路径</param> /// <returns>TIN数据</returns> public static ITin CreateTIN(IFeatureClass featureClass, string path) { string folder = System.IO.Path.GetDirectoryName(path); IGeoDataset geoDataset = featureClass as IGeoDataset; IField zField = featureClass.Fields.get_Field(4);//高程字段 ITinEdit tinEdit = new TinClass(); tinEdit.InitNew(geoDataset.Extent); tinEdit.AddFromFeatureClass(featureClass, null, zField, null, esriTinSurfaceType.esriTinMassPoint); if (System.IO.Directory.Exists(folder + "\\tin")) { (new System.IO.DirectoryInfo(folder + "\\tin")).Delete(true); } tinEdit.SaveAs(folder + "\\tin"); tinEdit.Refresh(); tinEdit.StopEditing(true); return(tinEdit as ITin); }
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; }
private List <CPoint> LookingForNeighboursDT(IFeatureLayer pFeatureLayer, double dblThreshold, int intPtNumLast, ref long lngTimeForSearching, ref long lngTimeForDT, ref long lngMemory, ref long lngMemoryDT, ref long lngMemoryDTProcess, ref int intOutPut, string strTINPath) { lngMemory = GC.GetTotalMemory(true); //lngMemoryDT = GC.GetTotalMemory(true); //lngMemoryDTProcess = Process.GetProcessesByName("ContinuousGeneralizer.vshost")[0].WorkingSet64; long lngStartTime = System.Environment.TickCount; //record the start time //lngMemoryDT = Process.GetProcessesByName("ContinuousGeneralizer.vshost")[0].WorkingSet64; //Process .GetProcessesByName("ContinuousGeneralizer.vshost")[0]. //create TIN IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IGeoDataset pGDS = (IGeoDataset)pFeatureClass; IEnvelope pEnv = (IEnvelope)pGDS.Extent; pEnv.SpatialReference = pGDS.SpatialReference; IFields pFields = pFeatureClass.Fields; IField pHeightFiled = new FieldClass(); try { pHeightFiled = pFields.get_Field(pFields.FindField("Id")); } catch (Exception) { pHeightFiled = pFields.get_Field(pFields.FindField("ID")); throw; } //ITinWorkspace ITinEdit pTinEdit = new TinClass(); pTinEdit.InitNew(pEnv); object Missing = Type.Missing; pTinEdit.AddFromFeatureClass(pFeatureClass, null, pHeightFiled, null, esriTinSurfaceType.esriTinHardLine, ref Missing); lngTimeForDT = System.Environment.TickCount - lngStartTime; //Time for constructing DT //long lngMemoryafterTinEdit = GC.GetTotalMemory(false) - lngMemoryDT; //GC.Collect(); //lngMemoryDT = GC.GetTotalMemory(true) - lngMemoryDT; //lngMemoryDTProcess = Process.GetProcessesByName("ContinuousGeneralizer.vshost")[0].WorkingSet64 - lngMemoryDTProcess; //C5.LinkedList<int> intLLt = new C5.LinkedList<int>(); ITinNodeCollection pTinNodeCollection = (ITinNodeCollection)pTinEdit; List <CPoint> CptLt = new List <CPoint>(pTinNodeCollection.NodeCount); for (int i = 1; i <= pTinNodeCollection.NodeCount; i++) //i=1-4: super node { ITinNode pNode = pTinNodeCollection.GetNode(i); CPoint cpt = new CPoint(pNode); //cpt.intTS = new C5.TreeSet<int>(); CptLt.Add(cpt); } //long lngMemoryafterfetching = GC.GetTotalMemory(true); //lngMemoryDT = GC.GetTotalMemory(true) - lngMemoryDT; //Looking for neighbours based on Breadth First Search if (intPtNumLast != -1) { dblThreshold = dblThreshold * Math.Pow(Convert.ToDouble(intPtNumLast) / Convert.ToDouble(CptLt.Count - 4), 0.5); //---------------dblThreshold------------------------------------------------// //Math.Pow(1.8 / Convert.ToDouble(CptLt.Count - 4), 0.5);//---------------dblThreshold------------------------------------------------// } //double dblThresholdDT = (1 + Math.Sqrt(2)) / 2 * dblThreshold; lngTimeForSearching = System.Environment.TickCount; //the start time SCG.LinkedList <int> intTargetLLt = new SCG.LinkedList <int>(); SCG.LinkedList <int> intAllLLt = new SCG.LinkedList <int>(); for (int i = 0; i < CptLt.Count; i++) { CptLt[i].isTraversed = true; intTargetLLt = new SCG.LinkedList <int>(); intTargetLLt.AddLast(CptLt[i].pTinNode.Index); intAllLLt = new SCG.LinkedList <int>(); intAllLLt.AddLast(CptLt[i].pTinNode.Index); while (intTargetLLt.Count > 0) { intTargetLLt = BSF(CptLt[i], ref CptLt, ref intTargetLLt, ref intAllLLt, dblThreshold, ref intOutPut); } intOutPut--; //the point will take itself as a close point, so we have to minus 1 //CptLt[i].intTS.Remove(CptLt[i].pTinNode.Index); RestoreIsTraversed(ref CptLt, ref intAllLLt); //intAllLLt.Dispose(); } //long lngMemoryaftersearch = GC.GetTotalMemory(true); lngTimeForSearching = System.Environment.TickCount - lngTimeForSearching; //the result time lngMemory = GC.GetTotalMemory(true) - lngMemory; pTinEdit.SaveAs(strTINPath + "\\" + pFeatureLayer.Name, true); long lngFileSize = CHelpFunc.GetDirectoryLength(strTINPath + "\\" + pFeatureLayer.Name); lngMemory += lngFileSize; lngMemoryDT = lngFileSize; return(CptLt); }
public void Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages message) { // Get Parameters IGPParameter3 inputParameter = (IGPParameter3)paramvalues.get_Element(0); IGPParameter3 polygonParameter = (IGPParameter3)paramvalues.get_Element(1); IGPParameter3 outputParameter = (IGPParameter3)paramvalues.get_Element(2); IGPParameter3 fieldParameter = (IGPParameter3)paramvalues.get_Element(3); // UnPackGPValue. This ensures you get the value from either the dataelement or GpVariable (ModelBuilder) IGPValue inputParameterValue = m_GPUtilities.UnpackGPValue(inputParameter); IGPValue polygonParameterValue = m_GPUtilities.UnpackGPValue(polygonParameter); IGPValue outputParameterValue = m_GPUtilities.UnpackGPValue(outputParameter); IGPValue fieldParameterValue = m_GPUtilities.UnpackGPValue(fieldParameter); // Decode Input Feature Layers IFeatureClass inputFeatureClass; IFeatureClass polygonFeatureClass; IQueryFilter inputFeatureClassQF; IQueryFilter polygonFeatureClassQF; m_GPUtilities.DecodeFeatureLayer(inputParameterValue, out inputFeatureClass, out inputFeatureClassQF); m_GPUtilities.DecodeFeatureLayer(polygonParameterValue, out polygonFeatureClass, out polygonFeatureClassQF); if (inputFeatureClass == null) { message.AddError(2, "Could not open input dataset."); return; } if (polygonFeatureClass == null) { message.AddError(2, "Could not open clipping polygon dataset."); return; } if (polygonFeatureClass.FeatureCount(null) > 1) { message.AddWarning("Clipping polygon feature class contains more than one feature."); } // Create the Geoprocessor Geoprocessor gp = new Geoprocessor(); // Create Output Polygon Feature Class CreateFeatureclass cfc = new CreateFeatureclass(); IName name = m_GPUtilities.CreateFeatureClassName(outputParameterValue.GetAsText()); IDatasetName dsName = name as IDatasetName; IFeatureClassName fcName = dsName as IFeatureClassName; IFeatureDatasetName fdsName = fcName.FeatureDatasetName as IFeatureDatasetName; // Check if output is in a FeatureDataset or not. Set the output path parameter for CreateFeatureClass tool. if (fdsName != null) { cfc.out_path = fdsName; } else { cfc.out_path = dsName.WorkspaceName.PathName; } // Set the output Coordinate System for CreateFeatureClass tool. // ISpatialReference3 sr = null; IGPEnvironment env = envMgr.FindEnvironment("outputCoordinateSystem"); // Same as Input if (env.Value.IsEmpty()) { IGeoDataset ds = inputFeatureClass as IGeoDataset; cfc.spatial_reference = ds.SpatialReference as ISpatialReference3; } // Use the environment setting else { IGPCoordinateSystem cs = env.Value as IGPCoordinateSystem; cfc.spatial_reference = cs.SpatialReference as ISpatialReference3; } // Remaining properties for Create Feature Class Tool cfc.out_name = dsName.Name; cfc.geometry_type = "POLYGON"; // Execute Geoprocessor gp.Execute(cfc, null); // Get Unique Field int iField = inputFeatureClass.FindField(fieldParameterValue.GetAsText()); IField uniqueField = inputFeatureClass.Fields.get_Field(iField); // Extract Clipping Polygon Geometry IFeature polygonFeature = polygonFeatureClass.GetFeature(0); IPolygon clippingPolygon = (IPolygon)polygonFeature.Shape; // Spatial Filter ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = polygonFeature.ShapeCopy; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; // Debug Message message.AddMessage("Generating TIN..."); // Create TIN ITinEdit tinEdit = new TinClass(); // Advanced TIN Functions ITinAdvanced2 tinAdv = (ITinAdvanced2)tinEdit; try { // Initialize New TIN IGeoDataset gds = inputFeatureClass as IGeoDataset; tinEdit.InitNew(gds.Extent); // Add Mass Points to TIN tinEdit.StartEditing(); tinEdit.AddFromFeatureClass(inputFeatureClass, spatialFilter, uniqueField, uniqueField, esriTinSurfaceType.esriTinMassPoint); tinEdit.Refresh(); // Get TIN Nodes ITinNodeCollection tinNodeCollection = (ITinNodeCollection)tinEdit; // Report Node Count message.AddMessage("Input Node Count: " + inputFeatureClass.FeatureCount(null).ToString()); message.AddMessage("TIN Node Count: " + tinNodeCollection.NodeCount.ToString()); // Open Output Feature Class IFeatureClass outputFeatureClass = m_GPUtilities.OpenFeatureClassFromString(outputParameterValue.GetAsText()); // Debug Message message.AddMessage("Generating Polygons..."); // Create Voronoi Polygons tinNodeCollection.ConvertToVoronoiRegions(outputFeatureClass, null, clippingPolygon, "", ""); // Release COM Objects tinEdit.StopEditing(false); System.Runtime.InteropServices.Marshal.ReleaseComObject(tinNodeCollection); System.Runtime.InteropServices.Marshal.ReleaseComObject(tinEdit); } catch (Exception ex) { message.AddError(2, ex.Message); } }
private void button1_Click(object sender, EventArgs e) { if (mLayerCombox.Text == "" || mFeildCombox.Text == "")//判断输入合法性 { MessageBox.Show("没有相应的图层"); return; } ITinEdit pTin = new TinClass(); //寻找Featurelayer IFeatureLayer pFeatureLayer = mSceneControl.Scene.get_Layer(mLayerCombox.SelectedIndex) as IFeatureLayer; if (pFeatureLayer != null) { IEnvelope pEnvelope = new EnvelopeClass(); IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IQueryFilter pQueryFilter = new QueryFilterClass(); IField pField = null; //找字段 pField = pFeatureClass.Fields.get_Field(pFeatureClass.Fields.FindField(mFeildCombox.Text)); if (pField.Type == esriFieldType.esriFieldTypeInteger || pField.Type == esriFieldType.esriFieldTypeDouble || pField.Type == esriFieldType.esriFieldTypeSingle) //判断类型 { IGeoDataset pGeoDataset = pFeatureLayer as IGeoDataset; pEnvelope = pGeoDataset.Extent; //设置空间参考系 ISpatialReference pSpatialReference; pSpatialReference = pGeoDataset.SpatialReference; //选择生成TIN的输入类型 esriTinSurfaceType pSurfaceTypeCount = esriTinSurfaceType.esriTinMassPoint; switch (mTINType.Text) { case "点": pSurfaceTypeCount = esriTinSurfaceType.esriTinMassPoint; break; case "直线": pSurfaceTypeCount = esriTinSurfaceType.esriTinSoftLine; break; case "光滑线": pSurfaceTypeCount = esriTinSurfaceType.esriTinHardLine; break; } //创建TIN pTin.InitNew(pEnvelope); object missing = Type.Missing; //生成TIN pTin.AddFromFeatureClass(pFeatureClass, pQueryFilter, pField, pField, pSurfaceTypeCount, ref missing); pTin.SetSpatialReference(pGeoDataset.SpatialReference); //创建Tin图层并将Tin图层加入到场景中去 ITinLayer pTinLayer = new TinLayerClass(); pTinLayer.Dataset = pTin as ITin; mSceneControl.Scene.AddLayer(pTinLayer, true); } else { MessageBox.Show("该字段的类型不符合构建TIN的条件"); } } }
/// <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; }