/// <summary> /// Converts the given inFeatureClass to a 3d featureclass using the given height field. If out featureclass exist it will be overwritten. /// </summary> /// <param name="inFeatureClass"></param> /// <param name="outFeatureClass"></param> /// <param name="heightField"></param> public static void Convert2dTo3dByAttr(object inFeatureClass, object outFeatureClass, object heightField, object toHeightField = null) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { Delete(outFeatureClass); FeatureTo3DByAttribute featureTo3D = new FeatureTo3DByAttribute(inFeatureClass, outFeatureClass, heightField) { to_height_field = toHeightField }; geoprocessor.Execute(featureTo3D, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void TableToTable(ITable srcTable, string outputLocation, string outputFcName, string where = null, object fieldMapping = null) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { TableToTable fcToFc = new TableToTable(srcTable, outputLocation, outputFcName) { field_mapping = fieldMapping, where_clause = where }; geoprocessor.Execute(fcToFc, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void AddField(object table, string fieldName, string fieldtype) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { AddField addField = new AddField(table, fieldName, fieldtype); geoprocessor.Execute(addField, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
private void Analyze(string filePath) { Geoprocessor gp = new Geoprocessor(); ESRI.ArcGIS.DataManagementTools.Project tool = new ESRI.ArcGIS.DataManagementTools.Project(); tool.in_dataset = filePath; tool.in_coor_system = filePath.GetShpSpatialReference(); tool.out_dataset = System.IO.Path.Combine(OutFolder, System.IO.Path.GetFileNameWithoutExtension(filePath) + "-Project.shp"); tool.out_coor_system = SpatialReference; try { var result = gp.Execute(tool, null) as IGeoProcessorResult; if (result == null) { var error = string.Empty; for (var i = 0; i < gp.MessageCount; i++) { error += gp.GetMessage(i); } Console.WriteLine("投影失败!错误信息:" + error); } }catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
/// <summary> /// 执行GP工具 /// </summary> /// <param name="process"></param> /// <returns></returns> private object Execute(IGPProcess process) { m_gp.OverwriteOutput = true; m_gp.TemporaryMapLayers = false; object sev = null; object obj = null; try { obj = m_gp.Execute(process, null); object subObj = null; string msg = m_gp.GetMessages(ref subObj); SendMessage(enumMessageType.OperationalLog, msg); } catch (Exception ex) { SendMessage(enumMessageType.Exception, ex.ToString()); string msg = m_gp.GetMessage(2); } finally { if (obj != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); } } return(obj); }
//执行计算,输出计算结果信息字符串 private string FieldCal(IFeatureLayer pFtLayer, string strExpression) { txtMessage.Text = "正在计算请稍后……\r\n"; try { Geoprocessor Gp = new Geoprocessor(); Gp.OverwriteOutput = true; CalculateField calField = new CalculateField(); calField.expression = strExpression; Gp.Execute(calField, null); for (int i = 0; i < Gp.MessageCount; i++) { txtMessage.Text += Gp.GetMessage(i).ToString() + "\r\n"; } return "计算成功"; } catch (Exception e) { txtMessage.Text += e.Message; return "计算失败" + e.Message; } }
//执行计算,输出计算结果信息字符串 private string FieldCal(IFeatureLayer pFtLayer, string strExpression) { txtMessage.Text = "正在计算请稍后……\r\n"; try { Geoprocessor Gp = new Geoprocessor(); Gp.OverwriteOutput = true; CalculateField calField = new CalculateField(); calField.expression = strExpression; Gp.Execute(calField, null); for (int i = 0; i < Gp.MessageCount; i++) { txtMessage.Text += Gp.GetMessage(i).ToString() + "\r\n"; } return("计算成功"); } catch (Exception e) { txtMessage.Text += e.Message; return("计算失败" + e.Message); } }
public static void JoinField(object in_data, object in_field, object join_table, object join_field, params string[] joinFields) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { JoinField joinFld = new JoinField(in_data, in_field, join_table, join_field) { fields = string.Join(",", joinFields) }; geoprocessor.Execute(joinFld, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int i = 0; i < geoprocessor.MessageCount; i++) { excMessage += geoprocessor.GetMessage(i) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void InterpolateShape(object in_surface, object in_feature_class, object out_feature_class, bool verticesOnly = false) { Geoprocessor geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { InterpolateShape inter = new InterpolateShape(in_surface, in_feature_class, out_feature_class); if (verticesOnly) { inter.vertices_only = "VERTICES_ONLY"; } geoprocessor.Execute(inter, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void RecalculateExtent(string fcPath) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { RecalculateFeatureClassExtent recalcExtent = new RecalculateFeatureClassExtent(fcPath); geoprocessor.Execute(recalcExtent, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void ExportCAD(string cadFilePath, string outputGdb, string outputDatasetName, double refScale = 1000, ISpatialReference sr = null) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { CADToGeodatabase cadToGdb = new CADToGeodatabase(cadFilePath, outputGdb, outputDatasetName, refScale); if (sr != null) { cadToGdb.spatial_reference = sr; } geoprocessor.Execute(cadToGdb, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void Near(object in_features, object near_features, object searchRadius = null) { Geoprocessor geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { Near near = new Near(in_features, near_features) { search_radius = searchRadius }; geoprocessor.Execute(near, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void CalculateField(object table, string fldName, object expression) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { CalculateField fieldCalc = new CalculateField(table, fldName, expression) { expression_type = "PYTHON_9.3" }; geoprocessor.Execute(fieldCalc, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void DeleteFeatures(object infeatures) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { DeleteFeatures del = new DeleteFeatures(infeatures); geoprocessor.Execute(del, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void Append(object inputs, object target) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { Append append = new Append(inputs, target); geoprocessor.Execute(append, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
public static void ExtractValuesToPoints(object points, object raster, object outpoints) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { ExtractValuesToPoints extract = new ExtractValuesToPoints(points, raster, outpoints); geoprocessor.Execute(extract, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
// Function for returning the tool messages. private bool ReturnMessages(Geoprocessor gp) { bool noErrors = true; try { if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { string s = gp.GetMessage(Count); if (s.Contains("ERROR"))// || s.Contains("WARNING 000117")) { if (s.Contains("Virmem low memory")) { //System.Windows.Forms.MessageBox.Show(s); noErrors = false; } } mLog.Debug(s); } } } catch (System.Exception ex) { eLog.Debug(ex); } return(noErrors); }
public static void AlterField(object inFeatureClass, object field, string newName, string newAlias = null) { var geoprocessor = new Geoprocessor() { OverwriteOutput = true, AddOutputsToMap = false }; try { AlterField alter = new AlterField(inFeatureClass, field) { new_field_name = newName, new_field_alias = newAlias ?? newName }; geoprocessor.Execute(alter, null); } catch (Exception) { if (geoprocessor.MessageCount > 0) { string excMessage = null; for (int Count = 0; Count <= geoprocessor.MessageCount - 1; Count++) { excMessage += geoprocessor.GetMessage(Count) + Environment.NewLine; } throw new Exception(excMessage); } } }
private void ExecuteGP(IGPProcess GPProcess) { Geoprocessor gp = new Geoprocessor { OverwriteOutput = true }; try { IGeoProcessorResult2 result = gp.Execute(GPProcess, null) as IGeoProcessorResult2; } catch (Exception ex) { MessageBox.Show(ex.Message, "GP Error"); } finally { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < gp.MessageCount; i++) { sb.AppendLine(gp.GetMessage(i)); } if (sb.Capacity > 0) { MessageBox.Show(sb.ToString(), "GP Messages"); } } }
// Function for returning the tool messages. private static void ReturnMessages(Geoprocessor gp) { if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { Console.WriteLine(gp.GetMessage(Count)); } } }
protected virtual void ReturnMessages(Geoprocessor gp) { if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { Console.WriteLine(gp.GetMessage(Count)); } } }
// Function for returning the tool messages. private void ReturnMessages(Geoprocessor gp) { string ms = ""; if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { ms += gp.GetMessage(Count); } } }
public static void Messages(Exception ex, ref Geoprocessor gp) { Console.WriteLine("..EXCEPTION: " + ex.Message); if (gp.MessageCount <= 0) { return; } for (var i = 0; i < gp.MessageCount; i++) { Console.WriteLine(".." + gp.GetMessage(i)); } }
public static bool ExportLayer2Dwg(IList <IFeatureLayer> pInPutLayerList, string outputfile) { Geoprocessor GP = new Geoprocessor(); GP.OverwriteOutput = true;//覆盖同名 GP.SetEnvironmentValue("workspace", @"C:\temp"); StringBuilder builder = new StringBuilder(); for (int i = 0; i < pInPutLayerList.Count; i++) { IFeatureLayer layer = pInPutLayerList[i]; IDataset dataset = layer.FeatureClass as IDataset; string layerfullname = dataset.Workspace.PathName + "\\" + dataset.Name; builder.Append(layerfullname + ";"); } string fullfilepath = builder.ToString().Substring(0, builder.Length - 1); ExportCAD exportcad = new ExportCAD(); exportcad.in_features = fullfilepath; exportcad.Output_Type = "DWG_R2010"; exportcad.Output_File = outputfile; try { IGeoProcessorResult results = (IGeoProcessorResult)GP.Execute(exportcad, null); string msg = ""; if (GP.MessageCount > 0) { for (int i = 0; i < GP.MessageCount; i++) { msg += GP.GetMessage(i) + "\n"; } } if (msg.Contains("Successed")) { return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
/// <summary> /// 输出地理处理的过程信息 /// </summary> /// <param name="gp"></param> /// <returns></returns> public static string GetMessages2(Geoprocessor gp) { StringBuilder msgBuilder = new StringBuilder(); if (gp != null) { for (int i = 0; i < gp.MessageCount; i++) { msgBuilder.Append(gp.GetMessage(i)); msgBuilder.Append(" "); } } return msgBuilder.ToString(); }
//------------------------------------------------------------------------- private static IEnumerable <string> ReturnMessages(Geoprocessor gp) { if (gp.MessageCount > 0) { var result = new string[gp.MessageCount]; for (int count = 0; count < gp.MessageCount; count++) { result[count] = gp.GetMessage(count); log.WarnEx(result[count]); } } return(null); }
private string GetGPMessages(Geoprocessor gp) { string text = string.Empty; if (gp.MessageCount > 0) { for (int i = 0; i < gp.MessageCount; i++) { text = text + gp.GetMessage(i) + "\n"; } } return(text); }
private static string ReturnMessages(Geoprocessor gp) { string msgRet = ""; if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { msgRet += gp.GetMessage(Count); } } return(msgRet); }
public static void Messages(Exception ex, ref Geoprocessor gp) { _msg.Items.Add("..EXCEPTION: " + ex.Message); if (gp.MessageCount <= 0) { return; } for (var i = 0; i < gp.MessageCount; i++) { _msg.Items.Add(".." + gp.GetMessage(i)); } _msg.Items.Add(">>>>>>>>>>>>>>>"); _msg.Refresh(); }
/// <summary> /// GP处理结果信息 /// </summary> /// <param name="gp">GP对象</param> private static void ReturnMessages(Geoprocessor gp) { string ms = ""; if (gp.MessageCount > 0) { for (int i = 0; i <= gp.MessageCount - 1; i++) { ms += "$" + gp.GetMessage(i) + "\n\n"; } } MessageBox.Show(ms); }
/// <summary> /// 输出地理处理的过程信息 /// </summary> /// <param name="gp"></param> /// <returns></returns> public static string GetMessages2(Geoprocessor gp) { StringBuilder msgBuilder = new StringBuilder(); if (gp != null) { for (int i = 0; i < gp.MessageCount; i++) { msgBuilder.Append(gp.GetMessage(i)); msgBuilder.Append(" "); } } return(msgBuilder.ToString()); }
/// <summary> /// 提供消息处理 /// </summary> /// <param name="geoprocessor"></param> private void ReturnMessages(Geoprocessor geoprocessor) { string ms = ""; if (geoprocessor.MessageCount > 0) { for (int count = 0; count < geoprocessor.MessageCount - 1; count++) { ms += geoprocessor.GetMessage(count) + "\n"; } } MessageBox.Show(ms); }
/// <summary> /// 创建FeatureClasss文件 /// </summary> /// <param name="_strFullPath">文件名</param> /// <param name="spatial_reference">空间参考</param> /// <returns></returns> public static IFeatureClass CreateFeatureClass(string _strFullPath, string spatial_reference) { int index = _strFullPath.LastIndexOf("\\"); string strShapeFolder = _strFullPath.Substring(0, index); string strShapeFile = _strFullPath.Substring(index + 1); DirectoryInfo di = new DirectoryInfo(strShapeFolder); if (!di.Exists) { di.Create(); } Geoprocessor gp = new Geoprocessor(); ESRI.ArcGIS.DataManagementTools.CreateFeatureclass createFs = new ESRI.ArcGIS.DataManagementTools.CreateFeatureclass(); createFs.geometry_type = "POLYGON"; createFs.out_name = strShapeFile; createFs.out_path = strShapeFolder; createFs.spatial_reference = spatial_reference; try { gp.AddOutputsToMap = false; gp.OverwriteOutput = true; gp.Execute(createFs, null); } catch { string error = ""; for (int i = 0; i < gp.MessageCount; i++) { error += gp.GetMessage(i); } } gp.ResetEnvironments(); IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(strShapeFolder, 0) as IFeatureWorkspace; IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strShapeFile); return(pFeatureClass); }
//GP message handling private static void ReturnMessages(Geoprocessor gp) { if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { System.Console.WriteLine(gp.GetMessage(Count)); } } }
private static string ReturnMessages(Geoprocessor gp) { string msgRet = ""; if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { msgRet += gp.GetMessage(Count); } } return msgRet; }
private string ReturnMessages(Geoprocessor gp) { StringBuilder sb = new StringBuilder(); if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { System.Diagnostics.Trace.WriteLine(gp.GetMessage(Count)); sb.AppendFormat("{0}\n", gp.GetMessage(Count)); } } return sb.ToString(); }
// Function for returning the tool messages. private static void ReturnMessages(Geoprocessor gp) { string ms = ""; if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { ms += gp.GetMessage(Count); } } }
/// <summary> /// Cria um shapefile a partir de um featureCursor /// </summary> /// <param name="feature">Feature desejada</param> public static void CriarShapefile(IFeatureLayer fLayer, IFeature feature, string pasta, IActiveView activeView, bool adicionarSaidaNoMapa, IFeatureWorkspace pFeatureWorkspaceShp) { if (feature != null) { #region Deletando shapefiles que possam existir já no diretório DirectoryInfo dirInf = new DirectoryInfo(pasta); FileInfo[] fi = dirInf.GetFiles(); for (int i = 0; i < fi.Length; i++) { if (fi[i].Name.Contains(fLayer.FeatureClass.AliasName) && !fi[i].Name.Contains(".lock")) { fi[i].Delete(); } } #endregion IWorkspace pScratchWorkspace; IScratchWorkspaceFactory pScratchWorkspaceFactory; pScratchWorkspaceFactory = new ScratchWorkspaceFactoryClass(); pScratchWorkspace = pScratchWorkspaceFactory.DefaultScratchWorkspace; IFeatureSelection pNewSelSet = fLayer as IFeatureSelection; IEnvelope pEnv = activeView.Extent.Envelope; IGeometry pEnvGeo = pEnv as IEnvelope; ISpatialFilter pSF = new SpatialFilterClass(); pSF.Geometry = pEnvGeo; pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IQueryFilter qf = new QueryFilterClass(); qf.WhereClause = (fLayer as IFeatureLayerDefinition).DefinitionExpression; pNewSelSet.SelectFeatures(qf, esriSelectionResultEnum.esriSelectionResultNew, false); Geoprocessor gp = new Geoprocessor(); gp.AddOutputsToMap = adicionarSaidaNoMapa; FeatureClassToShapefile fcToShapeFile = new FeatureClassToShapefile(); fcToShapeFile.Input_Features = fLayer; fcToShapeFile.Output_Folder = pasta; IGeoProcessorResult result = gp.Execute(fcToShapeFile, null) as IGeoProcessorResult; string nomeArquivoSaida = gp.GetMessage(3); IFeatureClass pFeatureClassShp = pFeatureWorkspaceShp.OpenFeatureClass(fLayer.FeatureClass.AliasName); GisUtils.TratarSubtiposDominiosShapefile(fLayer, pasta, pFeatureWorkspaceShp, pFeatureClassShp); pFeatureClassShp = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }
// Function for returning the tool messages. private static bool ReturnMessages(Geoprocessor gp) { bool theReturn = true; if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { string msg = gp.GetMessage(Count); if (msg.Contains("Failed to execute")) theReturn = false; Debug.WriteLine(msg); } } return theReturn; }
private string ExportPages(IActiveView docActiveView, int iDPI, string filename, enumExportType exportType, double paperWidth, double paperHeight, int blockCount) { string filepath = filename.Substring(0, filename.LastIndexOf("\\")); string NameExt = System.IO.Path.GetFileName(filename); if (docActiveView is IPageLayout) { double width = 0, height = 0; //实际长宽 //计算分页地图大小 paperWidth,paperHeight //分块数量 blockCount //计算分页图片大小 iWidth,iHeight #region 计算出图参数 var pPageLayout = docActiveView as IPageLayout; pPageLayout.Page.QuerySize(out width, out height); IUnitConverter pUnitCon = new UnitConverterClass(); switch (exportType) { case enumExportType.byPaperSize: if (paperWidth <= 0 || paperHeight <= 0) { paperWidth = 210; paperHeight = 297; } paperWidth = pUnitCon.ConvertUnits(paperWidth, esriUnits.esriMillimeters, pPageLayout.Page.Units); paperHeight = pUnitCon.ConvertUnits(paperHeight, esriUnits.esriMillimeters, pPageLayout.Page.Units); bool bW = (width > paperWidth + 0.001) ? true : false; bool bH = (height > paperHeight + 0.001) ? true : false; blockCount = (bW && bH) ? 4 : 1; break; case enumExportType.byBlockCount: default: if (blockCount < 1) blockCount = 1; paperWidth = width / blockCount; paperHeight = height / blockCount; break; } int iWidth = (int)(pUnitCon.ConvertUnits(paperWidth, pPageLayout.Page.Units, esriUnits.esriInches) * iDPI); int iHeight = (int)(pUnitCon.ConvertUnits(paperHeight, pPageLayout.Page.Units, esriUnits.esriInches) * iDPI); #endregion if (System.IO.File.Exists(filename)) { var pWS = OpenWorkspace(filename, enumWsFactoryType.Raster) as IRasterWorkspace; var pRDs = pWS.OpenRasterDataset(NameExt); var pDS = pRDs as IDataset; pDS.Delete(); } if (blockCount > 1) { #region 创建子目录,获得扩展名 string NameNoExt = System.IO.Path.GetFileNameWithoutExtension(filename); string sExt = System.IO.Path.GetExtension(filename).ToLower(); //创建子目录 string subPath = filename.Substring(0, filename.LastIndexOf(".")); if (System.IO.Directory.Exists(subPath)) { System.IO.Directory.Delete(subPath, true); } try { System.IO.Directory.CreateDirectory(subPath); if (!System.IO.Directory.Exists(subPath)) { subPath = subPath + "_1"; System.IO.Directory.CreateDirectory(subPath); } } catch (Exception ex) { MessageBox.Show(ex.Message); subPath = subPath + "_1"; System.IO.Directory.CreateDirectory(subPath); } //worldfile扩展名 string worldfileExt = "." + sExt[1].ToString() + sExt[sExt.Length - 1].ToString() + "w"; #endregion #region 分页输出 int index = 0; int minX = 0, maxY = iHeight; double w, h = 0; string t_name = subPath + @"\" + NameNoExt + "_"; IExport docExport = CreateExport(filename, 1); IEnvelope pEnv1 = new EnvelopeClass(); while (h < height - 0.0001) { w = 0; minX = 0; while (w < width - 0.0001) { pEnv1.XMin = w; pEnv1.YMin = h; pEnv1.XMax = w + paperWidth; pEnv1.YMax = h + paperHeight; index++; label1.Text += "."; Application.DoEvents(); //output输出 ActiveViewOutput(docActiveView, iDPI, iWidth, iHeight, pEnv1, t_name + index.ToString() + sExt, docExport); //写入worldfile WriteWorldfile(t_name + index.ToString() + worldfileExt, 1, 0, 0, -1, minX, maxY); w += paperWidth; minX += iWidth; } h += paperHeight; maxY += iHeight; } #endregion #region 合并栅格 //设置坐标参考 var pRasterWS = OpenWorkspace(subPath, enumWsFactoryType.Raster); ISpatialReferenceFactory2 pSrF = new SpatialReferenceEnvironmentClass(); var pSR = pSrF.CreateSpatialReference(3857); var pEnumDS = pRasterWS.get_Datasets(esriDatasetType.esriDTRasterDataset); var pDS = pEnumDS.Next(); while (pDS != null) { var GeoSchEdit = pDS as IGeoDatasetSchemaEdit; if (GeoSchEdit.CanAlterSpatialReference) GeoSchEdit.AlterSpatialReference(pSR); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pDS); pDS = pEnumDS.Next(); } System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pRasterWS); //saveas时占用很大内存且不释放,使用GP工具 //怎么不创建金字塔和头文件?? Geoprocessor geoprocessor = new Geoprocessor(); try { CreateRasterDataset createRD = new CreateRasterDataset(); createRD.cellsize = 1; createRD.number_of_bands = 3; createRD.out_path = filepath; createRD.out_name = NameExt; createRD.pyramids = "NONE"; createRD.compression = "NONE"; geoprocessor.Execute(createRD, null); WorkspaceToRasterDataset MosaicToRaster = new WorkspaceToRasterDataset(); MosaicToRaster.in_workspace = subPath; MosaicToRaster.in_raster_dataset = filename; geoprocessor.Execute(MosaicToRaster, null); } catch (Exception exc) { Console.WriteLine(exc.Message); for (int i = 0; i < geoprocessor.MessageCount; i++) { string abc = geoprocessor.GetMessage(i); Console.WriteLine(abc); } } #endregion return subPath; } else { Export10Plus(docActiveView, filename, iDPI, 0, 0, null); return ""; } } else //map { return ""; } }