コード例 #1
0
 /// <summary>
 /// Polulate the projection tree based on the EPSG file.
 /// </summary>
 private void PopulateList()
 {
     treeView.Nodes.Clear();
     using (Stream s = File.OpenRead(MapUtils.GetPROJ_LIB() + "\\epsg"))
     {
         using (StreamReader reader = new StreamReader(s))
         {
             string line;
             string name  = "";
             string proj4 = "";
             int    row   = 0;
             while ((line = reader.ReadLine()) != null)
             {
                 ++row;
                 if (line.StartsWith("#"))
                 {
                     if (proj4 != "")
                     {
                         // adding the previous section
                         string[] names     = name.Split(new string[] { " / " }, StringSplitOptions.None);
                         string[] proj_defs = proj4.Split(new char[] { '<', '>' });
                         if (proj_defs.Length > 3)
                         {
                             if (names.Length > 1)
                             {
                                 AddListItem(names[0].Trim(), names[1].Trim(), proj_defs[1].Trim(), proj_defs[2].Trim());
                             }
                             else
                             {
                                 if (proj_defs[2].Contains("longlat"))
                                 {
                                     AddListItem("Longitude-Latitude", names[0].Trim(), proj_defs[1].Trim(), proj_defs[2].Trim());
                                 }
                                 else
                                 {
                                     AddListItem("Other Non Geographic", names[0].Trim(), proj_defs[1].Trim(), proj_defs[2].Trim());
                                 }
                             }
                         }
                     }
                     proj4 = "";
                     name  = line.Substring(1).Trim();
                 }
                 else
                 {
                     proj4 += line;
                 }
             }
         }
     }
     treeView.Sort();
 }
コード例 #2
0
        /// <summary>
        /// Triggers a Zoom Chnaged event
        /// </summary>
        private void RaiseZoomChanged()
        {
            MS_UNITS mapunits = map.units;

            int unitPrecision = MapUtils.GetUnitPrecision(mapunits);

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }
            target.RaiseZoomChanged(this, Math.Round(zoom, unitPrecision), map.scaledenom);
        }
コード例 #3
0
        /// <summary>
        /// Click event handler of the buttonProjection control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonProjection_Click(object sender, EventArgs e)
        {
            if (projDialog == null)
            {
                projDialog = new ProjectionBrowserDialog();
            }

            projDialog.HelpRequested += new HelpEventHandler(MapPropertyEditor_HelpRequested);
            projDialog.Projection     = textBoxProjection.Text;
            if (projDialog.ShowDialog(this) == DialogResult.OK)
            {
                textBoxProjection.Text     = projDialog.Projection;
                textBoxProjection.Tag      = projDialog.ProjectionNative;
                comboBoxUnits.SelectedItem = MapUtils.GetMapUnitFromProj4(textBoxProjection.Tag.ToString());
            }
        }
コード例 #4
0
        /// <summary>
        /// Validating event handler of the textBoxZoomWidth control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void textBoxZoomWidth_Validating(object sender, CancelEventArgs e)
        {
            double result;

            if (!double.TryParse(((TextBoxBase)sender).Text, out result) || result <= 0)
            {
                MessageBox.Show("Invalid zoom width or wrong number", "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                return;
            }

            if (mapunits != map.units)
            {
                result = result * MapUtils.InchesPerUnit(mapunits) / MapUtils.InchesPerUnit(map.units);
            }

            zoomFactor        = result / (map.extent.maxx - map.extent.minx);
            textBoxScale.Text = Convert.ToString(Convert.ToInt32(map.scaledenom * zoomFactor));
        }
コード例 #5
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            mapunits = map.units;

            unitPrecision     = MapUtils.GetUnitPrecision(mapunits);
            textBoxX.Text     = Convert.ToString(Math.Round((map.extent.maxx + map.extent.minx) / 2, unitPrecision));
            textBoxY.Text     = Convert.ToString(Math.Round((map.extent.maxy + map.extent.miny) / 2, unitPrecision));
            labelUnit2.Text   = MapUtils.GetUnitName(mapunits);
            textBoxScale.Text = Convert.ToString(Convert.ToInt32(map.scaledenom));

            labelUnit1.Text = MapUtils.GetUnitName(mapunits);

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }

            textBoxZoomWidth.Text = Convert.ToString(Math.Round(zoom, unitPrecision));
        }
コード例 #6
0
        /// <summary>
        /// Validating event handler of the textBoxScale control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void textBoxScale_Validating(object sender, CancelEventArgs e)
        {
            double result;

            if (!double.TryParse(((TextBoxBase)sender).Text, out result) || result <= 0)
            {
                MessageBox.Show("Invalid scale or wrong number", "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                return;
            }
            zoomFactor = result / map.scaledenom;

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }

            textBoxZoomWidth.Text = Convert.ToString(Math.Round((zoom) * zoomFactor, unitPrecision));
        }
コード例 #7
0
        /// <summary>
        /// Click event handler of the buttonApply control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonApply_Click(object sender, EventArgs e)
        {
            double deltaX  = (map.extent.maxx - map.extent.minx) * zoomFactor / 2;
            double deltaY  = (map.extent.maxy - map.extent.miny) * zoomFactor / 2;
            double centerX = double.Parse(textBoxX.Text);
            double centerY = double.Parse(textBoxY.Text);

            map.setExtent(centerX - deltaX, centerY - deltaY, centerX + deltaX, centerY + deltaY);

            target.RaisePropertyChanged(this);

            double zoom = (map.extent.maxx - map.extent.minx);

            if (mapunits != map.units)
            {
                zoom = zoom * MapUtils.InchesPerUnit(map.units) / MapUtils.InchesPerUnit(mapunits);
            }

            target.RaiseZoomChanged(this, Math.Round(zoom, unitPrecision), map.scaledenom);

            zoomFactor = 1.0;
        }
