Exemplo n.º 1
0
        /// <summary> Checks if the 8 points +/- specified distance from specified UTMX/Y on specified grid (plot vs calcs) fall within bounds. /// </summary>
        /// <returns> Returns 100 if all points are within defined area and returns index of point outside range if all are not available. </returns>
        public int NewNodeCheck(TopoInfo topo, double UTMX, double UTMY, int minDist, string plotOrCalcs)
        {
            int goodToGo = 100;

            double X_Loc = 0;
            double Y_Loc = 0;

            int[] topoIndices      = topo.GetXYIndices("Topo", UTMX, UTMY, plotOrCalcs);       // topoElevs indices at site location
            int[] landCoverIndices = topo.GetXYIndices("Land cover", UTMX, UTMY, plotOrCalcs); // landCover indices at site location

            bool[] indexChecks = new bool[8];

            // Check that there is topography data
            if (topoIndices[0] == -999 && topoIndices[1] == -999)
            {
                goodToGo = -999;
                return(goodToGo);
            }

            if (topo.gotSR && landCoverIndices[0] == -999 && landCoverIndices[1] == -999)
            {
                goodToGo = -999;
                return(goodToGo);
            }

            if (topoIndices[0] == -888)
            {
                goodToGo = -888;
                return(goodToGo);
            }

            if (landCoverIndices[0] == -888)
            {
                goodToGo = -888;
                return(goodToGo);
            }

            for (int i = 0; i < 8; i++)
            {
                indexChecks[i] = true;

                if (i != 1 && i != 3 && i != 5 && i != 7) // only looking at N, E, S, W
                {
                    if (i == 0)                           // North
                    {
                        X_Loc = UTMX;
                        Y_Loc = UTMY + minDist;
                    }
                    else if (i == 1) // Northeast
                    {
                        X_Loc = UTMX + minDist * 0.7071;
                        Y_Loc = UTMY + minDist * 0.7071;
                    }
                    else if (i == 2) // East
                    {
                        X_Loc = UTMX + minDist;
                        Y_Loc = UTMY;
                    }
                    else if (i == 3) // Southeast
                    {
                        X_Loc = UTMX + minDist * 0.7071;
                        Y_Loc = UTMY - minDist * 0.7071;
                    }
                    else if (i == 4) // South
                    {
                        X_Loc = UTMX;
                        Y_Loc = UTMY - minDist;
                    }
                    else if (i == 5) // Southwest
                    {
                        X_Loc = UTMX - minDist * 0.7071;
                        Y_Loc = UTMY - minDist * 0.7071;
                    }
                    else if (i == 6) // West
                    {
                        X_Loc = UTMX - minDist;
                        Y_Loc = UTMY;
                    }
                    else if (i == 7) // Northwest
                    {
                        X_Loc = UTMX - minDist * 0.7071;
                        Y_Loc = UTMY + minDist * 0.7071;
                    }

                    topoIndices = topo.GetXYIndices("Topo", X_Loc, Y_Loc, plotOrCalcs);

                    int numXTopo = 0;
                    int numYTopo = 0;

                    if (plotOrCalcs == "Plot")
                    {
                        numXTopo = topo.topoNumXY.X.plot.num;
                        numYTopo = topo.topoNumXY.Y.plot.num;
                    }
                    else if (plotOrCalcs == "Calcs")
                    {
                        numXTopo = topo.topoNumXY.X.calcs.num;
                        numYTopo = topo.topoNumXY.Y.calcs.num;
                    }

                    if (topoIndices[0] < 0 || topoIndices[0] >= numXTopo || topoIndices[1] < 0 || topoIndices[1] >= numYTopo)
                    {
                        indexChecks[i] = false;
                    }

                    if (indexChecks[i] == true)
                    {
                        if (plotOrCalcs == "Plot")
                        {
                            if (topo.topoElevs[topoIndices[0], topoIndices[1]] == -999)
                            {
                                indexChecks[i] = false;
                            }
                        }
                    }

                    if (topo.gotSR)
                    {
                        landCoverIndices = topo.GetXYIndices("Land cover", X_Loc, Y_Loc, plotOrCalcs);

                        int numXLC = 0;
                        int numYLC = 0;

                        if (plotOrCalcs == "Plot")
                        {
                            numXLC = topo.LC_NumXY.X.plot.num;
                            numYLC = topo.LC_NumXY.Y.plot.num;
                        }
                        else if (plotOrCalcs == "Calcs")
                        {
                            numXLC = topo.LC_NumXY.X.calcs.num;
                            numYLC = topo.LC_NumXY.Y.calcs.num;
                        }

                        if (landCoverIndices[0] < 0 || landCoverIndices[0] >= numXLC || landCoverIndices[1] < 0 || landCoverIndices[1] >= numYLC)
                        {
                            indexChecks[i] = false;
                        }

                        if (indexChecks[i] == true)
                        {
                            if (plotOrCalcs == "Plot")
                            {
                                if (topo.landCover[landCoverIndices[0], landCoverIndices[1]] == -999)
                                {
                                    indexChecks[i] = false;
                                }
                            }
                        }
                    }
                }
            }

            // Go through array of booleans to figure out which way to move location
            bool allFalse = true;

            for (int i = 0; i < 8; i++)
            {
                if (i != 1 && i != 3 && i != 5 && i != 7) // only looking at N, E, S, W
                {
                    if (indexChecks[i] != true)
                    {
                        int oppSect = i - 4;
                        if (oppSect < 0)
                        {
                            oppSect = oppSect + 8;
                        }

                        if (indexChecks[oppSect] == true)
                        {
                            return(i);
                        }
                    }
                    else
                    {
                        allFalse = false;
                    }
                }
            }


            // If false at all locations, figure out which way to move based on distance to four corners
            if (allFalse == true)
            {
                double distToMinXMinY = topo.CalcDistanceBetweenPoints(UTMX, UTMY, topo.topoNumXY.X.all.min, topo.topoNumXY.Y.all.min);
                double distToMinXMaxY = topo.CalcDistanceBetweenPoints(UTMX, UTMY, topo.topoNumXY.X.all.min, topo.topoNumXY.Y.all.max);
                double distToMaxXMinY = topo.CalcDistanceBetweenPoints(UTMX, UTMY, topo.topoNumXY.X.all.max, topo.topoNumXY.Y.all.min);
                double distToMaxXMaxY = topo.CalcDistanceBetweenPoints(UTMX, UTMY, topo.topoNumXY.X.all.max, topo.topoNumXY.Y.all.max);

                if (distToMinXMinY > distToMinXMaxY && distToMinXMinY > distToMaxXMinY && distToMinXMinY > distToMaxXMaxY)
                {
                    goodToGo = 1; // Furthest from Min X/Y
                }
                else if (distToMinXMaxY > distToMinXMinY && distToMinXMaxY > distToMaxXMinY && distToMinXMaxY > distToMaxXMaxY)
                {
                    goodToGo = 3; // Furthest from MinX and MaxY
                }
                else if (distToMaxXMinY > distToMinXMinY && distToMaxXMinY > distToMinXMaxY && distToMaxXMinY > distToMaxXMaxY)
                {
                    goodToGo = 5; // Furthest from Max X/Y
                }
                else
                {
                    goodToGo = 7; // Furthest from Max X and Min Y
                }
            }


            return(goodToGo);
        }
