Beispiel #1
0
 public FieldSelectionForm(layerObj layer, string msg)
 {
     InitializeComponent();
     labelItem.Text = msg;
     layer.open();
     for (int i = 0; i < layer.numitems; i++)
     {
         listBoxItems.Items.Add(layer.getItem(i));
     }
     layer.close();
     buttonOK.Enabled = false;
 }
 public FieldSelectionForm(layerObj layer, string msg)
 {
     InitializeComponent();
     labelItem.Text = msg;
     layer.open();
     for (int i = 0; i < layer.numitems; i++)
     {
         listBoxItems.Items.Add(layer.getItem(i));
     }
     layer.close();
     buttonOK.Enabled = false;
 }
Beispiel #3
0
        public static void TestMSSQLConnection(string connection, string data)
        {
            mapObj   samplemap   = new mapObj(null);
            layerObj samplelayer = new layerObj(samplemap);

            samplelayer.connectiontype = MS_CONNECTION_TYPE.MS_PLUGIN;
            samplelayer.plugin_library = samplelayer.plugin_library_original = "msplugin_mssql2008.dll";

            samplelayer.connection = connection;
            samplelayer.data       = data;
            try
            {
                samplelayer.open();
            }
            finally
            {
                samplelayer.close();
            }
        }
        /// <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)));
        }
    public static void Main(string[] args)
    {
        if (args.Length < 2) usage();

          // creating a new map from scratch
          mapObj map = new mapObj(null);
          // adding a layer
          layerObj layer = new layerObj(map);
          layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
          layer.status = mapscript.MS_ON;
          layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
          // define the attribute names from the inline layer
          layer.addProcessing("ITEMS=attribute1,attribute2,attribute3");
          // define the class
          classObj classobj = new classObj(layer);
          classobj.template = "query";   // making the layer queryable
          // setting up the text based on multiple attributes
          classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')");
          // define the label
          classobj.label.outlinecolor = new colorObj(255, 255, 255, 0);
          classobj.label.force = mapscript.MS_TRUE;
          classobj.label.size = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
          classobj.label.position = (int)MS_POSITIONS_ENUM.MS_LC;
          classobj.label.wrap = ' ';
          // set up attribute binding
          classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2");
          // define the style
          styleObj style = new styleObj(classobj);
          style.color = new colorObj(0, 255, 255, 0);
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2");
          style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3");

          Random rand = new Random((int)DateTime.Now.ToFileTime()); ;

          // creating the shapes
          for (int i = 0; i < 10; i++)
          {
          shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);

          // setting the shape attributes
          shape.initValues(4);
          shape.setValue(0, Convert.ToString(i));
          shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex());
          shape.setValue(2, Convert.ToString(rand.Next(25) + 5));

          lineObj line = new lineObj();
          line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0));
          shape.add(line);
          layer.addFeature(shape);
          }

          map.width = 500;
          map.height = 500;
          map.setExtent(0,0,450,450);
          map.selectOutputFormat(args[0]);
          imageObj image = map.draw();
          image.save(args[1], map);

          //perform a query
          layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0));

          resultObj res;
          shapeObj feature;
          using (resultCacheObj results = layer.getResults())
          {
          if (results != null && results.numresults > 0)
          {
              // extracting the features found
              layer.open();
              for (int j = 0; j < results.numresults; j++)
              {
                  res = results.getResult(j);
                  feature = layer.getShape(res);
                  if (feature != null)
                  {
                      Console.WriteLine("  Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex);
                      for (int k = 0; k < layer.numitems; k++)
                      {
                          Console.Write("     " + layer.getItem(k));
                          Console.Write(" = ");
                          Console.Write(feature.getValue(k));
                          Console.WriteLine();
                      }
                  }
              }
              layer.close();
          }
          }
    }
