Esempio n. 1
0
        static public Image GenerateShadedReliefImage(
            IRasterDigitalElevationModel dem,
            IShadingMethod shadingMethod,
            ShadingParameters shadingParameters)
        {
            Bitmap bitmap = new Bitmap(dem.LonLength, dem.LatLength);

            double[][] window = new double[3][] { new double[3], new double[3], new double[3] };

            double earthRadius        = 6360000;
            double earthCircumference = earthRadius * 2 * Math.PI;
            double latSpacing         = earthCircumference / (360 * dem.LatResolution);

            shadingMethod.Initialize(shadingParameters);

            for (int y = 1; y < dem.LatLength - 1; y++)
            {
                GeoPosition geoPos     = dem.GetGeoPosition(0, y);
                double      lonSpacing = earthCircumference / (360 * dem.LonResolution) * Math.Cos(geoPos.Latitude * Math.PI / 180.0);

                for (int x = 1; x < dem.LonLength - 1; x++)
                {
                    GetMovingWindow(dem, window, x, y);

                    double dzdx = ((window[0][0] + 2 * window[0][1] + window[0][2])
                                   - (window[2][0] + 2 * window[2][1] + window[2][2]))
                                  / (8 * lonSpacing);

                    if (double.IsNaN(dzdx))
                    {
                        continue;
                    }

                    double dzdy = ((window[0][0] + 2 * window[1][0] + window[2][0])
                                   - (window[0][2] + 2 * window[1][2] + window[2][2]))
                                  / (8 * latSpacing);

                    if (double.IsNaN(dzdy))
                    {
                        continue;
                    }

                    double riseRun = Math.Sqrt(dzdx * dzdx + dzdy * dzdy);
                    double slope   = Math.PI / 2 - Math.Atan(riseRun);

                    double aspect = Math.Atan2(dzdy, dzdx);

                    //double aspect = Math.Atan2 (window[1][0] - window[1][2],
                    //    window[0][1] - window[2][1]);

                    if (dzdx != 0 || dzdy != 0)
                    {
                        if (aspect == 0)
                        {
                            aspect = Math.PI * 2;
                        }
                    }
                    else
                    {
                        aspect = 0;
                    }

                    Color color = shadingMethod.CalculateColor(aspect, slope);

                    bitmap.SetPixel(x, bitmap.Height - y, color);
                }
            }

            return(bitmap);
        }
Esempio n. 2
0
        private Polyline ConstructIsohypseSegment(IRasterDigitalElevationModel dem, IsohypseMovements isohypseMovements)
        {
            Polyline polyline = new Polyline();

            polyline.IsClosed = isohypseMovements.IsClosed;

            int x = isohypseMovements.StartingX;
            int y = isohypseMovements.StartingY;

            bool checkedOrientation = false;
            bool shouldBeReversed   = false;

            foreach (IsohypseMovement movement in isohypseMovements.Movements)
            {
                int dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;

                switch (movement)
                {
                case IsohypseMovement.East:
                    x++;
                    dx1 = dx2 = x;
                    dy1 = y;
                    dy2 = y + 1;
                    break;

                case IsohypseMovement.North:
                    dx1 = x;
                    dx2 = x + 1;
                    dy1 = dy2 = y;
                    y--;
                    break;

                case IsohypseMovement.South:
                    y++;
                    dx1 = x + 1;
                    dx2 = x;
                    dy1 = dy2 = y;
                    break;

                case IsohypseMovement.West:
                    dx1 = dx2 = x;
                    dy1 = y + 1;
                    dy2 = y;
                    x--;
                    break;
                }

                double elevation1 = dem.GetElevationForDataPoint(dx1, dy1);
                double elevation2 = dem.GetElevationForDataPoint(dx2, dy2);

                // check the orientation of the isohypse
                if (false == checkedOrientation)
                {
                    // the right-side elevation should be higher
                    if (elevation2 < elevation1)
                    {
                        shouldBeReversed = true;
                    }
                }

                double factor = (isohypseMovements.IsohypseElevation - elevation1) / (elevation2 - elevation1);
                double ix, iy;
                ix = (factor * (dx2 - dx1) + dx1);
                iy = (factor * (dy2 - dy1) + dy1);
                GeoPosition     geoPos         = dem.GetGeoPosition(ix, iy);
                Point3 <double> isohypseVertex = new Point3 <double> (geoPos.Longitude, geoPos.Latitude, isohypseMovements.IsohypseElevation);

                polyline.AddVertex(isohypseVertex);
            }

            // now reverse the polyline if needed
            if (shouldBeReversed)
            {
                polyline.Reverse();
            }

            return(polyline);
        }
        static public IList <PointOfInterest> FindPeaks(IRasterDigitalElevationModel dem, int howMany)
        {
            IList <PointOfInterest> peaks = new List <PointOfInterest> ();

            Point2 <int>[] neighbourPoints = { new Point2 <int> (-1, 0), new Point2 <int> (1, 0), new Point2 <int> (0, -1),
                                               new Point2 <int> (0, 1) };

            for (int x = 1; x < dem.LonLength - 1; x++)
            {
                for (int y = 1; y < dem.LatLength - 1; y++)
                {
                    double elevation = dem.GetElevationForDataPoint(x, y);

                    // first check if it is a peak
                    bool isPeak = true;
                    for (int i = 0; i < neighbourPoints.Length; i++)
                    {
                        if (elevation <= dem.GetElevationForDataPoint((int)(x + neighbourPoints[i].X), (int)(y + neighbourPoints[i].Y)))
                        {
                            isPeak = false;
                            break;
                        }
                    }

                    if (isPeak)
                    {
                        for (int i = 0; i < peaks.Count + 1; i++)
                        {
                            bool addPeak = false;

                            if (i == peaks.Count)
                            {
                                addPeak = true;
                            }
                            else
                            {
                                PointOfInterest peak = peaks[i] as PointOfInterest;

                                if (elevation > peak.Position.Elevation)
                                {
                                    addPeak = true;
                                }
                            }

                            if (addPeak)
                            {
                                PointOfInterest newPeak = new PointOfInterest(dem.GetGeoPosition(x, y),
                                                                              String.Format(System.Globalization.CultureInfo.InvariantCulture, "Peak {0}", elevation));
                                peaks.Insert(i, newPeak);
                                if (peaks.Count > howMany)
                                {
                                    peaks.RemoveAt(peaks.Count - 1);
                                }
                                break;
                            }
                        }
                    }
                }
            }

            return(peaks);
        }