Exemplo n.º 2
0
        /// <summary> Checks land cover at 8 points +/- 12000 m from UTMX/Y. If land cover = -999 or if outside range, return false </summary>
        public bool LandCoverCheck(TopoInfo topo, double UTMX, double UTMY, string siteName, bool showMessage)
        {
            bool   goodToGo = true;
            int    maxDist  = 12000;
            double X_Loc    = 0;
            double Y_Loc    = 0;

            int[] indices = topo.GetXYIndices("Land Cover", UTMX, UTMY, "Plot"); // Site location

            if (indices[0] == -888)
            {
                goodToGo = false;
                return(goodToGo);
            }

            // Check that there is land cover  data
            if (indices[0] == -999 && indices[1] == -999)
            {
                goodToGo = false;
                if (showMessage)
                {
                    MessageBox.Show("Land Cover data not loaded.", "Continuum 3");
                }
                return(goodToGo);
            }

            for (int i = 0; i <= 8; i++)
            {
                if (i == 0) // North
                {
                    X_Loc = UTMX;
                    Y_Loc = UTMY + maxDist;
                }
                else if (i == 1) // Northeast
                {
                    X_Loc = UTMX + maxDist * 0.7071;
                    Y_Loc = UTMY + maxDist * 0.7071;
                }
                else if (i == 2) // East
                {
                    X_Loc = UTMX + maxDist;
                    Y_Loc = UTMY;
                }
                else if (i == 3) // Southeast
                {
                    X_Loc = UTMX + maxDist * 0.7071;
                    Y_Loc = UTMY - maxDist * 0.7071;
                }
                else if (i == 4) // South
                {
                    X_Loc = UTMX;
                    Y_Loc = UTMY - maxDist;
                }
                else if (i == 5) // Southwest
                {
                    X_Loc = UTMX - maxDist * 0.7071;
                    Y_Loc = UTMY - maxDist * 0.7071;
                }
                else if (i == 6) // West
                {
                    X_Loc = UTMX - maxDist;
                    Y_Loc = UTMY;
                }
                else if (i == 7) // Northwest
                {
                    X_Loc = UTMX - maxDist * 0.7071;
                    Y_Loc = UTMY + maxDist * 0.7071;
                }

                indices = topo.GetXYIndices("Land Cover", X_Loc, Y_Loc, "Plot");

                if (indices[0] == -888)
                {
                    goodToGo = false;
                    return(goodToGo);
                }

                if (indices[0] < 0 || indices[0] >= topo.LC_NumXY.X.plot.num || indices[1] < 0 || indices[1] >= topo.LC_NumXY.Y.plot.num)
                {
                    goodToGo = false;
                    if (showMessage == true)
                    {
                        MessageBox.Show("Site: " + siteName + " is outside range of land cover data.", "Continuum 3");
                    }

                    return(goodToGo);
                }

                if (topo.landCover[indices[0], indices[1]] == -999)
                {
                    goodToGo = false;
                    if (showMessage == true)
                    {
                        MessageBox.Show("Site: " + siteName + " is outside range of land cover data.", "Continuum 3");
                    }
                    return(goodToGo);
                }
            }

            return(goodToGo);
        }