Beispiel #6
0
        /// <summary>
        /// Create a default layer for creating a preview to another layer
        /// </summary>
        /// <param name="originalMap">The original map.</param>
        /// <param name="originalLayer">The original layer.</param>
        /// <returns>The created layer object.</returns>
        private layerObj InitializeDefaultLayer(mapObj originalMap, layerObj originalLayer)
        {
            // create a new map object
            map = new mapObj(null);
            map.units = MS_UNITS.MS_PIXELS;
            map.setExtent(0, 0, this.Width, this.Height);
            map.width = this.Width;
            map.height = this.Height;
            outputFormatObj format = originalMap.outputformat;
            if (map.getOutputFormatByName(format.name) == null)
                map.appendOutputFormat(format);
            map.selectOutputFormat(originalMap.imagetype);
            // copy symbolset
            for (int i = 1; i < originalMap.symbolset.numsymbols; i++)
            {
                symbolObj origsym = originalMap.symbolset.getSymbol(i);
                map.symbolset.appendSymbol(MapUtils.CloneSymbol(origsym));
            }
            // copy the fontset
            string key = null;
            while ((key = originalMap.fontset.fonts.nextKey(key)) != null)
                map.fontset.fonts.set(key, originalMap.fontset.fonts.get(key, ""));
            // setting a default font
            //map.fontset.fonts.set("",
            //    originalMap.fontset.fonts.get(originalMap.fontset.fonts.nextKey(null),""));
            // insert a new layer
            layerObj layer = new layerObj(map);
            if (originalLayer != null)
            {
                // the chart type doesn't support having as single class in it
                if (originalLayer.type == MS_LAYER_TYPE.MS_LAYER_CHART)
                    layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                else
                    layer.type = originalLayer.type;
                originalLayer.open();
                // add the sample feature to the layer
                AddSampleFeature(layer, originalLayer.numitems);
                if (originalLayer.getResults() == null)
                    originalLayer.close(); // close only is no query results
            }
            else
            {
                layer.type = MS_LAYER_TYPE.MS_LAYER_ANNOTATION;
                // add the sample feature to the layer
                AddSampleFeature(layer, 0);
            }
            layer.status = mapscript.MS_ON;

            return layer;
        }
Beispiel #7
0
        public static void TestMSSQLConnection(string connection, string data)
        {
            mapObj samplemap = new mapObj(null);
            layerObj samplelayer = new layerObj(samplemap);
            samplelayer.connectiontype = MS_CONNECTION_TYPE.MS_PLUGIN;
            samplelayer.plugin_library = samplelayer.plugin_library_original = "msplugin_mssql2008.dll";

            samplelayer.connection = connection;
            samplelayer.data = data;
            try
            {
                samplelayer.open();
            }
            finally
            {
                samplelayer.close();
            }
        }
Beispiel #8
0
    public static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            usage();
        }

        // creating a new map from scratch
        mapObj map = new mapObj(null);
        // adding a layer
        layerObj layer = new layerObj(map);

        layer.type           = MS_LAYER_TYPE.MS_LAYER_POINT;
        layer.status         = mapscript.MS_ON;
        layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE;
        // define the attribute names from the inline layer
        layer.addProcessing("ITEMS=attribute1,attribute2,attribute3");
        // define the class
        classObj classobj = new classObj(layer);

        classobj.template = "query"; // making the layer queryable
        // setting up the text based on multiple attributes
        classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')");
        // define the label
        classobj.label.outlinecolor = new colorObj(255, 255, 255, 0);
        classobj.label.force        = mapscript.MS_TRUE;
        classobj.label.size         = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM;
        classobj.label.position     = (int)MS_POSITIONS_ENUM.MS_LC;
        classobj.label.wrap         = ' ';
        // set up attribute binding
        classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2");
        // define the style
        styleObj style = new styleObj(classobj);

        style.color = new colorObj(0, 255, 255, 0);
        style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2");
        style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3");

        Random rand = new Random((int)DateTime.Now.ToFileTime());;

        // creating the shapes
        for (int i = 0; i < 10; i++)
        {
            shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT);

            // setting the shape attributes
            shape.initValues(4);
            shape.setValue(0, Convert.ToString(i));
            shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex());
            shape.setValue(2, Convert.ToString(rand.Next(25) + 5));

            lineObj line = new lineObj();
            line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0));
            shape.add(line);
            layer.addFeature(shape);
        }

        map.width  = 500;
        map.height = 500;
        map.setExtent(0, 0, 450, 450);
        map.selectOutputFormat(args[0]);
        imageObj image = map.draw();

        image.save(args[1], map);

        //perform a query
        layer.queryByRect(map, new rectObj(0, 0, 450, 450, 0));

        resultObj res;
        shapeObj  feature;

        using (resultCacheObj results = layer.getResults())
        {
            if (results != null && results.numresults > 0)
            {
                // extracting the features found
                layer.open();
                for (int j = 0; j < results.numresults; j++)
                {
                    res     = results.getResult(j);
                    feature = layer.getShape(res);
                    if (feature != null)
                    {
                        Console.WriteLine("  Feature: shapeindex=" + res.shapeindex + " tileindex=" + res.tileindex);
                        for (int k = 0; k < layer.numitems; k++)
                        {
                            Console.Write("     " + layer.getItem(k));
                            Console.Write(" = ");
                            Console.Write(feature.getValue(k));
                            Console.WriteLine();
                        }
                    }
                }
                layer.close();
            }
        }
    }