コード例 #8
0
        public Color GetColorAtValue(double percent)
        {
            if (Value.Text == "Random values")
            {
                return(Color.FromArgb(MapUtils.GetRandomValue(256),
                                      MapUtils.GetRandomValue(256),
                                      MapUtils.GetRandomValue(256)));
            }

            // searching for the corresponding value
            int i;

            for (i = 0; i < Value.Count; i++)
            {
                if (Value.Keys[i] > percent)
                {
                    ++i;
                    break;
                }
            }

            // calculate color
            if (i > 0)
            {
                if (i < 2 || Value.Style == ColorRampStyle.Discrete)
                {
                    return(Value.Values[i - 1]);
                }
                else
                {
                    return(GetInterpolatedColor(Value.Values[i - 2], Value.Values[i - 1], percent / 100));
                }
            }
            else
            {
                return(Color.Empty);
            }
        }
コード例 #9
0
        /// <summary>
        /// Polulate the projection tree based on the EPSG file.
        /// </summary>
        private void PopulateList()
        {
            treeView.Nodes.Clear();
            using (Stream s = File.OpenRead(MapUtils.GetPROJ_LIB() + "\\epsg"))
            {
                using (StreamReader reader = new StreamReader(s))
                {
                    string line;
                    string name  = "";
                    string proj4 = "";
                    int    row   = 0;
                    while ((line = reader.ReadLine()) != null)
                    {
                        ++row;
                        if (line.StartsWith("#"))
                        {
                            if (proj4 != "")
                            {
                                ProcessLine(name, proj4);
                            }
                            proj4 = "";
                            name  = line.Substring(1).Trim();
                        }
                        else
                        {
                            proj4 += line;
                        }
                    }

                    //process last line
                    if (proj4 != "" && name != "")
                    {
                        ProcessLine(name, proj4);
                    }
                }
            }
            treeView.Sort();
        }
コード例 #10
0
        private void UpdateStyleList()
        {
            string selectedName = style.symbolname;

            if (listView.SelectedItems.Count > 0)
            {
                selectedName = listView.SelectedItems[0].Text;
            }

            // populate the style listview
            listView.Items.Clear();
            imageList.Images.Clear();

            ListViewItem selected = null;

            if (comboBoxCategory.Text != "")
            {
                // Create "no symbol" entry
                styleObj nosymbolstyle = new styleObj(null);
                MapUtils.SetDefaultColor(layer.type, nosymbolstyle);
                ListViewItem nosymbolitem = AddListItem(nosymbolstyle, layer, "Default");
                if (selectedName == null)
                {
                    selected = nosymbolitem;
                }

                if (comboBoxCategory.Text == "Inline Symbols")
                {
                    for (int i = 0; i < map.symbolset.numsymbols; i++)
                    {
                        symbolObj symbol = map.symbolset.getSymbol(i);
                        if (symbol.inmapfile == mapscript.MS_TRUE &&
                            !StyleLibrary.HasSymbol(symbol.name))
                        {
                            styleObj libstyle = new styleObj(null);
                            //if (symbol.type == (int)MS_SYMBOL_TYPE.MS_SYMBOL_PATTERNMAP)
                            //    MapUtils.SetDefaultColor(MS_LAYER_TYPE.MS_LAYER_LINE, libstyle);
                            //else
                            MapUtils.SetDefaultColor(layer.type, libstyle);
                            libstyle.setSymbolByName(map, symbol.name);
                            libstyle.size = 8;
                            MS_LAYER_TYPE type = layer.type;
                            try
                            {
                                //STEPH: change layer passed to the list view to be consistent with the other symbol categories
                                //so that it uses a point layer to display the style in the list
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                                ListViewItem item = AddListItem(libstyle, layer, symbol.name);
                                if (selectedName == item.Text)
                                {
                                    selected = item;
                                }
                            }
                            finally
                            {
                                layer.type = type;
                            }
                        }
                    }
                }
                else
                {
                    // collect all fonts specified in the fontset file
                    Hashtable fonts = new Hashtable();
                    string    key   = null;
                    while ((key = map.fontset.fonts.nextKey(key)) != null)
                    {
                        fonts.Add(key, key);
                    }

                    mapObj   styles     = StyleLibrary.Styles;
                    layerObj stylelayer = styles.getLayerByName(comboBoxCategory.Text);
                    for (int i = 0; i < stylelayer.numclasses; i++)
                    {
                        classObj classobj    = stylelayer.getClass(i);
                        int      symbolIndex = classobj.getStyle(0).symbol;
                        if (symbolIndex >= 0)
                        {
                            string font = styles.symbolset.getSymbol(symbolIndex).font;
                            if (font != null && !fonts.ContainsKey(font))
                            {
                                continue; // this font cannot be found in fontset
                            }
                        }

                        ListViewItem item = AddListItem(classobj.getStyle(0), stylelayer, classobj.name);
                        if (selectedName == item.Text)
                        {
                            selected = item;
                        }
                    }
                }
            }

            if (selected != null)
            {
                selected.Selected = true;
                selected.EnsureVisible();
            }
        }
