public static StatResultItem[] AreaStat <T>(string productName, string fname, ref string title, object aoiObj, Func <T, int, int> weight) { if (string.IsNullOrEmpty(fname)) { return(null); } IStatAnalysisEngine <T> exe = new StatAnalysisEngine <T>(); if (aoiObj == null) { title = productName + "按当前区域面积统计"; return(AreaStatByType <T>(productName, fname, "当前区域", title, weight)); } else { if (aoiObj as Dictionary <string, int[]> != null) { Dictionary <string, int[]> aoi = aoiObj as Dictionary <string, int[]>; title = productName + "自定义面积统计"; return(AreaStatCustom <T>(productName, fname, title, aoi, weight)); } else { title = productName + "按" + aoiObj.ToString() + "面积统计"; return(AreaStatByType <T>(productName, fname, aoiObj.ToString(), title, weight)); } } }
/// <summary> /// 按类型进行进行面积统计 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <param name="productName">产品名称:大雾、海冰、沙尘 ect</param> /// <param name="session"></param> /// <param name="statType">统计类型:当前区域 | 省级行政区划 | 土地利用类型</param> /// <param name="title">图表标题</param> /// <param name="filter">过滤条件 如:(v)=>{return v==1;}</param> private static StatResultItem[] AreaStatByType <T>(string productName, string fname, string statType, string title, Func <T, bool> filter) { IStatAnalysisEngine <T> exe = new StatAnalysisEngine <T>(); if (string.IsNullOrEmpty(title)) { title = productName + "按" + statType + "面积统计"; } if (string.IsNullOrEmpty(fname)) { return(null); } StatResultItem[] items = null; IRasterDataProvider prd = null; try { prd = GeoDataDriver.Open(fname) as IRasterDataProvider; if (statType == "当前区域") { items = AreaStatCurrentRegion <T>(prd, title, filter); } else { items = exe.StatArea(prd, statType, filter); } return(items); } catch { throw new ArgumentException("选择的文件:“" + Path.GetFileName(fname) + "”无法进行面积统计。"); } finally { if (prd != null) { prd.Dispose(); prd = null; } } }
/// <summary> /// 自定义统计 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <param name="productName">产品名称:大雾、海冰、沙尘 ect</param> /// <param name="session"></param> /// <param name="title">图表标题</param> /// <param name="weight">过滤条件 如:(v)=>{return v==1;}</param> private static StatResultItem[] AreaStatCustom <T>(string productName, string fname, string title, Dictionary <string, int[]> aoi, Func <T, int, int> weight) { IStatAnalysisEngine <T> exe = new StatAnalysisEngine <T>(); if (string.IsNullOrEmpty(title)) { title = productName + "面积统计"; } if (string.IsNullOrEmpty(fname)) { return(null); } StatResultItem[] items = null; IRasterDataProvider prd = null; try { prd = GeoDataDriver.Open(fname) as IRasterDataProvider; if (aoi == null || aoi.Count == 0) { return(null); } items = exe.StatAreaCustom(prd, aoi, weight); return(items); } catch { throw new ArgumentException("选择的文件:“" + Path.GetFileName(fname) + "”无法进行自定义面积统计。"); } finally { if (prd != null) { prd.Dispose(); prd = null; } } }