Exemplo n.º 1
0
        /// <summary>
        /// 区域查找
        /// </summary>
        /// <param name="queryArea">选择的范围,经纬度之间','隔开,"小经,小纬,大经,大纬"</param>
        /// <param name="ncfilepath">nc文件路径</param>
        /// <param name="zoom">地图缩放等级</param>
        public string ZoneLookUp(string queryArea, string ncfilepath, string zoom)
        {
            Inital(ncfilepath);
            IRectangle zoneQueryRect = CoreUtil.GetRectangle <QueryRectangleF>(queryArea);   //前台所要查找的范围
            //2.读取nc文件
            //先读取经纬度信息,确定读取的下标
            NCFileUtil    ncFile = new NCFileUtil(ncfilepath);
            NcLonLatModel ncLatLonModel = ncFile.ReadNcLonLat(models[0]);
            int           minLonIndex = 0, maxLonIndex = 0, minLatIndex = 0, maxLatIndex = 0;

            CoreUtil.GetIndex(ncLatLonModel.Lon, zoneQueryRect.minLon, zoneQueryRect.maxLon, ref minLonIndex, ref maxLonIndex);
            CoreUtil.GetIndex(ncLatLonModel.Lat, zoneQueryRect.minLat, zoneQueryRect.maxLat, ref minLatIndex, ref maxLatIndex);
            ncLatLonModel.minLonIndex = minLonIndex; ncLatLonModel.minLatIndex = minLatIndex; ncLatLonModel.maxLonIndex = maxLonIndex; ncLatLonModel.maxLatIndex = maxLatIndex;

            QueryNcDataModel queryNcDataModel = new QueryNcDataModel();

            queryNcDataModel.ncLatLonModel = ncLatLonModel;
            queryNcDataModel.StartRow      = minLatIndex;
            queryNcDataModel.StartColumn   = minLonIndex;
            queryNcDataModel.EndRow        = maxLatIndex;
            queryNcDataModel.EndColumn     = maxLonIndex;
            queryNcDataModel.RowCount      = maxLatIndex - minLatIndex + 1;
            queryNcDataModel.ColumnCount   = maxLonIndex - minLonIndex + 1;
            queryNcDataModel.Dir           = ncFile.GetValueInArea(models[0].Dir, minLatIndex, minLonIndex, queryNcDataModel.RowCount, queryNcDataModel.ColumnCount);
            queryNcDataModel.Value         = ncFile.GetValueInArea(models[0].Value, minLatIndex, minLonIndex, queryNcDataModel.RowCount, queryNcDataModel.ColumnCount);
            queryNcDataModel.Levels        = CoreUtil.GetLEVEL(queryNcDataModel.RowCount, queryNcDataModel.ColumnCount, 6);

            GFSWeatherJson gfsjson = new GFSWeatherJson();
            string         json    = gfsjson.createGeoJsonFromNetcdf(queryNcDataModel, int.Parse(zoom));

            return(json);
        }
Exemplo n.º 2
0
        public string createGeoJsonFromNetcdf(QueryNcDataModel queryNcDataModel, int zoom)
        {
            int countZoom = 0;

            for (int i = 0; i < queryNcDataModel.Levels.Length; i++)
            {
                if (queryNcDataModel.Levels[i] == 3)
                {
                    countZoom++;
                }
            }

            NcJsonObject uObject = new NcJsonObject();
            NcJsonHeader uHeader = new NcJsonHeader();

            uHeader.parameterNumber     = 2;
            uHeader.parameterNumberName = "U-7";
            uHeader.numberPoints        = queryNcDataModel.ncLatLonModel.Lat.Length * queryNcDataModel.ncLatLonModel.Lon.Length;
            uHeader.nx     = queryNcDataModel.ncLatLonModel.Lon.Length;
            uHeader.ny     = queryNcDataModel.ncLatLonModel.Lat.Length;
            uHeader.lo1    = queryNcDataModel.ncLatLonModel.minLon;
            uHeader.lo2    = queryNcDataModel.ncLatLonModel.maxLon;
            uHeader.la1    = queryNcDataModel.ncLatLonModel.maxLat;
            uHeader.la2    = queryNcDataModel.ncLatLonModel.minLat;
            uHeader.dx     = 1;
            uHeader.dy     = 1;
            uObject.header = uHeader;
            uObject.data   = new double[countZoom];


            NcJsonObject vObject = new NcJsonObject();
            NcJsonHeader vHeader = new NcJsonHeader();

            vHeader.parameterNumber     = 3;
            vHeader.parameterNumberName = "V-component_of_wind";
            vHeader.numberPoints        = queryNcDataModel.ncLatLonModel.Lat.Length * queryNcDataModel.ncLatLonModel.Lon.Length;
            vHeader.nx     = queryNcDataModel.ncLatLonModel.Lon.Length;
            vHeader.ny     = queryNcDataModel.ncLatLonModel.Lat.Length;
            vHeader.lo1    = queryNcDataModel.ncLatLonModel.minLon;
            vHeader.lo2    = queryNcDataModel.ncLatLonModel.maxLon;
            vHeader.la1    = queryNcDataModel.ncLatLonModel.maxLat;
            vHeader.la2    = queryNcDataModel.ncLatLonModel.minLat;
            vHeader.dx     = 1;
            vHeader.dy     = 1;
            vObject.header = vHeader;
            vObject.data   = new double[countZoom];

            DateTime start = DateTime.Now;

            int   idx = 0;
            float u = 0f, v = 0f;

            for (int j = 0; j < queryNcDataModel.Value.Length; j++)
            {
                if (queryNcDataModel.Levels[j] != zoom)
                {
                    continue;
                }

                float _dir   = queryNcDataModel.Dir[j];
                float _power = queryNcDataModel.Value[j];
                if (!float.IsNaN(_power))
                {
                    CalUV(ref u, ref v, (double)_dir, (double)_power);
                    //uHeader  power
                    vObject.data[idx] = saveValidNumber(v, 2);
                    //vHeader  dir
                    uObject.data[idx] = saveValidNumber(u, 2);
                }
                else
                {
                    //uHeader  power
                    vObject.data[idx] = float.NaN;
                    //vHeader  dir
                    uObject.data[idx] = float.NaN;
                }
                idx++;
            }

            List <NcJsonObject> objectFiles = new List <NcJsonObject>();

            objectFiles.Add(vObject);
            objectFiles.Add(uObject);

            string json = JsonUtil.JsonSerialize <NcJsonObject>(objectFiles);

            return(json);
        }