コード例 #11
0
ファイル: RangeTheme.cs プロジェクト: xiver/MapManager
        /// <summary>
        /// Create the theme according to the individual values of the layer contents
        /// </summary>
        private MapObjectHolder CreateLayerTheme()
        {
            if (layer == null)
            {
                return(null);
            }

            int index;

            for (index = 0; index < fieldName.Length; index++)
            {
                if (fieldName[index] == comboBoxColumns.Text)
                {
                    break;
                }
            }
            if (index == fieldName.Length)
            {
                return(null);
            }

            NumberFormatInfo ni = new NumberFormatInfo();

            ni.NumberDecimalSeparator = ".";
            mapObj map = target.GetParent();

            // create a new map object
            mapObj newMap = new mapObj(null);

            newMap.units = MS_UNITS.MS_PIXELS;
            map.selectOutputFormat(map.imagetype);
            // copy symbolset
            for (int s = 1; s < map.symbolset.numsymbols; s++)
            {
                symbolObj origsym = map.symbolset.getSymbol(s);
                newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;

            while ((key = map.fontset.fonts.nextKey(key)) != null)
            {
                newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));
            }

            newLayer                = new layerObj(newMap);
            newLayer.type           = layer.type;
            newLayer.status         = mapscript.MS_ON;
            newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            // add the classObj and styles
            classObj classobj;

            if (checkBoxKeepStyles.Checked)
            {
                classobj = layer.getClass(0).clone();
                classobj.setExpression(""); // remove expression to have the class shown
                // bindings are not supported with sample maps
                for (int s = 0; s < classobj.numstyles; s++)
                {
                    StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                }
                for (int l = 0; l < classobj.numlabels; l++)
                {
                    LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                }
                newLayer.insertClass(classobj, -1);
            }
            else
            {
                classobj      = new classObj(newLayer);
                classobj.name = MapUtils.GetClassName(newLayer);
                styleObj style = new styleObj(classobj);
                style.size = 8; // set default size (#4339)

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    // initialize with the default marker if specified in the symbol file for point symbols
                    symbolObj symbol;
                    for (int s = 0; s < map.symbolset.numsymbols; s++)
                    {
                        symbol = map.symbolset.getSymbol(s);

                        if (symbol.name == "default-marker")
                        {
                            style.symbol     = s;
                            style.symbolname = "default-marker";
                            break;
                        }
                    }
                }
                MapUtils.SetDefaultColor(layer.type, style);
            }

            // calculate breaks
            int classes = (int)numericUpDownClasses.Value;

            double[] breaks = null;
            if (comboBoxMode.SelectedIndex == 0)
            {
                breaks = CalculateEqualInterval(classes, index);
            }

            if (breaks == null)
            {
                return(null);
            }

            for (int i = 0; i < classes; i++)
            {
                double percent = ((double)(i + 1)) / classes * 100;
                // creating the corresponding class object
                if (i > 0)
                {
                    classobj = classobj.clone();
                    // bindings are not supported with sample maps
                    for (int s = 0; s < classobj.numstyles; s++)
                    {
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                    }
                    for (int l = 0; l < classobj.numlabels; l++)
                    {
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                    }
                    newLayer.insertClass(classobj, -1);
                }

                classobj.name = breaks[i].ToString(ni) + " - " + breaks[i + 1].ToString(ni);
                classobj.setExpression("(([" + comboBoxColumns.SelectedItem + "] >= "
                                       + breaks[i].ToString(ni) + ") && ([" + comboBoxColumns.SelectedItem + "] <= "
                                       + breaks[i + 1].ToString(ni) + "))");
                for (int j = 0; j < classobj.numstyles; j++)
                {
                    styleObj style = classobj.getStyle(j);
                    style.color           = colorRampPickerColor.GetMapColorAtValue(percent);
                    style.outlinecolor    = colorRampPickerOutlineColor.GetMapColorAtValue(percent);
                    style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent);

                    if (checkBoxFirstOnly.Checked)
                    {
                        break;
                    }
                }
            }

            return(new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)));
        }
