Пример #1
0
        public bool TransToGrid(string vectorFilename, string strAtrrName, string outFilename, double dPixCellSize = 0.0005, double dEnvelope_offsetX = 0, double dEnvelope_offsetY = 0, DataType typeData = DataType.GDT_Float64)
        {
            // 初始GdalRead
            this._GdalRead = GdalRead_Factory.CreateGdalRead(vectorFilename);
            this._GdalRead.InitDataSource(vectorFilename, Encoding.UTF8, 0, false);

            return(this.TransToGrid(strAtrrName, outFilename, dPixCellSize, dEnvelope_offsetX, dEnvelope_offsetY, typeData));
        }
Пример #2
0
        public bool TransToRaster(string vectorFilename, string strAtrrName, string dstRasterFile, double[] dEnvelopes, double dPixCellSize = 0.0005, double dEnvelope_offsetX = 0, double dEnvelope_offsetY = 0, string driverName = "GTiff", DataType typeData = DataType.GDT_Float32)
        {
            // 初始GdalRead
            this._GdalRead = GdalRead_Factory.CreateGdalRead(vectorFilename);
            this._GdalRead.InitDataSource(vectorFilename, Encoding.UTF8, 0, false);
            if (this._GdalRead == null || this._GdalRead.Layer == null)
            {
                Console.WriteLine(vectorFilename + " open failed.");
                return(false);
            }

            return(this.TransToRaster(strAtrrName, dstRasterFile, dEnvelopes, dPixCellSize, dEnvelope_offsetX, dEnvelope_offsetY, driverName, typeData));
        }
Пример #3
0
        /// <summary>分布图
        /// </summary>
        /// <param name="strParams">json参数</param>
        /// <returns></returns>
        private bool RunModel_Distribution()
        {
            // 解析参数
            var jsonParams = _Params;

            // 初始插值方法对象
            GdalAlg_IWD gdalAlg  = null;
            string      algType  = jsonParams["algType"] + "";
            string      algParms = JsonConvert.SerializeObject(jsonParams["algParms"]);

            switch (algType)
            {
            case "IDW":
                gdalAlg = (GdalAlg_IWD)InitGdalAlg_IWD(algParms);
                break;

            default:
                break;
            }

            // 初始格网生成参数
            string srcVectorFilename = jsonParams["srcData"]["srcVectorFilename"] + "";
            string srcTimeType       = jsonParams["srcData"]["srcTimeType"] + "";
            string strAtrrName       = jsonParams["algParms"]["algAtrrName"] + "";

            if (srcTimeType != "")
            {
                srcTimeType = "_" + srcTimeType + "";
            }
            double dCellSize         = Convert.ToDouble(jsonParams["algParms"]["algCellSize"] + "");
            double dEnvelope_offsetX = Convert.ToDouble(jsonParams["algParms"]["algEnvelope_offsetX"] + "");
            double dEnvelope_offsetY = Convert.ToDouble(jsonParams["algParms"]["algEnvelope_offsetY"] + "");
            double dNoDataValue      = -9999;

            string srcFileName           = Path.GetFileNameWithoutExtension(srcVectorFilename);
            string dstRasterFilename     = _FloderTemp + GdalCommon.CreateName(_FloderTemp, srcFileName, ".tiff") + ".tiff";
            bool   isUseClip             = Convert.ToBoolean(jsonParams["clipData"]["clipVaild"] + "");
            string clipVectorWhere       = jsonParams["clipData"]["clipWhere"] + "";
            string division              = clipVectorWhere != "" ? clipVectorWhere : "division";
            string clipVectorFilename    = GdalCommon.GetFile_Division(Convert.ToString(jsonParams["clipData"]["infoDivision"])) + division + ".geojson";
            string dstRasterFilenameClip = dstRasterFilename;

            if (isUseClip)
            {
                dstRasterFilenameClip = _FloderTemp + GdalCommon.CreateName(_FloderTemp, srcFileName, ".tiff") + "_Clip.tiff";
            }
            string strFileName = jsonParams["dstContour"]["dstFileName"] + "";

            strFileName   = strFileName != "" ? strFileName : _dtTag;  //GdalCommon.CreateName(_FloderTemp, "", ".geojson");
            _nameTag      = strAtrrName + srcTimeType + strFileName;
            _FloderOutput = _FloderOutput + "Distribution/" + gdalAlg.AlgName + "/";
            string outFilename = _FloderOutput + _nameTag + ".geojson";

            if (!Directory.Exists(_FloderOutput))
            {
                Directory.CreateDirectory(_FloderOutput);
            }

            // 初始插值源数据
            IGdalRead gdalRead = GdalRead_Factory.CreateGdalRead(srcVectorFilename);

            if (!gdalRead.InitDataSource(srcVectorFilename, Encoding.UTF8, 0, false))
            {
                Console.WriteLine(srcVectorFilename);
                this.InitError(string.Format("插值源数据{0}打开失败!数据不存在或文件错误!", Path.GetFileName(srcVectorFilename)), true);
                return(false);
            }

            // 调用IDW插值算法生成格网
            GdalTrans_Grid poTrans = new GdalTrans_Grid(gdalRead, gdalAlg);

            if (poTrans.TransToGrid(strAtrrName, dstRasterFilename, dCellSize, dEnvelope_offsetX, dEnvelope_offsetY) == false)
            {
                this.InitError("IDW插值算法生成格网出错!", true);
                return(false);
            }

            // 调用裁剪
            if (isUseClip)
            {
                GdalTrans_Clip poTrans_Clip = new GdalTrans_Clip();
                if (poTrans_Clip.ClipRaster(clipVectorFilename, "", dstRasterFilename, 1, dstRasterFilenameClip, dNoDataValue) == false)
                {
                    this.InitError("IDW插值格网裁剪出错!", true);
                    return(false);
                }
            }


            // 初始等值面提取参数
            double[] dLevelIntervals = jsonParams["dstContour"]["LevelIntervals"].ToObject <List <double> >().ToArray();
            double   dLevelBase      = Convert.ToDouble(jsonParams["dstContour"]["LevelBase"] + "");
            bool     isPolygon       = Convert.ToBoolean(jsonParams["dstContour"]["IsPolygon"] + "");

            // 调用等值面提取
            GdalTrans_Contour poTrans_Contour = new GdalTrans_Contour(gdalRead);

            poTrans_Contour.ContourGenerate(dstRasterFilenameClip, outFilename, 1, dLevelIntervals, dLevelBase, isPolygon);

            // 组装返回结果
            _ModeState = emModeState.Runout;
            _Datas     = new JObject();
            _Datas.Add("typeFile", "GeoJSON");
            _Datas.Add("typeAlg", algType);
            _Datas.Add("title", strAtrrName + srcTimeType);
            _Datas.Add("nameTag", _nameTag);
            _Datas.Add("outFile", outFilename);
            _dstRasterFile = dstRasterFilenameClip;
            return(true);
        }