You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							258 lines
						
					
					
						
							13 KiB
						
					
					
				
			
		
		
	
	
							258 lines
						
					
					
						
							13 KiB
						
					
					
				using ESRI.ArcGIS.Carto; | 
						|
using ESRI.ArcGIS.esriSystem; | 
						|
using ESRI.ArcGIS.Geodatabase; | 
						|
using IDEParameter; | 
						|
using KGIS.Framework.Utils; | 
						|
using System; | 
						|
using System.Diagnostics; | 
						|
using System.IO; | 
						|
using System.Runtime.InteropServices; | 
						|
using System.Text; | 
						|
 | 
						|
namespace GPHelper | 
						|
{ | 
						|
    class Program | 
						|
    { | 
						|
        [STAThread] | 
						|
        static void Main(string[] args) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                //LogAPI.Debug("GP分析开始"); | 
						|
                //args = new string[1] { "PFhNTFBlcnNpc3RlZE9iamV1BTlY3Q+" }; | 
						|
                #region 授权校验及GIS授权校验 | 
						|
                if (!KGIS.Framework.AE.AELicense.AoInit()) | 
						|
                { | 
						|
                    Console.WriteLine("Err:获取GIS授权信息失效!"); | 
						|
                    return; | 
						|
                } | 
						|
                //手动设置GIS高级许可证 | 
						|
                //IAoInitialize m_AoInitialize = new AoInitializeClass(); | 
						|
                //string IsProductCodeAdvanced = ConfigurationManager.AppSettings.Get("ProductCodeAdvanced"); | 
						|
                //if (IsProductCodeAdvanced == "true" && m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeAdvanced) != esriLicenseStatus.esriLicenseAvailable) | 
						|
                //{ | 
						|
                //    esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable; | 
						|
                //    licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced); | 
						|
                //} | 
						|
                #endregion | 
						|
 | 
						|
                string arguments = Environment.GetEnvironmentVariable("MY_ARGS"); | 
						|
                if (!string.IsNullOrWhiteSpace(arguments)) | 
						|
                    args[0] = arguments; | 
						|
                GeoprocessorHelper helper = new GeoprocessorHelper(); | 
						|
                GPParamClass gPParamClass = new GPParamClass(); | 
						|
 | 
						|
                string strParm = args[0]; | 
						|
                byte[] base64ToByte = Convert.FromBase64String(strParm.Trim()); | 
						|
                strParm = Encoding.UTF8.GetString(base64ToByte); | 
						|
                IVariantArray parameters = KGIS.Framework.AE.GeoDBAPI.DeSerialzedPersist(strParm) as IVariantArray; | 
						|
                if (parameters != null) | 
						|
                { | 
						|
                    string mType = parameters.Element[parameters.Count - 1].ToString(); | 
						|
                    parameters.Remove(parameters.Count - 1); | 
						|
 | 
						|
                    if (mType == "ZLDB") | 
						|
                    { | 
						|
                        IFeatureLayer layer = parameters.Element[parameters.Count - 1] as IFeatureLayer; | 
						|
                        ESRI.ArcGIS.Geometry.ISpatialReference sp = (layer.FeatureClass as IGeoDataset).SpatialReference; | 
						|
                        parameters.Element[parameters.Count - 1] = sp; | 
						|
 | 
						|
                        helper.ZLDataCheck(parameters); | 
						|
                        Marshal.ReleaseComObject(parameters); | 
						|
                        Console.WriteLine("增量数据检查,执行成功!"); | 
						|
                        Process.GetCurrentProcess().Kill(); | 
						|
                    } | 
						|
                    else if (mType == "BGDB") | 
						|
                    { | 
						|
                        IFeatureLayer layer = parameters.Element[1] as IFeatureLayer; | 
						|
                        ESRI.ArcGIS.Geometry.ISpatialReference sp = (layer.FeatureClass as IGeoDataset).SpatialReference; | 
						|
                        parameters.Element[parameters.Count - 1] = sp; | 
						|
                        helper.BGDataCheck(parameters); | 
						|
                        Marshal.ReleaseComObject(parameters); | 
						|
                        Console.WriteLine("变更数据检查,执行成功!"); | 
						|
                        Process.GetCurrentProcess().Kill(); | 
						|
                    } | 
						|
                    else if (mType == "CJDCQBG") | 
						|
                    { | 
						|
                        helper.CJDCQBG(parameters); | 
						|
                        Console.WriteLine("村级调查区处理,执行成功!"); | 
						|
                        Process.GetCurrentProcess().Kill(); | 
						|
                    } | 
						|
                    else if (mType == "CJDCQJX") | 
						|
                    { | 
						|
                        helper.CJDCQJX(parameters); | 
						|
                        Console.WriteLine("村级调查区界线处理,执行成功!"); | 
						|
                        Process.GetCurrentProcess().Kill(); | 
						|
                    } | 
						|
                    else if (mType == "XZQBG") | 
						|
                    { | 
						|
                        Console.WriteLine("行政区处理,执行开始!"); | 
						|
                        helper.XZQBG(parameters); | 
						|
                        Console.WriteLine("行政区处理,执行成功!"); | 
						|
                        Process.GetCurrentProcess().Kill(); | 
						|
                    } | 
						|
                    else if (mType == "XZQJX") | 
						|
                    { | 
						|
                        helper.XZQJX(parameters); | 
						|
                        Console.WriteLine("行政区界线处理,执行成功!"); | 
						|
                        Process.GetCurrentProcess().Kill(); | 
						|
                    } | 
						|
                    return; | 
						|
                } | 
						|
                else | 
						|
                if (args != null && args.Length > 0) | 
						|
                { | 
						|
                    //string strParm = args[0]; | 
						|
                    //byte[] base64ToByte = Convert.FromBase64String(strParm); | 
						|
                    //strParm = Encoding.UTF8.GetString(base64ToByte); | 
						|
                    gPParamClass = SerializeAPI.DeserializeToObject<GPParamClass>(strParm); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    //string parm = Console.ReadLine(); | 
						|
                    //byte[] base64ToByte = Convert.FromBase64String(parm); | 
						|
                    //parm = Encoding.UTF8.GetString(base64ToByte); | 
						|
                    //gPParamClass = SerializeAPI.DeserializeToObject<GPParamClass>(parm); | 
						|
                    //if (gPParamClass == null) return; | 
						|
                } | 
						|
 | 
						|
                IFeatureLayer _Layer = null; | 
						|
                switch (gPParamClass.GPType) | 
						|
                { | 
						|
                    case EnumGPType.Default: | 
						|
                        helper.RepairGeo(gPParamClass); | 
						|
                        break; | 
						|
                    case EnumGPType.Dissolve: | 
						|
                        helper.DissolveAnalysis(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.Union: | 
						|
                        helper.UnionAnalysis(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.FcToFc: | 
						|
                        helper.FeatureClassToFeatureClass(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.Intersect: | 
						|
                        helper.IntersectAnalysis(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.Erase: | 
						|
                        helper.EraseAnalysis(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.PolygonToLine: | 
						|
                        helper.PolygonToLine(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.UnsplitLine: | 
						|
                        helper.UnsplitLine(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.SelectLayerByLocation: | 
						|
                        { | 
						|
                            helper.MakeFeatureLayer(gPParamClass, ref _Layer); | 
						|
                            gPParamClass.FirstFeatureLayer2 = _Layer; | 
						|
                            IFeatureLayer tempLayer = null; | 
						|
                            helper.SelectLayerByLocationAnalysis(gPParamClass, ref tempLayer); | 
						|
                            FeatureClass fc = (_Layer.FeatureClass as FeatureClass); | 
						|
                            string path = gPParamClass.TempGDBPath; | 
						|
                            if (string.IsNullOrWhiteSpace(path)) | 
						|
                            { | 
						|
                                path = Kingo.PluginServiceInterface.CommonHelper.CreateTempDB("GP"); | 
						|
                                path = Path.Combine(path, "TempGDB.gdb"); | 
						|
                            } | 
						|
                            gPParamClass = new GPParamClass(); | 
						|
                            gPParamClass.FirstFeatureLayer2 = _Layer; | 
						|
                            gPParamClass.OutFeatureClassPath = path; | 
						|
                            gPParamClass.FcName = fc.Name; | 
						|
                            gPParamClass.IsGetOutPutFeature = true; | 
						|
                            helper.FeatureClassToFeatureClass(gPParamClass, ref _Layer); | 
						|
                            gPParamClass.OutFeatureClassPath = Path.Combine(path, gPParamClass.FcName); | 
						|
                            break; | 
						|
                        } | 
						|
                    case EnumGPType.SelectLayerByAttribute: | 
						|
                        { | 
						|
                            helper.MakeFeatureLayer(gPParamClass, ref _Layer); | 
						|
                            gPParamClass.FirstFeatureLayer2 = _Layer; | 
						|
                            //IFeatureLayer tempLayer = null; | 
						|
                            helper.SelectLayerByAttributeAnalysis(gPParamClass); | 
						|
                            FeatureClass fc = (_Layer.FeatureClass as FeatureClass); | 
						|
                            string FcName = string.IsNullOrWhiteSpace(gPParamClass.FcName) ? fc.Name : gPParamClass.FcName; | 
						|
                            string path = gPParamClass.TempGDBPath; | 
						|
                            if (string.IsNullOrWhiteSpace(path)) | 
						|
                            { | 
						|
                                path = Kingo.PluginServiceInterface.CommonHelper.CreateTempDB("GP"); | 
						|
                                path = Path.Combine(path, "TempGDB.gdb"); | 
						|
                            } | 
						|
                            gPParamClass = new GPParamClass(); | 
						|
                            gPParamClass.FirstFeatureLayer2 = _Layer; | 
						|
                            gPParamClass.OutFeatureClassPath = path; | 
						|
                            gPParamClass.FcName = FcName; | 
						|
                            gPParamClass.IsGetOutPutFeature = true; | 
						|
                            helper.FeatureClassToFeatureClass(gPParamClass, ref _Layer); | 
						|
                            gPParamClass.OutFeatureClassPath = Path.Combine(path, FcName); | 
						|
                            break; | 
						|
                        } | 
						|
                    case EnumGPType.MultipartToSinglePath: | 
						|
                        helper.MultipartToSinglePath(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.SpatialJoin: | 
						|
                        helper.SpatialJoinAnalysis(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.Identify: | 
						|
                        helper.IdentifyAnalysis(gPParamClass, ref _Layer); | 
						|
                        break; | 
						|
                    case EnumGPType.BGTBYCL: | 
						|
                        { | 
						|
                            //helper.BGTBYCL(gPParamClass); | 
						|
                            helper.CreateTempGDBForGP(gPParamClass); | 
						|
                            System.IO.FileInfo info = new System.IO.FileInfo(gPParamClass.TempGDBPath); | 
						|
                            Console.WriteLine(Path.Combine(gPParamClass.TempGDBPath, info.Name + ".gdb", "GXGC_Multipart")); | 
						|
                            return; | 
						|
                        } | 
						|
                    case EnumGPType.YBG: | 
						|
                        { | 
						|
                            helper.YBG(gPParamClass); | 
						|
                            Console.WriteLine(Path.Combine(gPParamClass.TempGDBPath, "GXGC_Multipart")); | 
						|
                            //helper.CreateTempGDBForGP(gPParamClass); | 
						|
                            //System.IO.FileInfo info = new System.IO.FileInfo(gPParamClass.TempGDBPath); | 
						|
                            //Console.WriteLine(Path.Combine(gPParamClass.TempGDBPath, info.Name + ".gdb")); | 
						|
                            return; | 
						|
                        } | 
						|
                    case EnumGPType.CZCYCL: | 
						|
                        { | 
						|
                            helper.CZCYCL(gPParamClass); | 
						|
                            Console.WriteLine(Path.Combine(gPParamClass.TempGDBPath, gPParamClass.FcName)); | 
						|
                            return; | 
						|
                        } | 
						|
                    case EnumGPType.CZCBG: | 
						|
                        { | 
						|
                            helper.CZCBG(gPParamClass); | 
						|
                            Console.WriteLine(Path.Combine(gPParamClass.TempGDBPath, gPParamClass.FcName)); | 
						|
                            return; | 
						|
                        } | 
						|
                    case EnumGPType.CJDCQBG: | 
						|
                        { | 
						|
                            helper.CJDCQBG(gPParamClass); | 
						|
                            Console.WriteLine(Path.Combine(gPParamClass.TempGDBPath, "CJDCQGXGC")); | 
						|
                            return; | 
						|
                        } | 
						|
                    case EnumGPType.XZQBG: | 
						|
                        { | 
						|
                            helper.XZQBG(gPParamClass); | 
						|
                            Console.WriteLine(Path.Combine(gPParamClass.TempGDBPath, "XZQGXGC")); | 
						|
                            return; | 
						|
                        } | 
						|
                    default: | 
						|
                        break; | 
						|
                } | 
						|
                Console.WriteLine(gPParamClass.OutFeatureClassPath); | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                Console.WriteLine(ex.Message); | 
						|
                LogAPI.Debug(ex.Message); | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                //Console.ReadKey(); | 
						|
            } | 
						|
            //Console.ReadKey(); | 
						|
        } | 
						|
    } | 
						|
}
 | 
						|
 |