コード例 #12
0
        /// <summary>
        /// Refresh the layer list by submitting a GetCapabilities request.
        /// </summary>
        public void LoadLayers()
        {
            //Create the XmlDocument.
            doc             = new XmlDocument();
            doc.XmlResolver = null;

            //serverURL = textBoxServer.Text.Trim().Split(new char[] { '?' })[0];
            serverURL = textBoxServer.Text.Trim();


            //steph: remove the check as it force user to encode \ in their URL (map=c:\data\mymap.map)
            //if url is not valid, let the app report it
            //if (!Uri.IsWellFormedUriString(serverURL, UriKind.Absolute))
            //{
            //    MessageBox.Show("The specified server URL is invalid",
            //        "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}


            while (true)
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    XmlTextReader reader;
                    if (serverURL.Contains("?"))
                    {
                        reader = new XmlTextReader(serverURL + "&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0");
                    }
                    else
                    {
                        reader = new XmlTextReader(serverURL + "?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0");
                    }

                    reader.Namespaces  = false;
                    reader.XmlResolver = resolver;
                    doc.Load(reader);
                    break;
                }
                catch (WebException wex)
                {
                    if (wex.Status == WebExceptionStatus.ProtocolError)
                    {
                        // Get HttpWebResponse to check the HTTP status code.
                        HttpWebResponse httpResponse = (HttpWebResponse)wex.Response;
                        if (httpResponse.StatusCode == HttpStatusCode.Unauthorized ||
                            httpResponse.StatusCode == HttpStatusCode.ProxyAuthenticationRequired)
                        {
                            CredentialsForm form = new CredentialsForm("Authentication required for " + serverURL,
                                                                       resolver);
                            if (form.ShowDialog(this) == DialogResult.OK)
                            {
                                continue;
                            }
                            return;
                        }
                    }
                    MessageBox.Show("Unable to load WMS capabilities of the layer, " + wex.Message,
                                    "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to load WMS capabilities of the layer, " + ex.Message,
                                    "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }

            // server version
            XmlAttribute att = doc.DocumentElement.Attributes["version"];

            wms_server_version = "1.1.1";
            if (att != null)
            {
                wms_server_version = att.Value.Trim();
            }
            if (!wms_server_version.StartsWith("1.0") && !wms_server_version.StartsWith("1.1"))
            {
                wms_server_version = "1.1.1";
            }

            // load supported image types
            comboBoxImageFormat.Items.Clear();
            foreach (XmlNode node in doc.SelectNodes("//Request/GetMap/Format"))
            {
                int index = comboBoxImageFormat.Items.Add(node.InnerText.Trim());
                if (comboBoxImageFormat.Items[index].ToString() == map.outputformat.mimetype ||
                    (comboBoxImageFormat.SelectedIndex < 0 &&
                     map.outputformat.mimetype.StartsWith(comboBoxImageFormat.Items[index].ToString())) ||
                    comboBoxImageFormat.Items[index].ToString().ToLower().StartsWith("image/png"))
                {
                    comboBoxImageFormat.SelectedIndex = index;
                }
            }

            // load epsg values
            Hashtable epsg = new Hashtable();

            using (Stream s = File.OpenRead(MapUtils.GetPROJ_LIB() + "\\epsg"))
            {
                using (StreamReader reader = new StreamReader(s))
                {
                    string line;
                    string projName = "";
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.StartsWith("#") && line.Length > 2)
                        {
                            projName = line.Substring(2);
                        }
                        else if (line.StartsWith("<"))
                        {
                            string[] items = line.Split(new char[] { '<', '>' },
                                                        StringSplitOptions.RemoveEmptyEntries);
                            if (items.Length > 0)
                            {
                                epsg.Add("EPSG:" + items[0], projName);
                            }
                        }
                    }
                }
            }

            // load projections
            Dictionary <string, string> projections = new Dictionary <string, string>();
            string selectedProj = null;

            foreach (XmlNode srs in doc.SelectNodes("//CRS | //SRS"))
            {
                string[] srs2 = srs.InnerText.Split();
                foreach (string s in srs2)
                {
                    if (!projections.ContainsKey(s))
                    {
                        if (epsg.ContainsKey(s))
                        {
                            projections.Add(s, epsg[s].ToString());
                        }
                        else
                        {
                            projections.Add(s, s);
                        }

                        if (s.Contains("EPSG:4326"))
                        {
                            selectedProj = epsg[s].ToString();
                        }
                    }
                }
            }

            sortedProj = new List <KeyValuePair <string, string> >(projections);

            bs                      = new BindingSource();
            bs.DataSource           = sortedProj;
            comboBoxProj.DataSource = bs;

            UpdateProjBinding();

            if (selectedProj != null)
            {
                comboBoxProj.SelectedValue = selectedProj;
            }

            if (comboBoxImageFormat.SelectedIndex < 0 && comboBoxImageFormat.Items.Count > 0)
            {
                comboBoxImageFormat.SelectedIndex = 0;
            }

            // ensure default imageindices are invalid
            if (treeViewLayers.ImageList != null)
            {
                treeViewLayers.ImageIndex         = treeViewLayers.ImageList.Images.Count;
                treeViewLayers.SelectedImageIndex = treeViewLayers.ImageList.Images.Count;
            }

            // set up the treeView
            treeViewLayers.BeginUpdate();
            treeViewLayers.Nodes.Clear();
            listViewLayers.Items.Clear();
            foreach (XmlNode node in doc.SelectNodes("//Capability/Layer"))
            {
                AddLayerNode(treeViewLayers.Nodes, node);
            }
            treeViewLayers.EndUpdate();
            treeViewLayers.ExpandAll();

            if (treeViewLayers.Nodes.Count > 0)
            {
                treeViewLayers.Nodes[0].EnsureVisible();
            }
        }
コード例 #13
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (map == null)
            {
                return;
            }
            // general tab
            this.textBoxName.Text      = map.name;
            this.textBoxShapePath.Text = map.shapepath;
            this.textBoxImagepath.Text = map.web.imagepath;
            this.textBoxSymbolset.Text = map.symbolset.filename;
            this.textBoxFontset.Text   = map.fontset.filename;
            // image details tab
            this.colorPickerBackColor.SetColor(map.imagecolor);
            comboBoxImageType.Items.Clear();
            comboBoxImageType.Items.AddRange(new object[] { "png", "jpeg", "gif", "png8", "png24", "pdf", "svg", "cairopng"
                                                            , "GTiff", "kml", "kmz" });

            for (int i = 0; i < map.numoutputformats; i++)
            {
                outputFormatObj format = map.getOutputFormat(i);
                if (!comboBoxImageType.Items.Contains(format.name))
                {
                    comboBoxImageType.Items.Add(format.name);
                }
            }

            //outputFormatObj[] formats = map.outputformatlist;
            //for (int i = 0; i < formats.Length; i++)
            //{
            //    if (!comboBoxImageType.Items.Contains(formats[i].name))
            //        comboBoxImageType.Items.Add(formats[i].name);
            //}
            comboBoxImageType.SelectedItem = map.imagetype;
            this.textBoxResolution.Text    = map.resolution.ToString();

            // setting up the projection information
            this.textBoxProjection.Tag  = map.getProjection();
            this.textBoxProjection.Text = "";
            string key = map.getFirstMetaDataKey();

            while (key != null)
            {
                if (key == "coordsys_name")
                {
                    this.textBoxProjection.Text = map.getMetaData("coordsys_name");
                    break;
                }
                key = map.getNextMetaDataKey(key);
            }
            if (this.textBoxProjection.Text == "")
            {
                string proj4;
                int    epsg;
                this.textBoxProjection.Text = MapUtils.FindProjection(this.textBoxProjection.Tag.ToString(), out proj4, out epsg);
            }

            comboBoxUnits.DataSource   = Enum.GetValues(typeof(MS_UNITS));
            comboBoxUnits.SelectedItem = (MS_UNITS)map.units;

            checkBoxTransparent.Checked = (map.outputformat.transparent == mapscript.MS_TRUE && map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA);
            checkBoxTransparent.Enabled = (map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGB || map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA);

            // extent tab
            UpdateExtentValues();

            SetDirty(false);
        }