Beispiel #9
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (layer == null)
            {
                return;
            }

            shapeObj shape;

            layer.open();

            // Get layer statistics
            maxvalue   = new double[layer.numitems];
            minvalue   = new double[layer.numitems];
            fieldName  = new string[layer.numitems];
            isNumber   = new bool[layer.numitems];
            isInteger  = new bool[layer.numitems];
            valueCount = new int[layer.numitems];
            int i;

            for (i = 0; i < layer.numitems; i++)
            {
                isNumber[i]   = true;
                isInteger[i]  = true;
                valueCount[i] = 0;
                fieldName[i]  = layer.getItem(i);
            }

            layer.whichShapes(layer.getExtent());

            NumberFormatInfo ni = new NumberFormatInfo();

            ni.NumberDecimalSeparator = ".";

            double val;

            while ((shape = layer.nextShape()) != null)
            {
                for (i = 0; i < layer.numitems; i++)
                {
                    if (isNumber[i])
                    {
                        string v = shape.getValue(i);
                        if (v != "" && Double.TryParse(v, NumberStyles.Any, ni, out val))
                        {
                            if (val % 1 != 0)
                            {
                                isInteger[i] = false;
                            }

                            if (valueCount[i] == 0)
                            {
                                maxvalue[i] = val;
                                minvalue[i] = val;
                            }
                            else
                            {
                                if (maxvalue[i] < val)
                                {
                                    maxvalue[i] = val;
                                }
                                if (minvalue[i] > val)
                                {
                                    minvalue[i] = val;
                                }
                            }
                            ++valueCount[i];
                        }
                        else
                        {
                            isNumber[i]  = false;
                            isInteger[i] = false;
                        }
                    }
                }
            }

            for (i = 0; i < layer.numitems; i++)
            {
                if (isNumber[i])
                {
                    comboBoxColumns.Items.Add(fieldName[i]);
                }
            }
            if (comboBoxColumns.Items.Count > 0)
            {
                comboBoxColumns.SelectedIndex = 0;
            }

            if (layer.getResults() == null)
            {
                layer.close(); // close only is no query results
            }
        }
Beispiel #10
0
        public override void InitializeBinding(MapObjectHolder target)
        {
            this.target = target;

            if (target.GetParent().GetParent().GetType() != typeof(layerObj))
            {
                this.Enabled = false;
                return;
            }

            layerObj layer = target.GetParent().GetParent();
            styleObj style = target;

            if (itemList == null)
            {
                itemList                       = new ComboBox();
                itemList.Width                 = targetControl.Width;
                itemList.Height                = targetControl.Height;
                itemList.Location              = targetControl.Location;
                itemList.DropDownStyle         = ComboBoxStyle.DropDownList;
                itemList.SelectedIndexChanged += new EventHandler(itemList_SelectedIndexChanged);
                targetControl.Parent.Controls.Add(itemList);
                itemList.BringToFront();
                Bitmap bmp = Resources.DataConnection;
                bmp.MakeTransparent(Color.Magenta);
                pbox          = new PictureBox();
                pbox.Image    = bmp;
                pbox.SizeMode = PictureBoxSizeMode.AutoSize;
                pbox.Location = new System.Drawing.Point(targetControl.Location.X + targetControl.Width + 2,
                                                         targetControl.Location.Y + (targetControl.Height - pbox.Image.Height) / 2);
                targetControl.Parent.Controls.Add(pbox);
                pbox.BringToFront();
            }

            BindingState = false;

            itemList.Items.Clear();
            layer.open();
            for (int i = 0; i < layer.numitems; i++)
            {
                itemList.Items.Add(layer.getItem(i));
            }
            if (layer.getResults() == null)
            {
                layer.close(); // close only is no query results
            }
            if (layer.connectiontype == MS_CONNECTION_TYPE.MS_OGR)
            {
                itemList.Items.Add("OGR:LabelFont");
                itemList.Items.Add("OGR:LabelSize");
                itemList.Items.Add("OGR:LabelText");
                itemList.Items.Add("OGR:LabelAngle");
                itemList.Items.Add("OGR:LabelFColor");
                itemList.Items.Add("OGR:LabelBColor");
                itemList.Items.Add("OGR:LabelPlacement");
                itemList.Items.Add("OGR:LabelAnchor");
                itemList.Items.Add("OGR:LabelDx");
                itemList.Items.Add("OGR:LabelDy");
                itemList.Items.Add("OGR:LabelPerp");
                itemList.Items.Add("OGR:LabelBold");
                itemList.Items.Add("OGR:LabelItalic");
                itemList.Items.Add("OGR:LabelUnderline");
                itemList.Items.Add("OGR:LabelPriority");
                itemList.Items.Add("OGR:LabelStrikeout");
                itemList.Items.Add("OGR:LabelStretch");
                itemList.Items.Add("OGR:LabelAdjHor");
                itemList.Items.Add("OGR:LabelAdjVert");
                itemList.Items.Add("OGR:LabelHColor");
                itemList.Items.Add("OGR:LabelOColor");
            }

            string binding = style.getBinding((int)styleBinding);

            if (binding != null)
            {
                itemList.SelectedItem = binding;
                BindingState          = true;
            }
            else
            {
                if (itemList.Items.Count > 0)
                {
                    itemList.SelectedIndex = 0;
                }
            }
        }