Ejemplo n.º 1
0
        /// <param name="pFeatureClass">融合要素</param>
        /// <param name="dissField">融合字段</param>
        /// <param name="outPath">输出数据库路径</param>
        /// <param name="name">输出要素名称</param>
        private IFeatureClass Dissolve(IFeatureClass pFeatureClass, string dissField, string outPath, string name)
        {
            IFeatureClass pOutFeatureClass = null;

            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor    gp        = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.DataManagementTools.Dissolve pDissolve = new ESRI.ArcGIS.DataManagementTools.Dissolve();
                gp.OverwriteOutput          = true;
                pDissolve.in_features       = pFeatureClass;
                pDissolve.dissolve_field    = dissField;
                pDissolve.out_feature_class = outPath + "\\" + name;
                pDissolve.multi_part        = "true"; //跨区域融合;

                ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2 result = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)gp.Execute(pDissolve, null);

                if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                {
                    MessageBox.Show("操作失败!");
                    return(null);
                }
                else
                {
                    pOutFeatureClass = gp.Open(result.ReturnValue) as IFeatureClass;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("操作失败!");
                return(null);
            }
            return(pOutFeatureClass);
        }
        /// <summary>
        /// 
        /// </summary>
        public DrawingProcessorHelper()
        {
            this.licenseInit = new Enbridge.ArcObjects.LicenseInit();

            this.gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            string outputCoordinateSystem = "PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',";
            outputCoordinateSystem += "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],";
            outputCoordinateSystem += "PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],";
            outputCoordinateSystem += "PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],";
            outputCoordinateSystem += "PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]";
            this.gp.OverwriteOutput = true;
            this.gp.SetEnvironmentValue("outputCoordinateSystem", outputCoordinateSystem);

            this.sourcePoints = new ESRI.ArcGIS.Geometry.PathClass();
            this.sourcePoints.AddPoint(new ESRI.ArcGIS.Geometry.Point());
            this.sourcePoints.AddPoint(new ESRI.ArcGIS.Geometry.Point());
            this.targetPoints = new ESRI.ArcGIS.Geometry.PathClass();
            this.targetPoints.AddPoint(new ESRI.ArcGIS.Geometry.Point());
            this.targetPoints.AddPoint(new ESRI.ArcGIS.Geometry.Point());

            this.defineProj = new ESRI.ArcGIS.DataManagementTools.DefineProjection();
            this.defineProj.coor_system = outputCoordinateSystem;

            this.workspaceFact = new ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass();

            rasterPropc = new ESRI.ArcGIS.DataSourcesRaster.RasterGeometryProc();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs the Calculate Statistics tool from ArcMap.
        /// </summary>
        /// <param name="pRDS"></param>
        private void CalcStats(IRasterDataset pRDS)
        {
            IGeoProcessorResult result = null;

            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.OverwriteOutput = true;
            gp.AddOutputsToMap = false;

            ESRI.ArcGIS.DataManagementTools.CalculateStatistics statTool = new ESRI.ArcGIS.DataManagementTools.CalculateStatistics();
            statTool.in_raster_dataset = pRDS;

            result = (IGeoProcessorResult)gp.Execute(statTool, null);
        }
Ejemplo n.º 4
0
        /// <param name="pFeatureClass1">相交要素1</param>
        /// <param name="pFeatureClass2">相交要素2</param>
        /// <param name="gdbPath">数据库路径</param>
        private IFeatureClass Intersect(IFeatureClass pFeatureClass1, IFeatureClass pFeatureClass2, string gdbPath)
        {
            IFeatureClass pOutFeatureClass = null;

            try
            {
                //调用GP

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

                //多个对象的输入:使用IGpValueTableObject接口,该接口可以设置
                IGpValueTableObject vtobject = new GpValueTableObjectClass();
                object pFeature1             = pFeatureClass1;
                object pFeature2             = pFeatureClass2;
                vtobject.SetColumns(2);
                vtobject.AddRow(ref pFeature1);
                vtobject.AddRow(ref pFeature2);

                ESRI.ArcGIS.AnalysisTools.Intersect pIntersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
                pIntersect.in_features       = vtobject;
                pIntersect.out_feature_class = System.Environment.CurrentDirectory + @"\temp\" + "temp.shp";
                pIntersect.output_type       = "Input";

                IGeoProcessorResult2 result = (IGeoProcessorResult2)gp.Execute(pIntersect, null);

                if (result.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
                {
                    MessageBox.Show("操作失败!");
                    return(null);
                }
                else
                {
                    //获取结果;
                    IFeatureClass resultFClass = gp.Open(result.ReturnValue) as IFeatureClass;
                    IDataset      pDataset     = resultFClass as IDataset;
                    //目标数据库;
                    IWorkspaceFactory factory         = new FileGDBWorkspaceFactoryClass();
                    IWorkspace        objectWorkspace = factory.OpenFromFile(gdbPath, 0);

                    string fileName = pFeatureClass1.AliasName + "_" + pFeatureClass2.AliasName;
                    pOutFeatureClass = IFeatureDataConverter_ConvertFeatureClass(pDataset.Workspace, objectWorkspace, pDataset.Name, fileName);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("操作失败!");
                return(null);
            }
            return(pOutFeatureClass);
        }
Ejemplo n.º 5
0
 private string InterSect(string flayer, string kadastroLayer)
 {
     ESRI.ArcGIS.Geoprocessor.Geoprocessor gp        = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
     ESRI.ArcGIS.AnalysisTools.Intersect   intersect = new ESRI.ArcGIS.AnalysisTools.Intersect();
     intersect.in_features       = flayer + ";" + kadastroLayer;
     intersect.out_feature_class = AppSingleton.Instance().WorkspacePath + "\\Final";
     intersect.join_attributes   = "All";
     intersect.output_type       = "INPUT";
     gp.AddOutputsToMap          = true;
     gp.AddOutputsToMap          = true;
     gp.OverwriteOutput          = true;
     gp.Execute(intersect, null);
     return(intersect.out_feature_class.ToString());
 }
Ejemplo n.º 6
0
 private string RasterToPolygon(object rasterlayer)
 {
     ESRI.ArcGIS.Geoprocessor.Geoprocessor       gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
     ESRI.ArcGIS.ConversionTools.RasterToPolygon rasterToPolygon = new ESRI.ArcGIS.ConversionTools.RasterToPolygon();
     rasterToPolygon.in_raster            = rasterlayer;
     rasterToPolygon.out_polygon_features = AppSingleton.Instance().WorkspacePath + "\\RasterToPolygon";
     rasterToPolygon.simplify             = "SIMPLIFY";
     rasterToPolygon.raster_field         = "Value";
     gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
     gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
     gp.OverwriteOutput = true;
     gp.Execute(rasterToPolygon, null);
     return(rasterToPolygon.out_polygon_features.ToString());
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 获取GP日志
 /// </summary>
 /// <param name="pGeoprocessor"></param>
 /// <param name="strReport"></param>
 /// <returns></returns>
 public static bool ReturnErrMessage(ESRI.ArcGIS.Geoprocessor.Geoprocessor pGeoprocessor, ref string strReport)
 {
     ESRI.ArcGIS.Geodatabase.GPMessage       pGPMessage  = new ESRI.ArcGIS.Geodatabase.GPMessage();
     ESRI.ArcGIS.Geodatabase.GPMessagesClass pGPMessages = new ESRI.ArcGIS.Geodatabase.GPMessagesClass();
     try
     {
         int iNum = 0;
         for (int i = 0; i < pGeoprocessor.MessageCount; i++)
         {
             int ii = pGeoprocessor.GetReturnCode(i);
             if (ii != 0)
             {
                 iNum = iNum + 1;
             }
             if (strReport == "")
             {
                 strReport = pGeoprocessor.GetMessage(i);
                 if (pGPMessages != null)
                 {
                     pGPMessage.Description = string.Format(strReport);
                     pGPMessages.Add(pGPMessage);
                 }
             }
             else
             {
                 strReport = strReport + "\r\n" + pGeoprocessor.GetMessage(i);
                 if (pGPMessages != null)
                 {
                     pGPMessage.Description = string.Format(strReport);
                     pGPMessages.Add(pGPMessage);
                 }
             }
         }
         if (iNum > 0)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 8
0
 private string Combine(string layerNames, string outLayerName)
 {
     try
     {
         ESRI.ArcGIS.Geoprocessor.Geoprocessor   gp      = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         ESRI.ArcGIS.SpatialAnalystTools.Combine combine = new ESRI.ArcGIS.SpatialAnalystTools.Combine();
         combine.in_rasters = layerNames;
         combine.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + outLayerName;
         gp.AddOutputsToMap = true;
         gp.OverwriteOutput = true;
         gp.Execute(combine, null);
         return(combine.out_raster.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 9
0
 private string CopyFeatureClass(object featureClass)
 {
     try
     {
         ESRI.ArcGIS.Geoprocessor.Geoprocessor        gp           = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         ESRI.ArcGIS.DataManagementTools.CopyFeatures copyFeatures = new ESRI.ArcGIS.DataManagementTools.CopyFeatures();
         copyFeatures.in_features       = featureClass;
         copyFeatures.out_feature_class = AppSingleton.Instance().WorkspacePath + "\\" + "Copy";
         gp.AddOutputsToMap             = true;
         gp.OverwriteOutput             = true;
         gp.Execute(copyFeatures, null);
         return(copyFeatures.out_feature_class.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 10
0
 public string RasterCalculatorYillik(string P, string T, string layerName)
 {
     try
     {
         ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rasterCalculator = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
         rasterCalculator.expression = "'" + P + "'/('" + T + "' + 10)";
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         rasterCalculator.output_raster = AppSingleton.Instance().WorkspacePath + "\\" + layerName;
         gp.AddOutputsToMap             = true;//AppSingleton.Instance().AralariEkle;
         gp.OverwriteOutput             = true;
         gp.Execute(rasterCalculator, null);
         return(rasterCalculator.output_raster.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 11
0
 public string Int(string layerName, string outName)
 {
     try
     {
         ESRI.ArcGIS.SpatialAnalystTools.Int intRaster = new ESRI.ArcGIS.SpatialAnalystTools.Int();
         intRaster.in_raster_or_constant = layerName;
         intRaster.out_raster            = AppSingleton.Instance().WorkspacePath + "\\" + outName;
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         gp.AddOutputsToMap = true;
         gp.OverwriteOutput = true;
         gp.Execute(intRaster, null);
         return(intRaster.out_raster.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 12
0
 private bool Combine(string layerNames)
 {
     try
     {
         ESRI.ArcGIS.Geoprocessor.Geoprocessor   gp      = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         ESRI.ArcGIS.SpatialAnalystTools.Combine combine = new ESRI.ArcGIS.SpatialAnalystTools.Combine();
         combine.in_rasters = layerNames;
         combine.out_raster = AppSingleton.Instance().WorkspacePath + "\\" + "Ekolojik_Sit_Alani";
         gp.AddOutputsToMap = true;
         gp.OverwriteOutput = true;
         gp.Execute(combine, null);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 13
0
 public string RasterCalculatorKKS(string nKS)
 {
     try
     {
         ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rasterCalculator = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
         rasterCalculator.expression = "1 / '" + nKS + "'";
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         rasterCalculator.output_raster = AppSingleton.Instance().WorkspacePath + "\\kks";
         gp.AddOutputsToMap             = AppSingleton.Instance().AralariEkle;
         gp.OverwriteOutput             = true;
         gp.Execute(rasterCalculator, null);
         return(rasterCalculator.output_raster.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 14
0
 public string RasterCalculatorKi(string d, string etp, string layerName)
 {
     try
     {
         ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rasterCalculator = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
         rasterCalculator.expression = "((100 * '" + d + "') / '" + etp + "')*10";
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         rasterCalculator.output_raster = AppSingleton.Instance().WorkspacePath + "\\" + layerName;
         gp.AddOutputsToMap             = AppSingleton.Instance().AralariEkle;
         gp.OverwriteOutput             = true;
         gp.Execute(rasterCalculator, null);
         return(rasterCalculator.output_raster.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
        public static void ExportLayerToUploadableRaster(string outputFilePath, string name, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a raster layer
                ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = (IRasterLayer)source;

                // create a new raster to raster converter utility
                ESRI.ArcGIS.DataManagementTools.CopyRaster raster2raster
                    = new ESRI.ArcGIS.DataManagementTools.CopyRaster();

                // set the input raster layer
                raster2raster.in_raster = rasterLayer;

                // set the output path and Shapefile name

                /* The name and location of the raster dataset to be created.
                 * .bil—Esri BIL
                 * .bip—Esri BIP
                 * .bmp—BMP
                 * .bsq—Esri BSQ
                 * .dat—ENVI DAT
                 * .gif—GIF
                 * .img—ERDAS IMAGINE
                 * .jpg—JPEG
                 * .jp2—JPEG 2000
                 * .png—PNG
                 * .tif—TIFF
                 * no extension for Esri Grid
                 */
                raster2raster.out_rasterdataset = outputFilePath + "\\" + name + ".tif";

                // create a new GeoProcessor
                ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // execute the RasterToOtherFormat
                geoprocessor.Execute(raster2raster, null);
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
        /// <summary>
        /// Run the Geoprocessing model
        /// </summary>
        /// <param name="modelParametersHybridDictionary">A HybridDictionary that contains all of the arguments to run the model</param>
        /// <returns>A message of how well the model executed</returns>
        /// <remarks></remarks>
        public static System.String ExecuteCustomGeoprocessingFunction(System.Collections.Specialized.HybridDictionary modelParametersHybridDictionary)
        {
            try
            {
                // Create a Geoprocessor object
                ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // Set the OverwriteOutput setting to True
                gp.OverwriteOutput = true;

                // Create a new instance of our custom model
                MYCUSTOMTOOLBOX.GolfFinder myModel = new MYCUSTOMTOOLBOX.GolfFinder();

                // Set the custom models parameters.
                myModel.BufferDistance             = modelParametersHybridDictionary["BufferDistance"];
                myModel.AIRPORT                    = modelParametersHybridDictionary["Airports"];
                myModel.GOLF                       = modelParametersHybridDictionary["Golf"];
                myModel.AirportBuffer              = modelParametersHybridDictionary["AirportBuffer"];
                myModel.Golf_Courses_Near_Airports = modelParametersHybridDictionary["GolfNearAirports"];

                // Execute the model and obtain the result from the run
                ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult geoProcessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(myModel, null);

                if (geoProcessorResult == null)
                {
                    // We have an error running the model.
                    // If the run fails a Nothing (VB.NET) or null (C#) is returned from the gp.Execute
                    object sev      = 2;
                    string messages = gp.GetMessages(ref sev);
                    return(messages);
                }
                else
                {
                    // The model completed successfully
                    return("Output successful. The shapefiles are locacted at: " + geoProcessorResult.ReturnValue.ToString());
                }
            }
            catch (Exception ex)
            {
                // Catch any other errors
                return("Error running the model. Debug the application and test again.");
            }
        }
Ejemplo n.º 17
0
        public IRasterCatalog CreateRasterCat(string name, string sdePath)
        {
            ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            CreateRasterCatalog createRasterCatalog            = new CreateRasterCatalog();
            IGPCoordinateSystem rSR = new GPCoordinateSystemClass();
            IGPSpatialReference gSR = new GPSpatialReferenceClass();

            rSR.SpatialReference = new UnknownCoordinateSystemClass();
            gSR.SpatialReference = new UnknownCoordinateSystemClass();

            createRasterCatalog.out_path = sdePath;
            createRasterCatalog.out_name = name;
            createRasterCatalog.raster_spatial_reference = (object)rSR;
            createRasterCatalog.spatial_reference        = (object)gSR;
            geoProcessor.Execute(createRasterCatalog, null);
            IRasterCatalog rastercat = ((IRasterWorkspaceEx)this.m_workSpace).OpenRasterCatalog(name);

            return(rastercat);
        }
Ejemplo n.º 18
0
 private string Divide(string yagisLayer, string sicaklikLayer)
 {
     try
     {
         ESRI.ArcGIS.SpatialAnalystTools.Divide divide = new ESRI.ArcGIS.SpatialAnalystTools.Divide();
         divide.in_raster_or_constant1 = yagisLayer;
         divide.in_raster_or_constant2 = sicaklikLayer;
         divide.out_raster             = AppSingleton.Instance().WorkspacePath + "\\" + "sonucLayer";
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         gp.AddOutputsToMap = true;
         gp.OverwriteOutput = true;
         gp.Execute(divide, null);
         return(divide.out_raster.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 19
0
 private bool JoinField(object table, string inField, string joinTable, string joinField)
 {
     try
     {
         ESRI.ArcGIS.Geoprocessor.Geoprocessor     gp   = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         ESRI.ArcGIS.DataManagementTools.JoinField join = new ESRI.ArcGIS.DataManagementTools.JoinField();
         join.in_data       = table;
         join.in_field      = inField;
         join.join_table    = joinTable;
         join.join_field    = joinField;
         gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
         gp.OverwriteOutput = true;
         gp.Execute(join, null);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 20
0
        private bool CalculateField(ILayer selectedLayer)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor          gp             = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.DataManagementTools.CalculateField calculateField = new ESRI.ArcGIS.DataManagementTools.CalculateField();
                calculateField.in_table        = AppSingleton.Instance().WorkspacePath + "\\RingBuffered_" + selectedLayer.Name;
                calculateField.field           = "priority";
                calculateField.expression      = "1/Sqr ( [distance] )";
                calculateField.expression_type = "VB";

                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(calculateField, null);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 21
0
 private bool ClipLayers(ILayer selectedLayer)
 {
     try
     {
         IFeatureWorkspace fWorkspace               = AppSingleton.Instance().PersonalWorkspace as IFeatureWorkspace;
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp   = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         ESRI.ArcGIS.AnalysisTools.Clip        clip = new ESRI.ArcGIS.AnalysisTools.Clip();
         clip.in_features       = selectedLayer;
         clip.clip_features     = AppSingleton.Instance().SinirLayer;
         clip.out_feature_class = AppSingleton.Instance().WorkspacePath + "\\Clip_" + selectedLayer.Name;
         gp.AddOutputsToMap     = AppSingleton.Instance().AralariEkle;
         gp.OverwriteOutput     = true;
         gp.Execute(clip, null);
         //return clip.out_feature_class.ToString();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Ejemplo n.º 22
0
        private bool CreateTin(ILayer selectedLayer, EnterpoleGrid grid)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor gp        = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.Analyst3DTools.CreateTin  createTin = new ESRI.ArcGIS.Analyst3DTools.CreateTin();
                createTin.out_tin = AppSingleton.Instance().Path + "\\TIN_" + selectedLayer.Name;                                                                    //RingBuffered_
                //erdinç
                createTin.in_features          = AppSingleton.Instance().WorkspacePath + "\\Clip_" + selectedLayer.Name + " " + grid.FieldName + " hardline <None>"; // 10.1 Hard_Line ; 10.0 hardline
                createTin.constrained_delaunay = "DELAUNAY";

                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(createTin, null);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 23
0
        private bool Reclassify(string selectedLayer)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor      gp      = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.SpatialAnalystTools.Reclassify reclass = new ESRI.ArcGIS.SpatialAnalystTools.Reclassify();
                reclass.in_raster     = selectedLayer;//RingBuffered_
                reclass.reclass_field = "Value";
                reclass.out_raster    = AppSingleton.Instance().WorkspacePath + "\\Reclassifiedlayer";
                reclass.remap         = "0 8 1;8 15 2;15 23 3;23 40 4;40 55 5;55 10000 6;NODATA 0";
                gp.AddOutputsToMap    = true;
                gp.OverwriteOutput    = true;
                gp.Execute(reclass, null);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 24
0
 private string IDW(ILayer selectedLayer, string FieldName)
 {
     try
     {
         ESRI.ArcGIS.SpatialAnalystTools.Idw idw = new ESRI.ArcGIS.SpatialAnalystTools.Idw();
         idw.cell_size         = AppSingleton.Instance().CellSize;
         idw.out_raster        = AppSingleton.Instance().WorkspacePath + "\\" + selectedLayer.Name + "_IDW_" + FieldName;
         idw.in_point_features = selectedLayer;
         idw.z_field           = FieldName;
         idw.power             = 3;
         idw.search_radius     = AppSingleton.Instance().IDWYaricap;
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
         gp.OverwriteOutput = true;
         gp.Execute(idw, null);
         return(idw.out_raster.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 25
0
 public string ClipLayers(ILayer sinirLayer, ILayer selectedLayer)
 {
     try
     {
         IFeatureWorkspace fWorkspace               = PersonalWorkspace as IFeatureWorkspace;
         ESRI.ArcGIS.Geoprocessor.Geoprocessor gp   = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
         ESRI.ArcGIS.AnalysisTools.Clip        clip = new ESRI.ArcGIS.AnalysisTools.Clip();
         clip.in_features   = selectedLayer;
         clip.clip_features = sinirLayer;
         var layerName = System.IO.Path.GetFileNameWithoutExtension(selectedLayer.Name);
         clip.out_feature_class = WorkspacePath + "\\Clip_" + layerName;
         gp.AddOutputsToMap     = AppSingleton.Instance().AralariEkle;
         gp.OverwriteOutput     = true;
         gp.Execute(clip, null);
         //return clip.out_feature_class.ToString();
         return(clip.out_feature_class.ToString());
     }
     catch (Exception ex)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 26
0
        //调用gp工具创建泰森多边形
        public static void CreateThiessenPolygons(IFeatureLayer in_features, string out_feature_class, string workspacename, string extent)
        {
            //IAoInitialize m_AoInitialize = new AoInitializeClass();
            //esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
            //licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.OverwriteOutput = true;
            gp.SetEnvironmentValue("workspace", workspacename);
            //gp.SetEnvironmentValue("extent", extent);
            ESRI.ArcGIS.AnalysisTools.CreateThiessenPolygons createthiessenpolygon = new CreateThiessenPolygons();
            createthiessenpolygon.in_features       = in_features;
            createthiessenpolygon.out_feature_class = out_feature_class;
            createthiessenpolygon.fields_to_copy    = "ALL";
            gp.Execute(createthiessenpolygon, null);
            string strMessage = "";

            for (int i = 0; i < gp.MessageCount; i++)
            {
                strMessage += gp.GetMessage(i).ToString() + "\r\n";
            }
            //MessageBox.Show(strMessage);
        }
        public static void ExportLayerToShapefile(string shapePath, string shapeName, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a feature layer
                ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (IFeatureLayer)source;

                // create a new feature class to feature class converter utility
                ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fc2fc
                    = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();

                // set the input feature layer
                fc2fc.in_features = featureLayer;

                // set the output path and Shapefile name
                fc2fc.out_path = shapePath;
                fc2fc.out_name = shapeName + ".shp";

                // create a new GeoProcessor
                ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(fc2fc, null);

                // export a copy of the layer file definition too for upload/style at a later time
                ESRI.ArcGIS.DataManagementTools.SaveToLayerFile saveToLayerFile
                    = new ESRI.ArcGIS.DataManagementTools.SaveToLayerFile();
                saveToLayerFile.in_layer  = source;
                saveToLayerFile.out_layer = shapePath + "\\" + shapeName + ".lyr";

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(saveToLayerFile, null);
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
Ejemplo n.º 28
0
        public string Reclassify(string layerName, string FieldName, string reclassMap, string outputType)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor gp      = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.Analyst3DTools.Reclassify reclass = new ESRI.ArcGIS.Analyst3DTools.Reclassify();
                reclass.in_raster     = AppSingleton.Instance().WorkspacePath + "\\" + layerName;              //RingBuffered_
                reclass.reclass_field = FieldName;                                                             //"Value";
                reclass.out_raster    = AppSingleton.Instance().WorkspacePath + "\\" + outputType + layerName; //Reclassified_
                reclass.remap         = reclassMap;                                                            // "50 1;50 100 2;100 150 3;NODATA 0";


                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(reclass, null);
                return(reclass.out_raster.ToString());
            }
            catch (Exception ex)
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 29
0
        private bool AddField(ILayer selectedLayer, string fieldName, string type)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor    gp       = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField();
                addField.in_table          = AppSingleton.Instance().WorkspacePath + "\\" + type + selectedLayer.Name;
                addField.field_name        = fieldName;
                addField.field_type        = "DOUBLE";
                addField.field_is_nullable = "NULLABLE";
                addField.field_is_required = "NON_REQUIRED";

                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(addField, null);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 30
0
        private bool RingBuffer(ILayer selectedLayer, string distances)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor        gp         = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer ringBuffer = new ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer();
                ringBuffer.Input_Features       = AppSingleton.Instance().WorkspacePath + "\\Clip_" + selectedLayer.Name;
                ringBuffer.Output_Feature_class = AppSingleton.Instance().WorkspacePath + "\\RingBuffered_" + selectedLayer.Name;
                ringBuffer.Distances            = distances;//"50;100;150";
                ringBuffer.Buffer_Unit          = "Meters";
                ringBuffer.Dissolve_Option      = "NONE";

                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(ringBuffer, null);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 31
0
        public bool AddField(object table, string fieldName, string type)
        {
            try
            {
                ESRI.ArcGIS.Geoprocessor.Geoprocessor    gp       = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField();
                addField.in_table          = table;
                addField.field_name        = fieldName;
                addField.field_type        = type;
                addField.field_is_nullable = "NULLABLE";
                addField.field_is_required = "NON_REQUIRED";

                gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle;
                gp.OverwriteOutput = true;
                gp.Execute(addField, null);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 32
0
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            _message = message;

            IFeatureClass osmPointFeatureClass = null;
            IFeatureClass osmLineFeatureClass = null;
            IFeatureClass osmPolygonFeatureClass = null;

            try
            {
                DateTime syncTime = DateTime.Now;

                IGPUtilities3 gpUtilities3 = new GPUtilitiesClass();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                IGPParameter baseURLParameter = paramvalues.get_Element(in_downloadURLNumber) as IGPParameter;
                IGPString baseURLString = gpUtilities3.UnpackGPValue(baseURLParameter) as IGPString;

                if (baseURLString == null)
                {
                    message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), baseURLParameter.Name));
                }

                IGPParameter downloadExtentParameter = paramvalues.get_Element(in_downloadExtentNumber) as IGPParameter;
                IGPValue downloadExtentGPValue = gpUtilities3.UnpackGPValue(downloadExtentParameter);

                esriGPExtentEnum gpExtent;
                IEnvelope downloadEnvelope = gpUtilities3.GetExtent(downloadExtentGPValue, out gpExtent);

                IGPParameter includeAllReferences = paramvalues.get_Element(in_includeReferencesNumber) as IGPParameter;
                IGPBoolean includeAllReferencesGPValue = gpUtilities3.UnpackGPValue(includeAllReferences) as IGPBoolean;

                if (includeAllReferencesGPValue == null)
                {
                    message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), includeAllReferences.Name));
                }

                IEnvelope newExtent = null;

                ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass() as ISpatialReferenceFactory;
                ISpatialReference wgs84 = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984) as ISpatialReference;

                // this determines the spatial reference as defined from the gp environment settings and the initial wgs84 SR
                ISpatialReference downloadSpatialReference = gpUtilities3.GetGPSpRefEnv(envMgr, wgs84, newExtent, 0, 0, 0, 0, null);

                downloadEnvelope.Project(wgs84);

                Marshal.ReleaseComObject(wgs84);
                Marshal.ReleaseComObject(spatialReferenceFactory);

                HttpWebRequest httpClient;
                System.Xml.Serialization.XmlSerializer serializer = null;
                serializer = new XmlSerializer(typeof(osm));

                // get the capabilities from the server
                HttpWebResponse httpResponse = null;

                api apiCapabilities = null;
                CultureInfo enUSCultureInfo = new CultureInfo("en-US");

#if DEBUG
                Console.WriteLine("Debbuging");
                message.AddMessage("Debugging...");
#endif

                message.AddMessage(resourceManager.GetString("GPTools_OSMGPDownload_startingDownloadRequest"));

                try
                {
                    httpClient = HttpWebRequest.Create(baseURLString.Value + "/api/capabilities") as HttpWebRequest;
                    httpClient = AssignProxyandCredentials(httpClient);

                    httpResponse = httpClient.GetResponse() as HttpWebResponse;

                    osm osmCapabilities = null;

                    Stream stream = httpResponse.GetResponseStream();

                    XmlTextReader xmlReader = new XmlTextReader(stream);
                    osmCapabilities = serializer.Deserialize(xmlReader) as osm;
                    xmlReader.Close();

                    apiCapabilities = osmCapabilities.Items[0] as api;

                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    message.AddError(120009, ex.Message);

                    if (ex is WebException)
                    {
                        WebException webException = ex as WebException;
                        string serverErrorMessage = webException.Response.Headers["Error"];
                        if (!String.IsNullOrEmpty(serverErrorMessage))
                        {
                            message.AddError(120009, serverErrorMessage);
                        }
                    }

                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Close();
                    }
                    httpClient = null;
                }

                if (apiCapabilities != null)
                {
                    // check for the extent
                    double roiArea = ((IArea)downloadEnvelope).Area;
                    double capabilitiyArea = Convert.ToDouble(apiCapabilities.area.maximum, new CultureInfo("en-US"));

                    if (roiArea > capabilitiyArea)
                    {
                        message.AddAbort(resourceManager.GetString("GPTools_OSMGPDownload_exceedDownloadROI"));
                        return;
                    }
                }

                // check for user interruption
                if (TrackCancel.Continue() == false)
                {
                    return;
                }

                // list containing either only one document for a single bbox request or multiple if relation references need to be resolved
                List<string> downloadedOSMDocuments = new List<string>();

                string requestURL = baseURLString.Value + "/api/0.6/map?bbox=" + downloadEnvelope.XMin.ToString("f5", enUSCultureInfo) + "," + downloadEnvelope.YMin.ToString("f5", enUSCultureInfo) + "," + downloadEnvelope.XMax.ToString("f5", enUSCultureInfo) + "," + downloadEnvelope.YMax.ToString("f5", enUSCultureInfo);
                string osmMasterDocument = downloadOSMDocument(ref message, requestURL, apiCapabilities);

                // check if the initial request was successfull
                // it might have failed at this point because too many nodes were requested or because of something else
                if (String.IsNullOrEmpty(osmMasterDocument))
                {
                    message.AddAbort(resourceManager.GetString("GPTools_OSMGPDownload_noValidOSMResponse"));
                    return;
                }

                // add the "master document" ) original bbox request to the list
                downloadedOSMDocuments.Add(osmMasterDocument);

                if (includeAllReferencesGPValue.Value)
                {
                    List<string> nodeList = new List<string>();
                    List<string> wayList = new List<string>();
                    List<string> relationList = new List<string>();
                    // check for user interruption
                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }

                    parseOSMDocument(osmMasterDocument, ref message, ref nodeList, ref wayList, ref relationList, ref downloadedOSMDocuments, baseURLString.Value, apiCapabilities);
                }

                string metadataAbstract = resourceManager.GetString("GPTools_OSMGPDownload_metadata_abstract");
                string metadataPurpose = resourceManager.GetString("GPTools_OSMGPDownload_metadata_purpose");

                IGPParameter targetDatasetParameter = paramvalues.get_Element(out_targetDatasetNumber) as IGPParameter;
                IDEDataset2 targetDEDataset2 = gpUtilities3.UnpackGPValue(targetDatasetParameter) as IDEDataset2;
                IGPValue targetDatasetGPValue = gpUtilities3.UnpackGPValue(targetDatasetParameter);
                string targetDatasetName = ((IGPValue)targetDEDataset2).GetAsText();

                IDataElement targetDataElement = targetDEDataset2 as IDataElement;
                IDataset targetDataset = gpUtilities3.OpenDatasetFromLocation(targetDataElement.CatalogPath);

                IName parentName = null;

                try
                {
                    parentName = gpUtilities3.CreateParentFromCatalogPath(targetDataElement.CatalogPath);
                }
                catch
                {
                    message.AddError(120033, resourceManager.GetString("GPTools_OSMGPFileReader_unable_to_create_fd"));
                    return;
                }

                // test if the feature classes already exists, 
                // if they do and the environments settings are such that an overwrite is not allowed we need to abort at this point
                IGeoProcessorSettings gpSettings = (IGeoProcessorSettings)envMgr;
                if (gpSettings.OverwriteOutput == true)
                {
                }

                else
                {
                    if (gpUtilities3.Exists((IGPValue)targetDEDataset2) == true)
                    {
                        message.AddError(120010, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_basenamealreadyexists"), targetDataElement.Name));
                        return;
                    }
                }

                string Container = "";
                IDEUtilities deUtilities = new DEUtilitiesClass();
                deUtilities.ParseContainer(targetDataElement.CatalogPath, ref Container);

                IFeatureWorkspace featureWorkspace = gpUtilities3.OpenFromString(Container) as IFeatureWorkspace;

                if (featureWorkspace == null)
                {
                    message.AddError(120011, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nofeatureworkspace"), Container));
                    return;
                }

                // load the descriptions from which to derive the domain values
                OSMDomains availableDomains = null;

                System.Xml.XmlTextReader reader = null;
                try
                {
                    if (File.Exists(m_editorConfigurationSettings["osmdomainsfilepath"]))
                    {
                        reader = new System.Xml.XmlTextReader(m_editorConfigurationSettings["osmdomainsfilepath"]);
                    }
                }
                // If is in the server and hasn't been install all the configuration files
                catch
                {
                    if (File.Exists(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(OSMGPDownload)).Location), "osm_domains.xml")))
                    {
                        reader = new System.Xml.XmlTextReader(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(OSMGPDownload)).Location), "osm_domains.xml"));
                    }
                }

                if (reader == null)
                {
                    message.AddError(120012, resourceManager.GetString("GPTools_OSMGPDownload_NoDomainConfigFile"));
                    return;
                }

                try
                {
                    serializer = new XmlSerializer(typeof(OSMDomains));
                    availableDomains = serializer.Deserialize(reader) as OSMDomains;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    message.AddError(120013, ex.Message);
                    return;
                }

                #region define and add domains to the workspace
                // we are using domains to guide the edit templates in the editor for ArcGIS desktop
                Dictionary<string, IDomain> codedValueDomains = new Dictionary<string, IDomain>();

                foreach (var domain in availableDomains.domain)
                {
                    ICodedValueDomain pointCodedValueDomain = new CodedValueDomainClass();
                    ((IDomain)pointCodedValueDomain).Name = domain.name + "_pt";
                    ((IDomain)pointCodedValueDomain).FieldType = esriFieldType.esriFieldTypeString;

                    ICodedValueDomain lineCodedValueDomain = new CodedValueDomainClass();
                    ((IDomain)lineCodedValueDomain).Name = domain.name + "_ln";
                    ((IDomain)lineCodedValueDomain).FieldType = esriFieldType.esriFieldTypeString;

                    ICodedValueDomain polygonCodedValueDomain = new CodedValueDomainClass();
                    ((IDomain)polygonCodedValueDomain).Name = domain.name + "_ply";
                    ((IDomain)polygonCodedValueDomain).FieldType = esriFieldType.esriFieldTypeString;

                    for (int i = 0; i < domain.domainvalue.Length; i++)
                    {
                        for (int domainGeometryIndex = 0; domainGeometryIndex < domain.domainvalue[i].geometrytype.Length; domainGeometryIndex++)
                        {
                            switch (domain.domainvalue[i].geometrytype[domainGeometryIndex])
                            {
                                case geometrytype.point:
                                    pointCodedValueDomain.AddCode(domain.domainvalue[i].value, domain.domainvalue[i].value);
                                    break;
                                case geometrytype.line:
                                    lineCodedValueDomain.AddCode(domain.domainvalue[i].value, domain.domainvalue[i].value);
                                    break;
                                case geometrytype.polygon:
                                    polygonCodedValueDomain.AddCode(domain.domainvalue[i].value, domain.domainvalue[i].value);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }

                    // add the domain tables to the domains collection
                    codedValueDomains.Add(((IDomain)pointCodedValueDomain).Name, (IDomain)pointCodedValueDomain);
                    codedValueDomains.Add(((IDomain)lineCodedValueDomain).Name, (IDomain)lineCodedValueDomain);
                    codedValueDomains.Add(((IDomain)polygonCodedValueDomain).Name, (IDomain)polygonCodedValueDomain);
                }

                IWorkspaceDomains workspaceDomain = featureWorkspace as IWorkspaceDomains;
                foreach (var domain in codedValueDomains.Values)
                {
                    IDomain testDomain = null;
                    try
                    {
                        testDomain = workspaceDomain.get_DomainByName(domain.Name);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    }

                    if (testDomain == null)
                    {
                        workspaceDomain.AddDomain(domain);
                    }
                }
                #endregion

                IGPEnvironment configKeyword = getEnvironment(envMgr, "configKeyword");
                IGPString gpString = null;
                if (configKeyword != null)
                    gpString = configKeyword.Value as IGPString;

                string storageKeyword = String.Empty;

                if (gpString != null)
                {
                    storageKeyword = gpString.Value;
                }

                IFeatureDataset targetFeatureDataset = null;
                if (gpUtilities3.Exists((IGPValue)targetDEDataset2))
                {
                    targetFeatureDataset = gpUtilities3.OpenDataset((IGPValue)targetDEDataset2) as IFeatureDataset;
                }
                else
                {
                    targetFeatureDataset = featureWorkspace.CreateFeatureDataset(targetDataElement.Name, downloadSpatialReference);
                }


                ESRI.ArcGIS.esriSystem.UID osmClassExtensionUID = new ESRI.ArcGIS.esriSystem.UIDClass();
                //GUID for the OSM feature class extension
                osmClassExtensionUID.Value = "{65CA4847-8661-45eb-8E1E-B2985CA17C78}";


                downloadSpatialReference = ((IGeoDataset)targetFeatureDataset).SpatialReference;
                OSMToolHelper osmToolHelper = new OSMToolHelper();

                #region create point/line/polygon feature classes and tables
                // points
                try
                {
                    osmPointFeatureClass = osmToolHelper.CreatePointFeatureClass((IWorkspace2)featureWorkspace, targetFeatureDataset, targetDataElement.Name + "_osm_pt", null, null, osmClassExtensionUID, storageKeyword, availableDomains, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120014, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullpointfeatureclass"), ex.Message));
                    return;
                }

                if (osmPointFeatureClass == null)
                {
                    return;
                }

                // change the property set of the osm class extension to skip any change detection during the initial data load
                osmPointFeatureClass.RemoveOSMClassExtension();

                // lines
                try
                {
                    osmLineFeatureClass = osmToolHelper.CreateLineFeatureClass((IWorkspace2)featureWorkspace, targetFeatureDataset, targetDataElement.Name + "_osm_ln", null, null, osmClassExtensionUID, storageKeyword, availableDomains, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120015, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nulllinefeatureclass"), ex.Message));
                    return;
                }

                if (osmLineFeatureClass == null)
                {
                    return;
                }

                // change the property set of the osm class extension to skip any change detection during the initial data load
                osmLineFeatureClass.RemoveOSMClassExtension();

                // polygons
                try
                {
                    osmPolygonFeatureClass = osmToolHelper.CreatePolygonFeatureClass((IWorkspace2)featureWorkspace, targetFeatureDataset, targetDataElement.Name + "_osm_ply", null, null, osmClassExtensionUID, storageKeyword, availableDomains, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120016, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullpolygonfeatureclass"), ex.Message));
                    return;
                }

                if (osmPolygonFeatureClass == null)
                {
                    return;
                }

                // change the property set of the osm class extension to skip any change detection during the initial data load
                osmPolygonFeatureClass.RemoveOSMClassExtension();

                // relation table
                ITable relationTable = null;

                try
                {
                    relationTable = osmToolHelper.CreateRelationTable((IWorkspace2)featureWorkspace, targetDataElement.Name + "_osm_relation", null, storageKeyword, metadataAbstract, metadataPurpose);
                }
                catch (Exception ex)
                {
                    message.AddError(120017, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullrelationtable"), ex.Message));
                    return;
                }

                if (relationTable == null)
                {
                    return;
                }

                // revision table 
                ITable revisionTable = null;

                try
                {
                    revisionTable = osmToolHelper.CreateRevisionTable((IWorkspace2)featureWorkspace, targetDataElement.Name + "_osm_revision", null, storageKeyword);
                }
                catch (Exception ex)
                {
                    message.AddError(120018, String.Format(resourceManager.GetString("GPTools_OSMGPDownload_nullrelationtable"), ex.Message));
                    return;
                }

                if (revisionTable == null)
                {
                    return;
                }

                // check for user interruption
                if (TrackCancel.Continue() == false)
                {
                    return;
                }
                #endregion

                #region clean any existing data from loading targets
                ESRI.ArcGIS.Geoprocessing.IGeoProcessor2 gp = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass();
                IGeoProcessorResult gpResult = new GeoProcessorResultClass();

                try
                {
                    IVariantArray truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_pt");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ln");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ply");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "_osm_relation");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);

                    truncateParameters = new VarArrayClass();
                    truncateParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "_osm_revision");
                    gpResult = gp.Execute("TruncateTable_management", truncateParameters, TrackCancel);
                }
                catch (Exception ex)
                {
                    message.AddWarning(ex.Message);
                }
                #endregion

                Dictionary<string, OSMToolHelper.simplePointRef> osmNodeDictionary = null;

                foreach (string osmDownloadDocument in downloadedOSMDocuments.Reverse<string>())
                {
                    long nodeCapacity = 0;
                    long wayCapacity = 0;
                    long relationCapacity = 0;

                    message.AddMessage(resourceManager.GetString("GPTools_OSMGPFileReader_countingNodes"));

                    osmToolHelper.countOSMStuff(osmDownloadDocument, ref nodeCapacity, ref wayCapacity, ref relationCapacity, ref TrackCancel);
                    message.AddMessage(String.Format(resourceManager.GetString("GPTools_OSMGPFileReader_countedElements"), nodeCapacity, wayCapacity, relationCapacity));

                    if (osmNodeDictionary == null)
                        osmNodeDictionary = new Dictionary<string, OSMToolHelper.simplePointRef>(Convert.ToInt32(nodeCapacity));

                    #region load points
                    osmToolHelper.loadOSMNodes(osmDownloadDocument, ref TrackCancel, ref message, targetDatasetGPValue, osmPointFeatureClass, false, false, Convert.ToInt32(nodeCapacity), ref osmNodeDictionary, featureWorkspace, downloadSpatialReference, availableDomains, false);
                    #endregion

                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }

                    #region load ways
                    if (wayCapacity > 0)
                    {
                        List<string> missingWays = null;
                        missingWays = osmToolHelper.loadOSMWays(osmDownloadDocument, ref TrackCancel, ref message, targetDatasetGPValue, osmPointFeatureClass, osmLineFeatureClass, osmPolygonFeatureClass, false, false, Convert.ToInt32(wayCapacity), ref osmNodeDictionary, featureWorkspace, downloadSpatialReference, availableDomains, false);
                    }
                    #endregion

                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }

                    # region for conserve memory condition, update refcount
                    int refCounterFieldIndex = osmPointFeatureClass.Fields.FindField("wayRefCount");
                    if (refCounterFieldIndex > -1)
                    {
                        foreach (var refNode in osmNodeDictionary)
                        {
                            try
                            {
                                IFeature updateFeature = osmPointFeatureClass.GetFeature(refNode.Value.pointObjectID);

                                int refCount = refNode.Value.RefCounter;
                                if (refCount == 0)
                                {
                                    refCount = 1;
                                }

                                updateFeature.set_Value(refCounterFieldIndex, refCount);
                                updateFeature.Store();
                            }
                            catch { }
                        }
                    }

                    #endregion

                    // check for user interruption
                    if (TrackCancel.Continue() == false)
                    {
                        return;
                    }
                    ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                    #region for local geodatabases enforce spatial integrity
                    bool storedOriginal = geoProcessor.AddOutputsToMap;
                    geoProcessor.AddOutputsToMap = false;

                    try
                    {
                        if (osmLineFeatureClass != null)
                        {
                            if (((IDataset)osmLineFeatureClass).Workspace.Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                            {
                                IVariantArray lineRepairParameters = new VarArrayClass();
                                lineRepairParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ln");
                                lineRepairParameters.Add("DELETE_NULL");

                                IGeoProcessorResult2 gpResults = gp.Execute("RepairGeometry_management", lineRepairParameters, TrackCancel) as IGeoProcessorResult2;
                                message.AddMessages(gpResults.GetResultMessages());
                            }
                        }

                        if (osmPolygonFeatureClass != null)
                        {
                            if (((IDataset)osmPolygonFeatureClass).Workspace.Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                            {
                                IVariantArray polygonRepairParameters = new VarArrayClass();
                                polygonRepairParameters.Add(((IWorkspace)featureWorkspace).PathName + "\\" + targetDataElement.Name + "\\" + targetDataElement.Name + "_osm_ply");
                                polygonRepairParameters.Add("DELETE_NULL");

                                IGeoProcessorResult2 gpResults = gp.Execute("RepairGeometry_management", polygonRepairParameters, TrackCancel) as IGeoProcessorResult2;
                                message.AddMessages(gpResults.GetResultMessages());
                            }
                        }
                    }
                    catch
                    {
                        message.AddWarning(resourceManager.GetString("GPTools_OSMGPDownload_repairgeometryfailure"));
                    }
                    geoProcessor.AddOutputsToMap = storedOriginal;
                    #endregion



                    #region load relations
                    if (relationCapacity > 0)
                    {
                        List<string> missingRelations = null;
                        missingRelations = osmToolHelper.loadOSMRelations(osmDownloadDocument, ref TrackCancel, ref message, targetDatasetGPValue, osmPointFeatureClass, osmLineFeatureClass, osmPolygonFeatureClass, Convert.ToInt32(relationCapacity), relationTable, availableDomains, false, false);
                    }
                    #endregion
                }

                #region update the references counts and member lists for nodes
                message.AddMessage(resourceManager.GetString("GPTools_OSMGPFileReader_updatereferences"));
                IFeatureCursor pointUpdateCursor = null;

                using (SchemaLockManager ptLockManager = new SchemaLockManager(osmPointFeatureClass as ITable))
                {
                    using (ComReleaser comReleaser = new ComReleaser())
                    {
                        int updateCount = 0;
                        pointUpdateCursor = osmPointFeatureClass.Update(null, false);
                        updateCount = ((ITable)osmPointFeatureClass).RowCount(null);

                        IStepProgressor stepProgressor = TrackCancel as IStepProgressor;

                        if (stepProgressor != null)
                        {
                            stepProgressor.MinRange = 0;
                            stepProgressor.MaxRange = updateCount;
                            stepProgressor.Position = 0;
                            stepProgressor.Message = resourceManager.GetString("GPTools_OSMGPFileReader_updatepointrefcount");
                            stepProgressor.StepValue = 1;
                            stepProgressor.Show();
                        }

                        comReleaser.ManageLifetime(pointUpdateCursor);

                        IFeature pointFeature = pointUpdateCursor.NextFeature();

                        int osmPointIDFieldIndex = osmPointFeatureClass.FindField("OSMID");
                        int osmWayRefCountFieldIndex = osmPointFeatureClass.FindField("wayRefCount");
                        int positionCounter = 0;
                        while (pointFeature != null)
                        {
                            positionCounter++;
                            string nodeID = Convert.ToString(pointFeature.get_Value(osmPointIDFieldIndex));

                            // let get the reference counter from the internal node dictionary
                            if (osmNodeDictionary[nodeID].RefCounter == 0)
                            {
                                pointFeature.set_Value(osmWayRefCountFieldIndex, 1);
                            }
                            else
                            {
                                pointFeature.set_Value(osmWayRefCountFieldIndex, osmNodeDictionary[nodeID].RefCounter);
                            }

                            pointUpdateCursor.UpdateFeature(pointFeature);

                            if (pointFeature != null)
                                Marshal.ReleaseComObject(pointFeature);

                            pointFeature = pointUpdateCursor.NextFeature();

                            if (stepProgressor != null)
                            {
                                stepProgressor.Position = positionCounter;
                            }
                        }

                        if (stepProgressor != null)
                        {
                            stepProgressor.Hide();
                        }
                    }
                }
                #endregion

                // clean all the downloaded OSM files
                foreach (string osmFile in downloadedOSMDocuments)
                {
                    if (File.Exists(osmFile))
                    {
                        try
                        {
                            File.Delete(osmFile);
                        }
                        catch { }
                    }
                }

                SyncState.StoreLastSyncTime(targetDatasetName, syncTime);

                gpUtilities3 = new GPUtilitiesClass() as IGPUtilities3;

                // repackage the feature class into their respective gp values
                IGPParameter pointFeatureClassParameter = paramvalues.get_Element(out_osmPointsNumber) as IGPParameter;
                IGPValue pointFeatureClassPackGPValue = gpUtilities3.UnpackGPValue(pointFeatureClassParameter);
                gpUtilities3.PackGPValue(pointFeatureClassPackGPValue, pointFeatureClassParameter);

                IGPParameter lineFeatureClassParameter = paramvalues.get_Element(out_osmLinesNumber) as IGPParameter;
                IGPValue lineFeatureClassPackGPValue = gpUtilities3.UnpackGPValue(lineFeatureClassParameter);
                gpUtilities3.PackGPValue(lineFeatureClassPackGPValue, lineFeatureClassParameter);

                IGPParameter polygonFeatureClassParameter = paramvalues.get_Element(out_osmPolygonsNumber) as IGPParameter;
                IGPValue polygon1FeatureClassPackGPValue = gpUtilities3.UnpackGPValue(polygonFeatureClassParameter);
                gpUtilities3.PackGPValue(polygon1FeatureClassPackGPValue, polygonFeatureClassParameter);

                gpUtilities3.ReleaseInternals();
                Marshal.ReleaseComObject(gpUtilities3);

                Marshal.ReleaseComObject(baseURLString);
                Marshal.ReleaseComObject(downloadExtentGPValue);
                Marshal.ReleaseComObject(downloadEnvelope);
                Marshal.ReleaseComObject(includeAllReferences);
                Marshal.ReleaseComObject(downloadSpatialReference);

                if (osmToolHelper != null)
                    osmToolHelper = null;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                message.AddError(120019, ex.Message);
            }
            finally
            {
                try
                {
                    if (osmPointFeatureClass != null)
                    {
                        osmPointFeatureClass.ApplyOSMClassExtension();
                        Marshal.ReleaseComObject(osmPointFeatureClass);
                    }

                    if (osmLineFeatureClass != null)
                    {
                        osmLineFeatureClass.ApplyOSMClassExtension();
                        Marshal.ReleaseComObject(osmLineFeatureClass);
                    }

                    if (osmPolygonFeatureClass != null)
                    {
                        osmPolygonFeatureClass.ApplyOSMClassExtension();
                        Marshal.ReleaseComObject(osmPolygonFeatureClass);
                    }
                }
                catch (Exception ex)
                {
                    message.AddError(120020, ex.ToString());
                }
            }
        }
        public static void ExportLayerToUploadableRaster(string outputFilePath, string name, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a raster layer
                ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = (IRasterLayer)source;

                // create a new raster to raster converter utility
                ESRI.ArcGIS.DataManagementTools.CopyRaster raster2raster
                    = new ESRI.ArcGIS.DataManagementTools.CopyRaster();

                // set the input raster layer
                raster2raster.in_raster = rasterLayer;

                // set the output path and Shapefile name
                /* The name and location of the raster dataset to be created.
                 * .bil—Esri BIL
                 * .bip—Esri BIP
                 * .bmp—BMP
                 * .bsq—Esri BSQ
                 * .dat—ENVI DAT
                 * .gif—GIF
                 * .img—ERDAS IMAGINE
                 * .jpg—JPEG
                 * .jp2—JPEG 2000
                 * .png—PNG
                 * .tif—TIFF
                 * no extension for Esri Grid
                 */
                raster2raster.out_rasterdataset = outputFilePath + "\\" + name + ".tif";

                // create a new GeoProcessor
                ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // execute the RasterToOtherFormat
                geoprocessor.Execute(raster2raster, null);
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
        public static void ExportLayerToShapefile(string shapePath, string shapeName, ILayer source)
        {
            try
            {
                // cast the selected/requested layer into a feature layer
                ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (IFeatureLayer)source;

                // create a new feature class to feature class converter utility
                ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fc2fc
                    = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass();

                // set the input feature layer
                fc2fc.in_features = featureLayer;

                // set the output path and Shapefile name
                fc2fc.out_path = shapePath;
                fc2fc.out_name = shapeName + ".shp";

                // create a new GeoProcessor
                ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(fc2fc, null);

                // export a copy of the layer file definition too for upload/style at a later time
                ESRI.ArcGIS.DataManagementTools.SaveToLayerFile saveToLayerFile
                    = new ESRI.ArcGIS.DataManagementTools.SaveToLayerFile();
                saveToLayerFile.in_layer = source;
                saveToLayerFile.out_layer = shapePath + "\\" + shapeName + ".lyr";

                // execute the FeatureClassToFeatureClass
                geoprocessor.Execute(saveToLayerFile, null);
            }
            catch (Exception ex)
            {
                // an error occured
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
        }
        /// <summary>
        /// Run the Geoprocessing model
        /// </summary>
        /// <param name="modelParametersHybridDictionary">A HybridDictionary that contains all of the arguments to run the model</param>
        /// <returns>A message of how well the model executed</returns>
        /// <remarks></remarks>
        public static System.String ExecuteCustomGeoprocessingFunction(System.Collections.Specialized.HybridDictionary modelParametersHybridDictionary)
        {

            try
            {

                // Create a Geoprocessor object
                ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

                // Set the OverwriteOutput setting to True
                gp.OverwriteOutput = true;

                // Create a new instance of our custom model
                MYCUSTOMTOOLBOX.GolfFinder myModel = new MYCUSTOMTOOLBOX.GolfFinder();

                // Set the custom models parameters.
                myModel.BufferDistance = modelParametersHybridDictionary["BufferDistance"];
                myModel.AIRPORT = modelParametersHybridDictionary["Airports"];
                myModel.GOLF = modelParametersHybridDictionary["Golf"];
                myModel.AirportBuffer = modelParametersHybridDictionary["AirportBuffer"];
                myModel.Golf_Courses_Near_Airports = modelParametersHybridDictionary["GolfNearAirports"];

                // Execute the model and obtain the result from the run
                ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult geoProcessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(myModel, null);

                if (geoProcessorResult == null)
                {
                    // We have an error running the model. 
                    // If the run fails a Nothing (VB.NET) or null (C#) is returned from the gp.Execute
                    object sev = 2;
                    string messages = gp.GetMessages(ref sev);
                    return messages;
                }
                else
                {
                    // The model completed successfully
                    return "Output successful. The shapefiles are locacted at: " + geoProcessorResult.ReturnValue.ToString();
                }

            }
            catch (Exception ex)
            {
                // Catch any other errors
                return "Error running the model. Debug the application and test again.";
            }

        }   
        private IFeatureLayer DissolveLineLayer(IFeatureLayer InFeatureLayer)
        {
            try{
            ITable dissolveTable = (ITable)InFeatureLayer;
            IDataset dataset = (IDataset)InFeatureLayer;

            ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
                            ESRI.ArcGIS.DataManagementTools.Dissolve d = new ESRI.ArcGIS.DataManagementTools.Dissolve();
            d.in_features = dissolveTable;
            d.out_feature_class = System.IO.Path.Combine(dataset.Workspace.PathName, "doodie");
            d.dissolve_field = "SHAPE";
            //d.statistics_fields = "";
            d.multi_part = "MULTI_PART";
            geoprocessor.Execute(d, null);

            return d.out_feature_class as IFeatureLayer ;

            //ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //ESRI.ArcGIS.DataManagementTools.Dissolve d = new ESRI.ArcGIS.DataManagementTools.Dissolve();
            //ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult Result;
            //IFeatureLayer pOutFeatureLayer = new FeatureLayer();

            //try
            //{

            //    geoprocessor.AddOutputsToMap = false;
            //    geoprocessor.OverwriteOutput = true;

            //    d.in_features = InFeatureLayer.Name ;
            //    d.dissolve_field = InFeatureLayer.FeatureClass.ShapeFieldName;
            //    d.out_feature_class = "Dissolve";

            //    Result = geoprocessor.Execute(d, null) as IGeoProcessorResult;

            //    pOutFeatureLayer.FeatureClass = geoprocessor.Open("Dissolve") as IFeatureClass;
            //    return pOutFeatureLayer;

            //IFeatureLayer OutFeatureLayer = new FeatureLayer();
            //IGxCatalogDefaultDatabase Defaultgdb = ArcMap.Application as IGxCatalogDefaultDatabase;

            //string g = Defaultgdb.DefaultDatabaseName.PathName;

            //ITable dissolveTable = (ITable)InFeatureLayer;
            //IDataset dataset = (IDataset)InFeatureLayer;

            //ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            //ESRI.ArcGIS.DataManagementTools.Dissolve d = new ESRI.ArcGIS.DataManagementTools.Dissolve();
            //d.in_features = dissolveTable;
            //d.out_feature_class = Defaultgdb.DefaultDatabaseName.PathName + "\\diss";
            //d.dissolve_field = InFeatureLayer.FeatureClass.ShapeFieldName;
            ////d.statistics_fields = "";
            ////d.multi_part = "MULTI_PART";
            //geoprocessor.Execute(d, null);

            //OutFeatureLayer.FeatureClass = d.out_feature_class as IFeatureClass;
            //return OutFeatureLayer;
            ////return d.out_feature_class as IFeatureClass;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return null;
            }
        }
        public bool CopyTable(string InTable, string OutTable, bool Messages = false)
        {
            // This works absolutely fine for dbf and geodatabase but does not export to CSV.

            // Note the csv export already removes ghe geometry field; in this case it is not necessary to check again.

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

            IGeoProcessorResult myresult = new GeoProcessorResultClass();

            // Create a variant array to hold the parameter values.
            IVariantArray parameters = new VarArrayClass();

            // Populate the variant array with parameter values.
            parameters.Add(InTable);
            parameters.Add(OutTable);

            // Execute the tool.
            try
            {
                myresult = (IGeoProcessorResult)gp.Execute("CopyRows_management", parameters, null);

                // Wait until the execution completes.
                while (myresult.Status == esriJobStatus.esriJobExecuting)
                    Thread.Sleep(1000);
                    // Wait for 1 second.

                
                if (Messages)
                {
                    MessageBox.Show("Process complete");
                }
                gp = null;
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                gp = null;
                return false;
            }
        }
        public bool CopyFeatures(string InFeatureClass, string OutFeatureClass, bool Messages = false)
        {
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.OverwriteOutput = true;
            IGeoProcessorResult myresult = new GeoProcessorResultClass();
            object sev = null;

            // Create a variant array to hold the parameter values.
            IVariantArray parameters = new VarArrayClass();

            // Populate the variant array with parameter values.
            parameters.Add(InFeatureClass);
            parameters.Add(OutFeatureClass);

            // Execute the tool.
            try
            {
                myresult = (IGeoProcessorResult)gp.Execute("CopyFeatures_management", parameters, null);
                // Wait until the execution completes.
                while (myresult.Status == esriJobStatus.esriJobExecuting)
                    Thread.Sleep(1000);
                    // Wait for 1 second.
                if (Messages)
                {
                    MessageBox.Show("Process complete");
                }
                gp = null;
                return true;
            }
            catch (Exception ex)
            {
                if (Messages)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show(gp.GetMessages(ref sev));
                }
                gp = null;
                return false;
            }
        }
        public bool AppendTable(string InTable, string TargetTable, bool Messages = false)
        {
            ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            gp.OverwriteOutput = true;

            IGeoProcessorResult myresult = new GeoProcessorResultClass();

            // Create a variant array to hold the parameter values.
            IVariantArray parameters = new VarArrayClass();


            // Populate the variant array with parameter values.
            parameters.Add(InTable);
            parameters.Add(TargetTable);

            // Execute the tool. Note this only works with geodatabase tables.
            try
            {
                myresult = (IGeoProcessorResult)gp.Execute("Append_management", parameters, null);

                // Wait until the execution completes.
                while (myresult.Status == esriJobStatus.esriJobExecuting)
                    Thread.Sleep(1000);
                // Wait for 1 second.
                if (Messages)
                {
                    MessageBox.Show("Process complete");
                }
                gp = null;
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                gp = null;
                return false;
            }
        }
Ejemplo n.º 40
0
        public IRasterCatalog CreateRasterCat(string name, string sdePath)
        {
            ESRI.ArcGIS.Geoprocessor.Geoprocessor geoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
            CreateRasterCatalog createRasterCatalog = new CreateRasterCatalog();
            IGPCoordinateSystem rSR = new GPCoordinateSystemClass();
            IGPSpatialReference gSR = new GPSpatialReferenceClass();
            rSR.SpatialReference = new UnknownCoordinateSystemClass();
            gSR.SpatialReference = new UnknownCoordinateSystemClass();

            createRasterCatalog.out_path = sdePath;
            createRasterCatalog.out_name = name;
            createRasterCatalog.raster_spatial_reference = (object)rSR;
            createRasterCatalog.spatial_reference = (object)gSR;
            geoProcessor.Execute(createRasterCatalog, null);
            IRasterCatalog rastercat = ((IRasterWorkspaceEx)this.m_workSpace).OpenRasterCatalog(name);
            return rastercat;
        }