123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.IO;
- using System.Net;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using SimulationCommon;
- public class GetNCData
- {
- public tempNCread tempreadNC = new tempNCread();
- public double initlatitudes;
- public double initlongitudes;
- //longitudeArray:经度一维数组;
- //latitudeArray:纬度一维数组;
- //tempArray:海面温度_24(时间)*7(纬度)*10(经度);
- public bool GetData()
- {
- //中心点坐标应该选取伤员初始位置坐标
- string url1 = $"{Util.baseURl}rescue-platform-service/api/v1/dem/getNcInfos?ncPath=D:/data/haiyang/2023_u10_v10_temp.nc&varName=sst¢erLon=" + initlongitudes + "¢erLat=" + initlatitudes;
- // Create a GET request to the specified URL
- HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
- request1.Method = "GET";
- // Send request and get response
- using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse())
- {
- using (StreamReader reader1 = new StreamReader(response1.GetResponseStream()))
- {
- string result1 = reader1.ReadToEnd();
- //Console.WriteLine("result1:" + result1);
- // Parse the JSON string into a JObject
- JObject resultObject1 = JObject.Parse(result1);
- // Extract the 'data' field from the parsed JObject
- JArray dataArray1 = (JArray)resultObject1["data"];
- if(dataArray1 == null)
- return false;
- // Determine the dimensions of the data array
- int times5 = dataArray1.Count;
- int latitudes5 = ((JArray)dataArray1[0]).Count;
- int longitudes5 = ((JArray)dataArray1[0][0]).Count;
- // Initialize float[][][] array
- float[][][] tempArray = new float[times5][][];
- for (int t = 0; t < times5; t++)
- {
- tempArray[t] = new float[latitudes5][];
- for (int lat = 0; lat < latitudes5; lat++)
- {
- tempArray[t][lat] = new float[longitudes5];
- for (int lon = 0; lon < longitudes5; lon++)
- {
- tempArray[t][lat][lon] = (float)dataArray1[t][lat][lon] - 273.15f;
- }
- }
- }
- JArray lonArray = (JArray)resultObject1["data_lon"];
- JArray lanArray = (JArray)resultObject1["data_lat"];
- //JArray tArray = (JArray)resultObject["data_time"];
- int lons = lonArray.Count;
- int lans = lanArray.Count;
- //int times = tArray.Count;
- float[] longitudeArray = new float[lons];
- float[] latitudeArray = new float[lans];
- //float[] timeArray = new float[times];
- for (int i = 0; i < lons; i++)
- {
- longitudeArray[i] = (float)lonArray[i];
- }
- for (int j = 0; j < lans; j++)
- {
- latitudeArray[j] = (float)lanArray[j];
- }
- /* for (int k = 0; k < lons; k++)
- {
- timeArray[k] = (float)tArray[k];
- }*/
- tempreadNC.latitudeArray = latitudeArray;
- tempreadNC.longitudeArray = longitudeArray;
- tempreadNC.tempArray = tempArray;
- }
- }
- return true;
- }
-
- }
|