Пример #1
0
 private void AddDataRequest(int sourceID, int[] origin, int[] shape)
 {
     if (!entireDataRequests.Contains(sourceID))
     {
         if (origin == null || shape == null)
         {
             foreach (var dr in pendingRequests.Where(dr => dr.Variable.ID == sourceID).ToArray())
             {
                 pendingRequests.Remove(dr);
             }
             pendingRequests.Add(DataRequest.GetData(source.Variables.GetByID(sourceID), null, null));
             entireDataRequests.Add(sourceID);
         }
         else
         {
             pendingRequests.Add(DataRequest.GetData(source.Variables.GetByID(sourceID), origin, shape));
         }
     }
 }
Пример #2
0
        public HeightMap GetHeightMap(FileMetadata metadata)
        {
            HeightMap heightMap = new HeightMap(metadata.Width, metadata.Height);

            heightMap.Count   = heightMap.Width * heightMap.Height;
            heightMap.Minimum = 15000;
            heightMap.Maximum = -15000;
            var coords = new List <GeoPoint>(heightMap.Count);

            MultipleDataResponse response = _dataset.GetMultipleData(
                DataRequest.GetData(_elevationVariable),
                DataRequest.GetData(_latVariable),
                DataRequest.GetData(_longVariable));

            Array latitudes  = response[_latVariable.ID].Data;
            Array longitudes = response[_longVariable.ID].Data;
            Array elevations = response[_elevationVariable.ID].Data;

            int index = 0;

            var elevationsEnumerator = elevations.GetEnumerator();

            foreach (double latitude in latitudes)
            {
                foreach (double longitude in longitudes)
                {
                    elevationsEnumerator.MoveNext();
                    float heightValue = (float)Convert.ChangeType(elevationsEnumerator.Current, typeof(float));

                    coords.Add(new GeoPoint(latitude, longitude, heightValue));
                    heightMap.Minimum = Math.Min(heightMap.Minimum, heightValue);
                    heightMap.Maximum = Math.Max(heightMap.Maximum, heightValue);

                    index++;
                }
            }

            Debug.Assert(index == heightMap.Count);
            heightMap.Coordinates = coords;
            return(heightMap);
        }
Пример #3
0
        public HeightMap GetHeightMapInBBox(BoundingBox bbox, FileMetadata metadata, float noDataValue = float.MinValue)
        {
            HeightMap heightMap = null;

            try
            {
                int registrationOffset = metadata.FileFormat.Registration == DEMFileRegistrationMode.Grid ? 1 : 0;

                int yNorth = (int)Math.Floor((bbox.yMax - metadata.PhysicalStartLat) / metadata.pixelSizeY);
                int ySouth = (int)Math.Ceiling((bbox.yMin - metadata.PhysicalStartLat) / metadata.pixelSizeY);
                int xWest  = (int)Math.Floor((bbox.xMin - metadata.PhysicalStartLon) / metadata.pixelSizeX);
                int xEast  = (int)Math.Ceiling((bbox.xMax - metadata.PhysicalStartLon) / metadata.pixelSizeX);

                xWest  = Math.Max(0, xWest);
                xEast  = Math.Min(metadata.Width - 1 - registrationOffset, xEast);
                yNorth = Math.Max(0, yNorth);
                ySouth = Math.Min(metadata.Height - 1 - registrationOffset, ySouth);

                heightMap       = new HeightMap(xEast - xWest + 1, yNorth - ySouth + 1);
                heightMap.Count = heightMap.Width * heightMap.Height;

                // The netCDF storage is arranged as contiguous latitudinal bands.
                MultipleDataResponse response = _dataset.GetMultipleData(
                    DataRequest.GetData(_elevationVariable, new int[] { ySouth, xWest }, new int[] { heightMap.Height, heightMap.Width }),
                    DataRequest.GetData(_latVariable, new int[] { ySouth }, new int[] { heightMap.Height }),
                    DataRequest.GetData(_longVariable, new int[] { xWest }, new int[] { heightMap.Width }));

                Array latitudes  = response[_latVariable.ID].Data;
                Array longitudes = response[_longVariable.ID].Data;
                Array elevations = response[_elevationVariable.ID].Data;

                int index = 0;

                // Coordinates in height maps are rows in lat descending order
                // Here, netCDF enumerates in lat ascending order.
                // We stack the rows and enumerate them at the end
                Stack <List <GeoPoint> > geoPointsRows = new Stack <List <GeoPoint> >();
                var elevationsEnumerator = elevations.GetEnumerator();
                foreach (double latitude in latitudes)
                {
                    List <GeoPoint> curRow = new List <GeoPoint>();
                    foreach (double longitude in longitudes)
                    {
                        elevationsEnumerator.MoveNext();
                        float heightValue = (float)Convert.ChangeType(elevationsEnumerator.Current, typeof(float));

                        curRow.Add(new GeoPoint(latitude, longitude, heightValue));

                        index++;
                    }
                    geoPointsRows.Push(curRow);
                }

                Debug.Assert(index == heightMap.Count);
                heightMap.Coordinates = GetUnstackedCoordinates(geoPointsRows, heightMap.Count); // enumerate stack
            }
            catch (Exception ex)
            {
                Trace.TraceError($"{nameof(NetCdfFile)} error: {ex.Message}");
            }

            return(heightMap);
        }