Пример #1
0
        /// <summary>
        /// Get the cell slope in radians based on its circular neighborhood. The results is the angle between vertical axis and normal of the cell.
        /// E.g. 0 = cell is completely flat, pi/2 = the cell is a vertical wall.
        /// </summary>
        /// <param name="cellY">Y coordinate of the cell</param>
        /// <param name="cellX">X coordinate of the cell</param>
        /// <returns>Cell slope in radians</returns>
        private double GetCellSlope(int cellY, int cellX)
        {
            double cn = Math.Sqrt(2);
            double northsouth;
            double eastwest;

            if (cellX <= 0 || cellY <= 0 || cellX >= ElevationMap.GetLength(1) - 1 || cellY >= ElevationMap.GetLength(0) - 1)
            {
                return(0);
            }

            try {
                northsouth = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY - 1, cellX] + cn * ElevationMap[cellY - 1, cellX + 1]) / 4
                             - (cn * ElevationMap[cellY + 1, cellX - 1] + ElevationMap[cellY + 1, cellX] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;

                eastwest = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY, cellX - 1] + cn * ElevationMap[cellY + 1, cellX - 1]) / 4
                           - (cn * ElevationMap[cellY - 1, cellX + 1] + ElevationMap[cellY, cellX + 1] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;
            } catch (IndexOutOfRangeException) {
                System.Diagnostics.Debug.WriteLine("{0}, {1}", cellX, cellY);
                return(0);
            }

            Vector3 northVector = Vector3.Normalize(new Vector3(0, 2 * (float)cellResolution, (float)northsouth));
            Vector3 eastVector  = Vector3.Normalize(new Vector3(2 * (float)cellResolution, 0, (float)eastwest));

            Vector3 slopeVector = Vector3.Cross(eastVector, northVector);

            return(GetVectorAngle(slopeVector, verticalVector));
        }
 public ElevationTileCollection(ElevationMap elevationMap)
 {
     foreach (var item in elevationMap.Tiles)
     {
         _elevationTiles.Add(new ElevationTile(new GpsLocation(item.Longitude, item.Latitude, 0)));
     }
 }
Пример #3
0
        /// <summary>
        ///  Calculate West-East and North-South components of the cell slope.
        /// </summary>
        /// <param name="cellY">Y coordinate of the cell</param>
        /// <param name="cellX">X coordinate of the cell</param>
        /// <param name="westeast">output West-East component</param>
        /// <param name="southnorth">output North-South component</param>
        private void GetCellSlopeComponents(int cellY, int cellX, out double eastwest, out double northsouth)
        {
            double cn = Math.Sqrt(2);

            if (cellX <= 0 || cellY <= 0 || cellX >= ElevationMap.GetLength(1) - 1 || cellY >= ElevationMap.GetLength(0) - 1)
            {
                northsouth = eastwest = 0;
                return;
            }

            try {
                northsouth = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY - 1, cellX] + cn * ElevationMap[cellY - 1, cellX + 1]) / 4
                             - (cn * ElevationMap[cellY + 1, cellX - 1] + ElevationMap[cellY + 1, cellX] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;

                eastwest = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY, cellX - 1] + cn * ElevationMap[cellY + 1, cellX - 1]) / 4
                           - (cn * ElevationMap[cellY - 1, cellX + 1] + ElevationMap[cellY, cellX + 1] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;
            } catch (IndexOutOfRangeException) {
                System.Diagnostics.Debug.WriteLine("{0}, {1}", cellX, cellY);
                northsouth = eastwest = 0;
            }
        }
 public MapGraph(Voronoi voronoi, ElevationMap elevationMap)
 {
     this.elevationMap = elevationMap;
     generateGraph(voronoi);
 }
