示例#1
0
        public void Message(string msg, ref bool Handled)
        {
            if (msg.StartsWith("ODP_Selected_WMS_Layer") || msg.StartsWith("ODP_Added_WMS_Layer"))
            {
                m_OnWMSLayer       = true;
                m_WMSLayerIDReturn = "";

                if (Activated)
                {
                    // Force reloading of the new layer by toggling activation
                    MapWinGIS.Extents oldExts = m_MapWin.View.Extents;
                    LoadLayer();
                    m_MapWin.View.Extents = oldExts;
                }
            }
            else if (msg.StartsWith("ODP_Selected_Non_WMS_Layer"))
            {
                m_OnWMSLayer       = false;
                m_WMSLayerIDReturn = "";
            }
            else if (msg.StartsWith("ODP_Identifier_Data_Return"))
            {
                if (Activated)
                {
                    m_WMSLayerIDReturn = msg.Replace("ODP_Identifier_Data_Return ", "");
                    // Force reloading of the new layer by toggling activation
                    MapWinGIS.Extents oldExts = m_MapWin.View.Extents;
                    LoadLayer();
                    m_MapWin.View.Extents = oldExts;
                }
            }
        }
示例#2
0
 public void SnapshotTest()
 {
     MapWindow.Interfaces.View target   = new View(); // TODO: Initialize to an appropriate value
     MapWinGIS.Extents         Bounds   = null;       // TODO: Initialize to an appropriate value
     MapWinGIS.Image           expected = null;       // TODO: Initialize to an appropriate value
     MapWinGIS.Image           actual;
     actual = target.Snapshot(Bounds);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
示例#3
0
        /// <summary>
        /// determine if the shape is partially inside grid extents
        /// </summary>
        /// <param name="shp"></param>
        /// <param name="hdr"></param>
        /// <returns>false, if the shape is completely outside grid extents
        ///          true, if it's at least partially inside</returns>
        private bool IsGridContainsShape(MapWinGIS.Shape shp, MapWinGIS.GridHeader hdr)
        {
            double gridXmin = hdr.XllCenter;
            double gridYmin = hdr.YllCenter;
            double gridXmax = gridXmin + (hdr.NumberCols * hdr.dX);
            double gridYmax = gridYmin + (hdr.NumberRows * hdr.dY);

            MapWinGIS.Extents ext = shp.Extents;
            if (ext.xMin > gridXmax || ext.yMin > gridYmax ||
                ext.xMax < gridXmin || ext.yMax < gridYmin)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        private string GetLayerDescription()
        {
            string s = "";

            MapWinGIS.Map map = _legend.Map;
            if (map != null)
            {
                txtComments.Text = map.get_LayerDescription(_layerHandle);
            }

            MapWinGIS.Extents ext = _shapefile.Extents;
            //string units = Globals.get_MapUnits();
            string units = "";
            string type  = _shapefile.ShapefileType.ToString().Substring(4).ToLower() + " shapefile";

            var layer = map.get_OgrLayer(_layerHandle);

            if (layer != null)
            {
                s += "Datasource type: OGR layer" + Environment.NewLine;
                s += "Driver name: " + layer.DriverName + Environment.NewLine;
                s += "Connection string: " + layer.GetConnectionString() + Environment.NewLine;
                s += "Layer type: " + layer.SourceType.ToString() + Environment.NewLine;
                s += "Name or query: " + layer.GetSourceQuery() + Environment.NewLine;
                s += "Support editing: " + layer.SupportsEditing[tkOgrSaveType.ostSaveAll] + Environment.NewLine;
                s += "Dynamic loading: " + layer.DynamicLoading + "\n";
            }
            else
            {
                s += "Datasource type: ESRI Shapefile" + Environment.NewLine;
            }

            s += "Type: " + type + Environment.NewLine +
                 "Number of shapes: " + _shapefile.NumShapes + Environment.NewLine +
                 "Selected: " + _shapefile.NumSelected + Environment.NewLine +
                 "Source: " + _shapefile.Filename + Environment.NewLine +
                 "Bounds X: " + String.Format("{0:F2}", ext.xMin) + " to " + String.Format("{0:F2}", ext.xMax) + units + Environment.NewLine +
                 "Bounds Y: " + String.Format("{0:F2}", ext.yMin) + " to " + String.Format("{0:F2}", ext.yMax) + units + Environment.NewLine +
                 "Projection: " + _shapefile.Projection;
            return(s);
        }
示例#5
0
        public void LayerSelected(int Handle)
        {
            if (Handle == -1)
            {
                return;
            }

            //only do this if not on a wms layer, because wms layers are handled through the Message
            if (!m_OnWMSLayer)
            {
                if (Activated)
                {
                    // Force reloading of the new layer by toggling activation
                    MapWinGIS.Extents oldExts = m_MapWin.View.Extents;
                    //Activated = false;
                    //Activated = true;
                    LoadLayer();
                    m_MapWin.View.Extents = oldExts;
                }
            }
        }
示例#6
0
        public MapWinGIS.Extents GetBoundBox(Bounds bounds)
        {
            double maxX, maxY, minX, minY;
            double x1 = 0, y1 = 0, x2 = 0, y2 = 0;

            MapWinGIS.Extents boundBox = new MapWinGIS.Extents();

            //get the projection points
            m_MapWin.View.PixelToProj(bounds.x1, bounds.y1, ref x1, ref y1);
            m_MapWin.View.PixelToProj(bounds.x2, bounds.y2, ref x2, ref y2);

            //Set max and min X values
            if (x1 >= x2)
            {
                maxX = x1;
                minX = x2;
            }
            else
            {
                maxX = x2;
                minX = x1;
            }

            //Set max and min Y values
            if (y1 >= y2)
            {
                maxY = y1;
                minY = y2;
            }
            else
            {
                maxY = y2;
                minY = y1;
            }

            boundBox.SetBounds(minX, minY, 0, maxX, maxY, 0);

            return(boundBox);
        }
示例#7
0
        private MapWinGIS.Extents GetMaxExtents(MapWinGIS.Extents ex, MapWinGIS.GridHeader header)
        {
            MapWinGIS.Extents extents = new MapWinGIS.ExtentsClass();
            double            xMin = 0, xMax = 0, yMin = 0, yMax = 0;
            double            newXMin = 0, newXMax = 0, newYMin = 0, newYMax = 0;

            //find the grid Max and Min extents
            xMin = header.XllCenter;
            yMin = header.YllCenter;
            xMax = header.XllCenter + header.dX * header.NumberCols;
            yMax = header.YllCenter + header.dY * header.NumberRows;

            if (ex == null)
            {
                return(null);
            }
            else if (ex.xMax < xMin || ex.yMax < yMin || ex.xMin > xMax || ex.yMin > yMax)
            {
                //out of bounds return nothing
                return(null);
            }
            else
            {
                //check to make sure the selected bounds are within the grid
                if (ex.xMin < xMin)
                {
                    newXMin = xMin;
                }
                else
                {
                    newXMin = ex.xMin;
                }

                if (ex.yMin < yMin)
                {
                    newYMin = yMin;
                }
                else
                {
                    newYMin = ex.yMin;
                }

                if (ex.xMax > xMax)
                {
                    newXMax = xMax;
                }
                else
                {
                    newXMax = ex.xMax;
                }

                if (ex.yMax > yMax)
                {
                    newYMax = yMax;
                }
                else
                {
                    newYMax = ex.yMax;
                }

                extents.SetBounds(newXMin, newYMin, 0, newXMax, newYMax, 0);
            }

            return(extents);
        }
示例#8
0
        private void PopulateLV(ref System.Data.DataSet dataset, Grid grid, MapWinGIS.Extents extents, int LyrHandle)
        {
            int maxCapacity = grid.Header.NumberCols * grid.Header.NumberRows;

            System.Collections.Hashtable table = new Hashtable();
            int       endRow = 0, endCol = 0;
            int       startRow = 0, startCol = 0;
            double    cellValue = 0;
            GridValue gridValue;

            try
            {
                //find the begining and end cells
                grid.ProjToCell(extents.xMin, extents.yMax, out startCol, out startRow);
                grid.ProjToCell(extents.xMax, extents.yMin, out endCol, out endRow);

                MapWinGIS.GridDataType type = grid.DataType;

                // Ensure the same datatype is used between noDataValue and Cell Value to prevent missing
                // digits on scientific notation
                double noDataValue = 0;

                if (type == MapWinGIS.GridDataType.LongDataType)
                {
                    noDataValue = (double)Math.Round(double.Parse(grid.Header.NodataValue.ToString()));
                }
                else if (type == MapWinGIS.GridDataType.DoubleDataType)
                {
                    noDataValue = double.Parse(grid.Header.NodataValue.ToString());
                }
                else if (type == MapWinGIS.GridDataType.FloatDataType)
                {
                    noDataValue = (double)float.Parse(grid.Header.NodataValue.ToString());
                }
                else if (type == MapWinGIS.GridDataType.ShortDataType)
                {
                    noDataValue = (double)short.Parse(grid.Header.NodataValue.ToString());
                }

                bool WarnedBefore = false;
                //find all the values and the count
                for (int row = startRow; row <= endRow; row++)
                {
                    for (int col = startCol; col <= endCol; col++)
                    {
                        try
                        {
                            //System.Diagnostics.Debug.WriteLine("Col: " + col + " Row: " + row);
                            //System.Diagnostics.Debug.WriteLine(grid.get_Value(col,row).ToString());
                            if (type == MapWinGIS.GridDataType.LongDataType)
                            {
                                cellValue = long.Parse(grid.get_Value(col, row).ToString());
                            }
                            else if (type == MapWinGIS.GridDataType.DoubleDataType)
                            {
                                cellValue = double.Parse(grid.get_Value(col, row).ToString());
                            }
                            else if (type == MapWinGIS.GridDataType.FloatDataType)
                            {
                                cellValue = float.Parse(grid.get_Value(col, row).ToString());
                            }
                            else if (type == MapWinGIS.GridDataType.ShortDataType)
                            {
                                cellValue = short.Parse(grid.get_Value(col, row).ToString());
                            }

                            //ignore the value if it is a no data value
                            // Assume that if the value and the nodata value are both very near min long, it's nodata (float rounding errors)
                            if (cellValue != noDataValue && !(cellValue < -2147483640 && noDataValue < -2147483640))
                            {
                                //if the table contains the value then increment the count
                                if (table.Contains(cellValue))
                                {
                                    gridValue = (GridValue)table[cellValue];
                                    gridValue.count++;
                                    table[cellValue] = gridValue;
                                }
                                //add a new value to the table.
                                // Cap to maximum size of unique values
                                else if (table.Count < 10000)
                                {
                                    gridValue           = new GridValue();
                                    gridValue.cellValue = cellValue;
                                    gridValue.count     = 1;
                                    table.Add(cellValue, gridValue);
                                }
                                else
                                {
                                    if (!WarnedBefore)
                                    {
                                        MapWinUtility.Logger.Message("Warning: Exceeded maximum cap of 10,000 unique values in the table. Some values may be ommitted.", "Exceeded Max Unique Values", MessageBoxButtons.OK, MessageBoxIcon.Information, DialogResult.OK);
                                        WarnedBefore = true;
                                    }
                                }
                            }
                        }
                        catch (FormatException)
                        {
                            // Probably a bad nodata value.
                        }
                    }
                }

                if (table.Count > 0)
                {
                    IDictionaryEnumerator myEnumerator = table.GetEnumerator();

                    //itialize the high and low values
                    myEnumerator.MoveNext();
                    double high = ((GridValue)myEnumerator.Value).cellValue;
                    double low  = ((GridValue)myEnumerator.Value).cellValue;
                    myEnumerator.Reset();

                    //move to the next value in the hashtable
                    while (myEnumerator.MoveNext())
                    {
                        gridValue = (GridValue)myEnumerator.Value;
                        string s  = gridValue.cellValue.ToString();
                        double ds = 0;
                        double.TryParse(s, out ds);

                        if (m_parent.m_MapWin.Layers[LyrHandle].ColoringScheme != null)
                        {
                            MapWinGIS.GridColorScheme sch = (MapWinGIS.GridColorScheme)m_parent.m_MapWin.Layers[LyrHandle].ColoringScheme;
                            for (int z = 0; z < sch.NumBreaks; z++)
                            {
                                MapWinGIS.GridColorBreak brk = sch.get_Break(z);
                                double compareStart          = 0;
                                double compareEnd            = 0;
                                if (double.TryParse(brk.HighValue.ToString(), out compareEnd) && double.TryParse(brk.LowValue.ToString(), out compareStart))
                                {
                                    if (compareEnd >= ds && compareStart <= ds && brk.Caption != "")
                                    {
                                        s += " (" + brk.Caption + ")";
                                        break;
                                    }
                                }
                                else
                                {
                                    if (brk.HighValue.ToString() == s && brk.LowValue.ToString() == s && brk.Caption != "")
                                    {
                                        s += " (" + brk.Caption + ")";
                                        break;
                                    }
                                }
                            }
                        }

                        dataset.Tables[0].Rows.Add(s, gridValue.count.ToString());

                        //keep track of the high and low values in the hashtable
                        if (gridValue.cellValue > high)
                        {
                            high = gridValue.cellValue;
                        }

                        if (gridValue.cellValue < low)
                        {
                            low = gridValue.cellValue;
                        }
                    }

                    lbHighValue.Text = high.ToString();
                    lbLowValue.Text  = low.ToString();
                }
                //the region that was selected was out of the grid bounds
                else
                {
                    lbHighValue.Text = "No Data";
                    lbLowValue.Text  = "No Data";
                }
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("PopulateLV()", ex.Message);
            }
        }
示例#9
0
        public void PopulateForm(bool ShowAfterward, MapWinGIS.Grid grid, string layerName, MapWinGIS.Extents ex, int LyrHandle)
        {
            m_HavePanel = !ShowAfterward;

            try
            {
                SetTitle(layerName);
                MapWinGIS.Extents extents = null;

                //clear the list view
                dgv.DataSource = null;

                System.Data.DataSet ds = new System.Data.DataSet();
                ds.Tables.Add();
                ds.Tables[0].Columns.Add("Value", typeof(string));
                ds.Tables[0].Columns.Add("Count", typeof(long));

                if (m_hDraw != -1)
                {
                    m_parent.m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                    m_hDraw = -1;
                }

                //recalculates the extents if needed
                extents = GetMaxExtents(ex, grid.Header);

                extents = ex;

                if (extents != null)
                {
                    //set the map cursor to a wait cursor
                    MapWinGIS.tkCursor m_PreviousCursor = m_parent.m_MapWin.View.MapCursor;
                    m_parent.m_MapWin.View.MapCursor = MapWinGIS.tkCursor.crsrWait;

                    //populate all the values and counts
                    PopulateLV(ref ds, grid, extents, LyrHandle);

                    //set the cursor back to the Identifier cursor
                    m_parent.m_MapWin.View.MapCursor = m_PreviousCursor;
                }
                else
                {
                    lbHighValue.Text = "No Data";
                    lbLowValue.Text  = "No Data";
                }

                SkipDisplayValues = true;
                if (m_hDraw != -1)
                {
                    m_parent.m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                }

                dgv.DataSource = ds.Tables[0];

                if (dgv.SelectedRows.Count > 0)
                {
                    dgv.SelectedRows[0].Selected = false;
                }

                SkipDisplayValues = false;

                m_Extents = extents;
                m_Grid    = grid;

                if (ShowAfterward)
                {
                    this.Show();
                }
            }
            catch (System.Exception exception)
            {
                ShowErrorBox("PopulateForm()", exception.Message);
            }
        }