Esempio n. 1
0
    public static MapData ReadMapData(string path, BinaryFileMetadata metadata)
    {
        float[,] data = new float[metadata.GetColumns(), metadata.GetRows()];
        float min = float.MaxValue, max = float.MinValue;

        using (BinaryReader input = new BinaryReader(StreamUtil.GetFileStream(path))) {
            for (int y = 0; y < metadata.GetRows(); y++)
            {
                for (int x = 0; x < metadata.GetColumns(); x++)
                {
                    float next = ReadNext(input, metadata);
                    data[x, y] = next;
                    if (next >= lowestPossibleHeight)
                    {
                        min = Mathf.Min(min, next);
                        max = Mathf.Max(max, next);
                    }
                }
            }
        }
        metadata.SetMinHeight(min);
        metadata.SetMaxHeight(max);
        ReplaceNoDataValuesWithMinHeight(metadata, data);

        return(new MapData(data, metadata));
    }
Esempio n. 2
0
 public void MetaDataFromSampleFileWorks()
 {
     Assert.True(Mathf.Abs((float)metadata.GetCellsize() - 10.0F) < precision, "Cellsize not correct.");
     Assert.True(metadata.GetColumns() == 10, "ncols not correct.");
     Assert.True(metadata.GetRows() == 13, "nrows not correct.");
     Assert.True(Mathf.Abs(metadata.GetMaxHeight() - 1960.91F) < precision, "maxheight not correct.");
     Assert.True(Mathf.Abs(metadata.GetMinHeight() - 1951.887F) < precision, "minheight not correct.");
     Assert.True(metadata.GetDataType() == BinaryDataType.Single, "Data type not correct.");
     Assert.True(Mathf.Abs((float)(metadata.GetLowerLeftCornerX() - (-12492736.0119444))) < precision, "Lower left corner X value not correct.");
     Assert.True(Mathf.Abs((float)(metadata.GetLowerLeftCornerY() - (4302859.27676796))) < precision, "Lower left corner Y value not correct.");
 }
Esempio n. 3
0
 private static void ReplaceNoDataValuesWithMinHeight(BinaryFileMetadata metadata, float[,] data)
 {
     for (int x = 0; x < metadata.GetColumns(); x++)
     {
         for (int y = 0; y < metadata.GetRows(); y++)
         {
             if (data[x, y] < lowestPossibleHeight)
             {
                 data[x, y] = metadata.GetMinHeight();
             }
         }
     }
 }