/// <summary>
        /// 坐标转换
        /// </summary>
        /// <param name="in_dataset"></param>
        /// <param name="in_coor_system"></param>
        /// <param name="out_dataset"></param>
        /// <param name="out_coor_system"></param>
        /// <param name="CustomGeoTransformation"></param>
        /// <param name="msgLog"></param>
        /// <returns></returns>
        public static bool GPGeoTransformation(string in_dataset, string in_coor_system, string out_dataset, string out_coor_system,
                                               string CustomGeoTransformation, out string msgLog)
        {
            msgLog = string.Empty;

            try
            {
                ESRI.ArcGIS.DataManagementTools.Project pAppend = new ESRI.ArcGIS.DataManagementTools.Project();
                gp.OverwriteOutput      = false;
                pAppend.in_dataset      = in_dataset;
                pAppend.in_coor_system  = in_coor_system;
                pAppend.out_dataset     = out_dataset;
                pAppend.out_coor_system = out_coor_system;
                if (!string.IsNullOrEmpty(CustomGeoTransformation))
                {
                    pAppend.transform_method = CustomGeoTransformation;
                }
                gp.Execute(pAppend, null);
                if (!ReturnErrMessage(gp, ref msgLog))
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                ReturnErrMessage(gp, ref msgLog);
                return(false);
            }

            msgLog = "";
            return(true);
        }
Example #2
0
        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());
            }
        }
Example #3
0
        //做投影变换
        private void ProjectClass(out string strRes)
        {
            strRes = "";

            if (this.lstLyrFile.Items.Count < 0)
            {
                return;
            }
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            for (int i = 0; i < this.lstLyrFile.Items.Count; i++)
            {
                if (!this.lstLyrFile.Items[i].Checked)
                {
                    continue;
                }
                string strFeaName = this.lstLyrFile.Items[i].Text;
                this.lblTips.Text = "正在进行投影转换:" + strFeaName;

                ESRI.ArcGIS.DataManagementTools.Project prjtool = new ESRI.ArcGIS.DataManagementTools.Project();
                prjtool.in_dataset = this.txtSource.Text + "\\" + strFeaName;
                if (rdoSHP.Checked && !prjtool.in_dataset.ToString().EndsWith(".shp"))
                {
                    prjtool.in_dataset += ".shp";//shp文件入口需加后缀名
                }
                prjtool.out_dataset     = this.txtGdbFile.Text + "\\" + strFeaName;
                prjtool.out_coor_system = m_strOutPrj;
                //


                bool bres = RunTool(gp, prjtool);

                if (!bres)
                {
                    strRes = strRes + "'" + strFeaName + "'转换失败\r\n";
                }
                else
                {
                    strRes = strRes + "'" + strFeaName + "'转换成功\r\n";
                }

                prjtool = null;

                this.progressBarX1.PerformStep();
            }
            gp = null;
        }
Example #4
0
        //做投影变换
        private void ProjectClass()
        {
            if (this.lstLyrFile.Items.Count < 0)
            {
                return;
            }

            for (int i = 0; i < this.lstLyrFile.Items.Count; i++)
            {
                if (!this.lstLyrFile.Items[i].Checked)
                {
                    continue;
                }
                string strFeaName = this.lstLyrFile.Items[i].Text;
                this.lblTips.Text = "正在进行坐标转换:" + strFeaName;

                ESRI.ArcGIS.DataManagementTools.Project prjtool = new ESRI.ArcGIS.DataManagementTools.Project();
                prjtool.in_dataset = this.txtSource.Text + "\\" + strFeaName;
                if (rdoSHP.Checked && !prjtool.in_dataset.ToString().EndsWith(".shp"))
                {
                    prjtool.in_dataset += ".shp";//shp文件入口需加后缀名
                }
                prjtool.out_dataset     = this.txtGdbFile.Text + "\\" + strFeaName;
                prjtool.out_coor_system = m_strOutPrj;

                //考虑到直接做投影的方式 不进行偏移和旋转
                if (this.dtTns.DataSource != null)
                {
                    prjtool.transform_method = "temp";
                }

                //
                Geoprocessor gp = new Geoprocessor();
                gp.OverwriteOutput = true;

                RunTool(gp, prjtool);

                this.progressBarX1.PerformStep();
            }
        }