コード例 #14
0
        /// <summary>
        /// Create the theme according to the individual values of the layer contents
        /// </summary>
        private MapObjectHolder CreateLayerTheme()
        {
            if (layer == null)
            {
                return(null);
            }

            mapObj map = target.GetParent();

            // create a new map object
            mapObj newMap = new mapObj(null);

            newMap.units = MS_UNITS.MS_PIXELS;
            map.selectOutputFormat(map.imagetype);
            // copy symbolset
            for (int s = 1; s < map.symbolset.numsymbols; s++)
            {
                symbolObj origsym = map.symbolset.getSymbol(s);
                newMap.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;

            while ((key = map.fontset.fonts.nextKey(key)) != null)
            {
                newMap.fontset.fonts.set(key, map.fontset.fonts.get(key, ""));
            }

            newLayer                = new layerObj(newMap);
            newLayer.type           = layer.type;
            newLayer.status         = mapscript.MS_ON;
            newLayer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
            // add the classObj and styles
            classObj classobj;

            if (checkBoxKeepStyles.Checked)
            {
                classobj = layer.getClass(0).clone();
                classobj.setExpression(""); // remove expression to have the class shown
                // bindings are not supported with sample maps
                for (int s = 0; s < classobj.numstyles; s++)
                {
                    StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                }
                for (int l = 0; l < classobj.numlabels; l++)
                {
                    LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                }
                newLayer.insertClass(classobj, -1);
            }
            else
            {
                classobj      = new classObj(newLayer);
                classobj.name = MapUtils.GetClassName(newLayer);
                styleObj style = new styleObj(classobj);
                style.size = 8; // set default size (#4339)

                if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    // initialize with the default marker if specified in the symbol file for point symbols
                    symbolObj symbol;
                    for (int s = 0; s < map.symbolset.numsymbols; s++)
                    {
                        symbol = map.symbolset.getSymbol(s);

                        if (symbol.name == "default-marker")
                        {
                            style.symbol     = s;
                            style.symbolname = "default-marker";
                            break;
                        }
                    }
                }
                MapUtils.SetDefaultColor(layer.type, style);
            }

            SortedDictionary <string, string> items = new SortedDictionary <string, string>();
            int i = 0;

            shapeObj shape;

            layer.open();

            layer.whichShapes(layer.getExtent());

            if (checkBoxClassItem.Checked)
            {
                layer.classitem = comboBoxColumns.SelectedItem.ToString();
            }

            while ((shape = layer.nextShape()) != null)
            {
                string value = shape.getValue(comboBoxColumns.SelectedIndex);
                if (checkBoxZero.Checked && (value == "" || value == ""))
                {
                    continue;
                }

                if (!items.ContainsValue(value))
                {
                    if (i == 100)
                    {
                        if (MessageBox.Show("The number of the individual values is greater than 100 would you like to continue?", "MapManager",
                                            MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
                        {
                            break;
                        }
                    }

                    items.Add(value, value);

                    ++i;
                }
            }

            if (layer.getResults() == null)
            {
                layer.close(); // close only is no query results
            }
            i = 0;
            foreach (string value in items.Keys)
            {
                double percent = ((double)(i + 1)) / items.Count * 100;

                // creating the corresponding class object
                if (i > 0)
                {
                    classobj = classobj.clone();
                    // bindings are not supported with sample maps
                    for (int s = 0; s < classobj.numstyles; s++)
                    {
                        StyleBindingController.RemoveAllBindings(classobj.getStyle(s));
                    }
                    for (int l = 0; l < classobj.numlabels; l++)
                    {
                        LabelBindingController.RemoveAllBindings(classobj.getLabel(l));
                    }
                    newLayer.insertClass(classobj, -1);
                }

                classobj.name = value;
                if (checkBoxClassItem.Checked)
                {
                    classobj.setExpression(value);
                }
                else
                {
                    classobj.setExpression("('[" + comboBoxColumns.SelectedItem + "]' = '" + value + "')");
                }

                for (int j = 0; j < classobj.numstyles; j++)
                {
                    styleObj style = classobj.getStyle(j);
                    style.color           = colorRampPickerColor.GetMapColorAtValue(percent);
                    style.outlinecolor    = colorRampPickerOutlineColor.GetMapColorAtValue(percent);
                    style.backgroundcolor = colorRampPickerBackgroundColor.GetMapColorAtValue(percent);

                    if (checkBoxFirstOnly.Checked)
                    {
                        break;
                    }
                }
                ++i;
            }

            return(new MapObjectHolder(newLayer, new MapObjectHolder(newMap, null)));
        }
コード例 #15
0
        /// <summary>
        /// Click event handler of the buttonOK control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="e">The event parameters.</param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            // construct layer definition
            StringBuilder s = new StringBuilder(layerdef);

            s.Replace("%name%", MapUtils.GetUniqueLayerName(map, "grid", 0));

            s.Replace("%labelformat%", textBoxLabelFormat.Text);
            s.Replace("%labelcolorR%", colorPickerLabelColor.Value.R.ToString());
            s.Replace("%labelcolorG%", colorPickerLabelColor.Value.G.ToString());
            s.Replace("%labelcolorB%", colorPickerLabelColor.Value.B.ToString());
            s.Replace("%colorR%", colorPickerLineColor.Value.R.ToString());
            s.Replace("%colorG%", colorPickerLineColor.Value.G.ToString());
            s.Replace("%colorB%", colorPickerLineColor.Value.B.ToString());

            if (textBoxLabelSize.Text.Trim() != "")
            {
                s.Replace("%labelsize%", textBoxLabelSize.Text.ToString());
            }
            else
            {
                s.Replace("%labelsize%", "8");
            }

            if (textBoxLineWidth.Text.Trim() != "")
            {
                s.Replace("%linewidth%", textBoxLineWidth.Text.ToString());
            }
            else
            {
                s.Replace("%linewidth%", "2");
            }

            // optional parameters
            if (textBoxMinArcs.Text.Trim() != "")
            {
                s.Replace("%minarcs%", "MINARCS " + textBoxMinArcs.Text.ToString());
            }
            else
            {
                s.Replace("%minarcs%", "");
            }

            if (textBoxMaxArcs.Text.Trim() != "")
            {
                s.Replace("%maxarcs%", "MAXARCS " + textBoxMaxArcs.Text.ToString());
            }
            else
            {
                s.Replace("%maxarcs%", "");
            }

            if (textBoxMinInterval.Text.Trim() != "")
            {
                s.Replace("%mininterval%", "MININTERVAL " + textBoxMinInterval.Text.ToString());
            }
            else
            {
                s.Replace("%mininterval%", "");
            }

            if (textBoxMaxInterval.Text.Trim() != "")
            {
                s.Replace("%maxinterval%", "MAXINTERVAL " + textBoxMaxInterval.Text.ToString());
            }
            else
            {
                s.Replace("%maxinterval%", "");
            }

            if (textBoxMinSubdivide.Text.Trim() != "")
            {
                s.Replace("%minsubdivide%", "MINSUBDIVIDE " + textBoxMinSubdivide.Text.ToString());
            }
            else
            {
                s.Replace("%minsubdivide%", "");
            }

            if (textBoxMaxSubdivide.Text.Trim() != "")
            {
                s.Replace("%maxsubdivide%", "MAXSUBDIVIDE " + textBoxMaxSubdivide.Text.ToString());
            }
            else
            {
                s.Replace("%maxsubdivide%", "");
            }

            if (textBoxProjection.Tag != null)
            {
                s.Replace("%projection%", textBoxProjection.Tag.ToString());
            }
            else
            {
                s.Replace("%projection%", "init=epsg:4326");
            }

            // create layer
            layerObj layer = new layerObj(map);

            try
            {
                layer.updateFromString(s.ToString());

                DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                map.removeLayer(layer.index);
            }
        }
コード例 #16
0
        /// <summary>
        /// Adding the selected layer to map
        /// </summary>
        void AddLayerToMap()
        {
            // trying to open the layer
            layerObj layer = new layerObj(map);

            layer.connection     = textBoxServer.Text.Trim();
            layer.connectiontype = MS_CONNECTION_TYPE.MS_WMS;
            layer.type           = MS_LAYER_TYPE.MS_LAYER_RASTER;
            layer.status         = mapscript.MS_ON;

            // set up authentication
            NetworkCredential cred = (NetworkCredential)resolver.GetCredentials();

            if (cred != null)
            {
                layer.metadata.set("wms_auth_username", cred.UserName);
                layer.metadata.set("wms_auth_password", cred.Password);
                layer.metadata.set("wms_auth_type", "any");
            }
            WebProxy proxy = (WebProxy)resolver.Proxy;

            if (proxy != null)
            {
                layer.metadata.set("wms_proxy_host", proxy.Address.Host);
                layer.metadata.set("wms_proxy_port", proxy.Address.Port.ToString());
                layer.metadata.set("wms_proxy_auth_type", "any");
                layer.metadata.set("wms_proxy_type", resolver.ProxyType);
                cred = (NetworkCredential)resolver.GetProxyCredentials();
                if (cred != null)
                {
                    layer.metadata.set("wms_proxy_username", cred.UserName);
                    layer.metadata.set("wms_proxy_password", cred.Password);
                }
            }

            // setting up the selected layer
            selected = new MapObjectHolder(layer, target);

            // set queryable flag
            if (wms_queryable == "1")
            {
                layer.template = "query.html";
            }

            // setting up the layer metadata section
            layer.metadata.set("wms_name", wms_name);
            layer.metadata.set("wms_format", comboBoxImageFormat.Text.Trim());

            layer.metadata.set("wms_server_version", wms_server_version);

            if (!colorPickerLayerColor.Value.IsEmpty)
            {
                colorObj color = new colorObj(colorPickerLayerColor.Value.R,
                                              colorPickerLayerColor.Value.G, colorPickerLayerColor.Value.B, 0);
                layer.metadata.set("wms_bgcolor", "0x" + color.toHex().Substring(1));
            }

            if (!checkBoxTransparent.Checked)
            {
                layer.metadata.set("wms_transparent", "FALSE");
            }

            // wms_style
            if (comboBoxStyle.Text != "")
            {
                layer.metadata.set("wms_style", comboBoxStyle.Text);
            }

            // title
            if (wms_title != null)
            {
                layer.name = MapUtils.GetUniqueLayerName(map, wms_title, 0);
            }
            else
            {
                layer.name = MapUtils.GetUniqueLayerName(map, "Layer", 0);
            }

            // scale denom
            if (wms_maxscaledenom > 0)
            {
                layer.maxscaledenom = wms_maxscaledenom;
            }
            if (wms_minscaledenom > 0)
            {
                layer.maxscaledenom = wms_minscaledenom;
            }

            // get bbox parameters
            if (wms_bbox != null && map.numlayers == 1)
            {
                // this is the first layer, set the extent of the map
                map.setExtent(wms_bbox.minx, wms_bbox.miny, wms_bbox.maxx, wms_bbox.maxy);
            }

            // setting up the selected projection
            KeyValuePair <string, string> current = (KeyValuePair <string, string>)bs.Current;
            string wms_srs = current.Key;

            // mapping not EPSG systems to the EPSG variants
            if (string.Compare(wms_srs, "CRS:84", true) == 0)
            {
                wms_srs = "EPSG:4326";
            }
            else if (string.Compare(wms_srs, "CRS:83", true) == 0)
            {
                wms_srs = "EPSG:4369";
            }
            else if (string.Compare(wms_srs, "CRS:27", true) == 0)
            {
                wms_srs = "EPSG:4267";
            }

            if (wms_srs.StartsWith("EPSG", StringComparison.InvariantCultureIgnoreCase))
            {
                layer.metadata.set("wms_srs", wms_srs);
            }
            layer.setProjection(wms_srs);
        }
コード例 #17
0
 public static bool HasSymbol(string name)
 {
     return(MapUtils.FindSymbol(map.symbolset, name) != null);
 }
コード例 #18
0
ファイル: MapUtils.cs プロジェクト: xiver/MapManager
        /// <summary>
        /// This function tries to find out the projection from the EPSG file based on the name or the proj4 parameters
        /// </summary>
        /// <param name="projection">input projection in proj.4 fromat</param>
        /// <param name="proj4">the matching projection in the epsg file</param>
        /// <param name="proj4">epsg</param>
        /// <returns>Projection Name</returns>
        public static string FindProjection(string projection, out string proj4, out int epsg)
        {
            string[] def = null;
            if (projection.Contains("+proj"))
            {
                def = projection.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }

            // todo: epsg based search
            string projName = "";

            proj4 = "";
            epsg  = 0;
            using (Stream s = File.OpenRead(MapUtils.GetPROJ_LIB() + "\\epsg"))
            {
                using (StreamReader reader = new StreamReader(s))
                {
                    string line;
                    int    i;
                    int    minrank = 100;
                    string line2   = "";
                    while ((line = reader.ReadLine()) != null)
                    {
                        int rank = 0;
                        if (def != null)
                        {
                            // proj4 based search
                            for (i = 0; i < def.Length; i++)
                            {
                                if (!line.Contains(def[i]))
                                {
                                    if (def[i].StartsWith("+proj"))
                                    {
                                        break;
                                    }
                                    if (def[i].StartsWith("+ellps"))
                                    {
                                        break;
                                    }
                                    if (def[i].StartsWith("+zone"))
                                    {
                                        break;
                                    }
                                    if (def[i].StartsWith("+datum"))
                                    {
                                        break;
                                    }
                                    if (def[i].StartsWith("+units"))
                                    {
                                        break;
                                    }
                                    if (def[i].StartsWith("+south"))
                                    {
                                        break;
                                    }
                                    if (def[i].StartsWith("+north"))
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        ++rank;
                                    }
                                }
                            }
                            if (i == def.Length)
                            {
                                if (rank < minrank)
                                {
                                    minrank  = rank;
                                    projName = line2.Substring(2);
                                    proj4    = line;
                                    if (rank == 0)
                                    {
                                        // found
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // name based search
                            if (line.Contains(projection))
                            {
                                break;
                            }
                        }
                        if (line.StartsWith("#"))
                        {
                            line2 = line;
                        }
                    }
                }
            }

            string[] proj_defs = proj4.Split(new char[] { '<', '>' });
            if (proj_defs.Length >= 3)
            {
                proj4 = proj_defs[2].Trim();
                int.TryParse(proj_defs[1].Trim(), out epsg);
            }

            if (projName != "")
            {
                if (projName.Contains(" / "))
                {
                    return(projName);
                }
                if (proj4.Contains("longlat"))
                {
                    return("Longitude-Latitude / " + projName);
                }
                else
                {
                    return("Other Non Geographic / " + projName);
                }
            }
            else
            {
                return(projection);
            }
        }
コード例 #19
0
        public static void ExpandFontStyles()
        {
            string        symbolSetFileContents = File.ReadAllText(symbolsetFileName);
            string        fontSetFileContents   = File.ReadAllText(fontsetFileName);
            StringBuilder newSymbols            = new StringBuilder();
            StringBuilder newFonts = new StringBuilder();

            for (int i = 0; i < map.numlayers; i++)
            {
                layerObj layer = map.getLayer(i);
                if (MapUtils.HasMetadata(layer, "character-count"))
                {
                    string charcount = layer.getMetaData("character-count");
                    int    num;
                    if (layer.numclasses == 1 && charcount != null && int.TryParse(charcount, out num))
                    {
                        classObj classobj = layer.getClass(0);
                        if (!fontSetFileContents.Contains(classobj.name))
                        {
                            throw new Exception("Invalid font reference in mmstyles.map: " + classobj.name + ". The fontset file should contain an entry for this font name.");
                        }
                        for (int c = 33; c < 33 + num; c++)
                        {
                            string symbolname = classobj.name + "-" + c.ToString();

                            if (!symbolSetFileContents.Contains(symbolname))
                            {
                                symbolObj sym = new symbolObj(symbolname, null);
                                sym.character = "&#" + c.ToString() + ";";
                                sym.antialias = mapscript.MS_TRUE;
                                sym.type      = (int)MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE;
                                sym.font      = classobj.name;
                                sym.inmapfile = 0;
                                map.symbolset.appendSymbol(sym);
                                newSymbols.Append(String.Format("SYMBOL{0}  NAME \"{1}\"{0}  TYPE TRUETYPE{0}  ANTIALIAS TRUE{0}  CHARACTER \"{2}\"{0}  FONT \"{3}\"{0}END{0}", Environment.NewLine, symbolname, sym.character, sym.font));
                            }
                            if (c > 33)
                            {
                                // the first class is already inserted
                                classObj class2 = classobj.clone();
                                class2.name = symbolname;
                                styleObj style2 = class2.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                                layer.insertClass(class2, -1);
                            }
                            else
                            {
                                styleObj style2 = classobj.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                            }
                        }
                        if (!classobj.name.EndsWith("-33"))
                        {
                            classobj.name += "-33";
                        }
                    }
                    layer.removeMetaData("character-count");
                }
            }
            if (newSymbols.Length > 0)
            {
                // writing the new symbols to the symbolset file
                int lastpos = symbolSetFileContents.LastIndexOf("END", StringComparison.InvariantCultureIgnoreCase);
                symbolSetFileContents = symbolSetFileContents.Substring(0, lastpos) + newSymbols.ToString() + "END";
                File.WriteAllText(symbolsetFileName, symbolSetFileContents);
            }
            if (newFonts.Length > 0)
            {
                // writing the new fonts to the fontset file
                File.WriteAllText(fontsetFileName, fontSetFileContents + newFonts.ToString());
            }
        }
コード例 #20
0
ファイル: SelectList.cs プロジェクト: 4g0st1n0/MapManager
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            listView.Items.Clear();

            if (map != null)
            {
                // setting up the icon background colors createLegendIcon
                // will take over the legend imagecolor setting from the map object
                int red   = map.legend.imagecolor.red;
                int green = map.legend.imagecolor.green;
                int blue  = map.legend.imagecolor.blue;
                map.legend.imagecolor.red   = this.BackColor.R;
                map.legend.imagecolor.green = this.BackColor.G;
                map.legend.imagecolor.blue  = this.BackColor.B;
                listView.BackColor          = this.BackColor;

                using (outputFormatObj format = map.outputformat)
                {
                    string imageType = null;
                    if ((format.renderer != mapscript.MS_RENDER_WITH_GD &&
                         format.renderer != mapscript.MS_RENDER_WITH_AGG) ||
                        string.Compare(format.mimetype.Trim(), "image/vnd.wap.wbmp", true) == 0 ||
                        string.Compare(format.mimetype.Trim(), "image/tiff", true) == 0 ||
                        string.Compare(format.mimetype.Trim(), "image/jpeg", true) == 0)
                    {
                        // falling back to the png type in case of the esoteric or bad looking types
                        imageType = map.imagetype;
                        map.selectOutputFormat("png24");
                    }

                    imageList.Images.Clear();
                    imageList.ImageSize = new Size(30, 20);

                    try
                    {
                        for (int i = 0; i < map.numlayers; i++)
                        {
                            layerObj layer = map.getLayer(i);
                            if (layer.status != mapscript.MS_OFF)
                            {
                                resultObj res;
                                shapeObj  feature;
                                using (resultCacheObj results = layer.getResults())
                                {
                                    if (results != null && results.numresults > 0)
                                    {
                                        // creating the icon for this layer
                                        using (classObj def_class = new classObj(null)) // for drawing legend images
                                        {
                                            using (imageObj image = def_class.createLegendIcon(map, layer, 30, 20))
                                            {
                                                // drawing the class icons
                                                layer.getClass(0).drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                                byte[] img = image.getBytes();
                                                using (MemoryStream ms = new MemoryStream(img))
                                                {
                                                    imageList.Images.Add(Image.FromStream(ms));
                                                }
                                            }
                                        }

                                        // extracting the features found
                                        for (int j = 0; j < results.numresults; j++)
                                        {
                                            res     = results.getResult(j);
                                            feature = layer.getShape(res);
                                            if (feature != null)
                                            {
                                                ListViewItem item = new ListViewItem(layer.name, imageList.Images.Count - 1);
                                                item.SubItems.Add(feature.index.ToString());
                                                item.SubItems.Add(MapUtils.GetShapeTypeName((MS_SHAPE_TYPE)feature.type));
                                                listView.Items.Add(item);

                                                StringBuilder s = new StringBuilder("");
                                                s.AppendLine("Feature Properties:");
                                                for (int k = 0; k < layer.numitems; k++)
                                                {
                                                    s.Append(layer.getItem(k));
                                                    s.Append(" = ");
                                                    s.AppendLine(feature.getValue(k));
                                                }
                                                item.Tag = s.ToString();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        // switch back to the original type
                        if (imageType != null)
                        {
                            map.selectOutputFormat(imageType);
                        }
                        // restoring the original legend backgroundcolor
                        map.legend.imagecolor.red   = red;
                        map.legend.imagecolor.green = green;
                        map.legend.imagecolor.blue  = blue;
                    }

                    listView.SmallImageList = imageList;
                }
                if (listView.Items.Count > 0)
                {
                    listView.Items[0].Selected = true;
                }
                else
                {
                    richTextBox.Text = "";
                }
            }
        }