Пример #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //initialize list
            InitializeList();

            double maxHeight = 0;
            double minHeight = 0;

            using (Tiff tiff = Tiff.Open(@"C:\Users\javier.santos\Downloads\eudem_dem_5deg_n25w020.tif", "r"))
            {
                int height = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();

                FieldValue[] modelPixelScaleTag = tiff.GetField((TiffTag)33550);
                FieldValue[] modelTiepointTag   = tiff.GetField((TiffTag)33922);
                FieldValue[] GDALMetadataTag    = tiff.GetField((TiffTag)42112);

                byte[]      GDALMetadata = GDALMetadataTag[1].GetBytes();
                XmlDocument doc          = new XmlDocument();
                string      xml          = Encoding.UTF8.GetString(GDALMetadata);
                xml = xml.Replace("\0", string.Empty);
                doc.LoadXml(xml);
                XmlNode initialXMLNode = doc.GetElementsByTagName("GDALMetadata")[0];
                foreach (XmlNode node in initialXMLNode.ChildNodes)
                {
                    string name = node.Attributes.GetNamedItem("name").Value;
                    switch (name)
                    {
                    case "STATISTICS_MAXIMUM":
                        maxHeight = Double.Parse(node.InnerText);
                        break;

                    case "STATISTICS_MINIMUM":
                        minHeight = Double.Parse(node.InnerText);
                        break;
                    }
                }

                byte[] modelPixelScale = modelPixelScaleTag[1].GetBytes();
                double pixelSizeX      = BitConverter.ToDouble(modelPixelScale, 0);
                double pixelSizeY      = BitConverter.ToDouble(modelPixelScale, 8) * -1;

                byte[] modelTransformation = modelTiepointTag[1].GetBytes();
                double originLon           = BitConverter.ToDouble(modelTransformation, 24);
                double originLat           = BitConverter.ToDouble(modelTransformation, 32);

                double startLat = originLat + (pixelSizeY / 2.0);
                double startLon = originLon + (pixelSizeX / 2.0);

                var      scanline      = new byte[tiff.ScanlineSize()];
                Single[] scanline32Bit = new Single[tiff.ScanlineSize() / 2];

                double currentLat = startLat;
                double currentLon = startLon;

                //Write into the file
                //using (StreamWriter writer = new StreamWriter("output.txt"))
                //{
                ElevationMap elevationMap = new ElevationMap();

                //for (int i = 0; i < height; i++)
                for (int i = 0; i < height; i++)
                {
                    //MapRow row = new MapRow();

                    tiff.ReadScanline(scanline, i);
                    Buffer.BlockCopy(scanline, 0, scanline32Bit, 0, scanline.Length);

                    var latitude = currentLat + (pixelSizeY * i);
                    for (int j = 0; j < scanline32Bit.Length; j++)
                    {
                        var    longitude = currentLon + (pixelSizeX * j);
                        Single value     = scanline32Bit[j];
                        if (value == 2143289344)
                        {
                            value = -9999;
                        }

                        //Check results
                        CheckMinMaxResult(new PointXYZ(latitude, longitude, value));

                        //row.Add(new PointXYZ(latitude, longitude, value));
                        //writer.Write(value + " ");
                    }

                    //elevationMap.Add(row);
                    //writer.WriteLine();
                }

                //}
            }


            //Write into the file
            using (StreamWriter writer = new StreamWriter("outputResults.txt"))
            {
                writer.WriteLine("MAX REAL HEIGHT = " + maxHeight);
                writer.WriteLine("MIN REAL HEIGHT = " + minHeight);
                writer.WriteLine();
                //Max Values
                for (int i = 0; i < MinMaxResultsSalmples; i++)
                {
                    writer.WriteLine("MAXIMUM " + i);
                    writer.WriteLine(listMaxResult[i].X + ", " + listMaxResult[i].Y + ", " + listMaxResult[i].Z);
                }
                //Min values
                for (int i = 0; i < MinMaxResultsSalmples; i++)
                {
                    writer.WriteLine("MINIMUN " + i);
                    writer.WriteLine(listMinResult[i].X + ", " + listMinResult[i].Y + ", " + listMinResult[i].Z);
                }
            }

            System.Windows.Forms.MessageBox.Show("Done");
        }