Example #5
0
        public static ISpatialReference ProjectWorkspaceContents(
			IWorkspace w,
			FileInfo pgdb,
			Dictionary<string,ISpatialReference> outputSRDict,
			int hWnd)
        {
            bool bHaveStartedProjecting = false;
            string theBackup = "";
            IStepProgressor theStepProgressor = null;
            ISpatialReference theReturn = null;

            try
            {
                // Get the default SR (if set)
                ISpatialReference theDefaultSR = null;
                if (outputSRDict.ContainsKey("*"))
                    theDefaultSR = outputSRDict["*"];

                // Check for schema locks
                IEnumDataset theEnumDataset = w.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                ISchemaLock theSLock = theEnumDataset.Next() as ISchemaLock;
                int datasetCount = 0;

                while (theSLock != null)
                {
                    datasetCount++;
                    try
                    {
                        theSLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                        theSLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                    }
                    catch (Exception ex)
                    {
                        string msg = "There is an exclusive lock. Please ensure you do not have ArcCatalog running.";
                        MessageBox.Show(msg);
                        throw new ExclusiveLockException(msg, ex);
                    }

                    theSLock = theEnumDataset.Next() as ISchemaLock;
                }

                if (hWnd != 0)
                {
                    IProgressDialogFactory theFactory = new ProgressDialogFactoryClass();
                    IProgressDialog2 thePDialog = (IProgressDialog2)theFactory.Create(null, hWnd);
                    theStepProgressor = (IStepProgressor)thePDialog;
                    thePDialog.Description = "";
                    thePDialog.Title = "Projecting Transaction";
                    thePDialog.Animation = esriProgressAnimationTypes.esriProgressGlobe;

                    theStepProgressor = (IStepProgressor)thePDialog;
                    theStepProgressor.MinRange = 0;
                    theStepProgressor.MaxRange = datasetCount + 2;
                    theStepProgressor.StepValue = 1;
                }

                // Make a backup copy of the database
                //if (theStepProgressor != null) theStepProgressor.Message = "Creating backup file";
                //theBackup = CreateBackup(pgdb);
                if (theStepProgressor != null) theStepProgressor.Step();

                if (theStepProgressor != null) theStepProgressor.Message = "Initializing Geoprocessor";
                Geoprocessor theGP = SetupGPEnvironment(pgdb.FullName);
                if (theStepProgressor != null) theStepProgressor.Step();

                IGPProcess theGPProc = null;

                // Do feature datasets
                theEnumDataset = w.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                IFeatureDataset theInFDataset = theEnumDataset.Next() as IFeatureDataset;

                // Mark that we're starting to edit the transaction
                tm.dao.MetadataDAO mdao = new tm.dao.MetadataDAO((IFeatureWorkspace)w);
                mdao.markStartReprojecting();
                bHaveStartedProjecting = true;

                while (theInFDataset != null)
                {
                    // Choose the output SR
                    ISpatialReference theOutputSR = null;
                    if (outputSRDict.ContainsKey(theInFDataset.Name))
                        theOutputSR = outputSRDict[theInFDataset.Name];
                    else
                        theOutputSR = theDefaultSR;

                    if (theOutputSR != null)
                    {
                        // Write the output SR to a prj file
                        string prjFile = CreatePrjFile(theOutputSR);
                        theReturn = theOutputSR;

                        string inFDName = pgdb.FullName + System.IO.Path.DirectorySeparatorChar + theInFDataset.Name;
                        string outFDName = inFDName + "_isdut";

                        if (theStepProgressor != null) theStepProgressor.Message = "Projecting " + theInFDataset.Name;

                        theGPProc = new ESRI.ArcGIS.DataManagementTools.Project(inFDName, outFDName, prjFile);

                        if (RunTool(theGP, theGPProc, null))
                        {
                            //Debug.Print("Successful project of " + inFDName + " to " + outFDName);
                            IFeatureDataset theOutFDataset = ((IFeatureWorkspace)w).OpenFeatureDataset(theInFDataset.Name + "_isdut");
                            WriteOutputBack(theInFDataset, theOutFDataset);
                        }
                        else
                        {
                            Debug.Print("Project of " + inFDName + " unsuccessful");
                            throw new GPFailedException("Projection failed for " + inFDName, null);
                        }
                    }
                    else
                    {
                        util.Logger.Write("No SR was defined for feature dataset '" + theInFDataset.Name + "'", util.Logger.LogLevel.Warn);
                    }

                    if (theStepProgressor != null) theStepProgressor.Step();

                    theInFDataset = theEnumDataset.Next() as IFeatureDataset;
                }

                // Editing of the transaction is finished, clear the flag
                mdao.markEndReprojecting();

                try
                {
                    // If we got here, it's safe to delete the backup
                    System.IO.File.Delete(theBackup);
                }
                catch (Exception) { }
            }
            catch (Exception ex)
            {
                if (bHaveStartedProjecting)
                {
                    MessageBox.Show("ProjectWorkspaceContents experienced an error and has left the transaction in a halfway state." + Environment.NewLine
                        + "A backup file was created prior to the operation. Please delete the original file and replace it with the backup." + Environment.NewLine
                        + "The original file: " + pgdb.FullName + Environment.NewLine
                        + "The backup file: " + theBackup, "Projection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new ProjectFailedToFinishException("ProjectWorkspaceContents left Personal Geodatabase in a halfway state. Backup PGDB is '" + theBackup + "'.", ex);
                }
                else
                {
                    MessageBox.Show("ProjectWorkspaceContents experienced an error and has left the transaction untouched.");
                    throw new ProjectFailedToStartException("ProjectWorkspaceContents did not begin processing", ex);
                }
            }
            finally
            {
                if (theStepProgressor != null)
                    ((IProgressDialog2)theStepProgressor).HideDialog();
                theStepProgressor = null;
            }

            return theReturn;
        }
Example #6
0
        public void Run()
        {
            if (this.infileName == string.Empty || this.outfileName == string.Empty) return;
            if (this.outcoorSys == string.Empty) return;

            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;

            ESRI.ArcGIS.DataManagementTools.Project project = new ESRI.ArcGIS.DataManagementTools.Project();

            IGeoProcessorResult result;

            project.in_dataset = infileName;

            project.out_dataset = outfileName;

            project.out_coor_system = this.outcoorSys;

            result = (IGeoProcessorResult)gp.Execute(project, null);

            if (result != null)
            {
                this.resultStr = "投影完成";
            }
            else
            {
                this.resultStr = "投影失败";
            }
        }