Ejemplo n.º 1
0
    static void doc_PrintPage(object sender, PrintPageEventArgs e)
    {
        // Create the output format
        outputFormatObj of = new outputFormatObj("CAIRO/WINGDIPRINT", "cairowinGDIPrint");

        map.appendOutputFormat(of);
        map.selectOutputFormat("cairowinGDIPrint");
        map.resolution = e.Graphics.DpiX;
        Console.WriteLine("map resolution = " + map.resolution.ToString() + "DPI  defresolution = " + map.defresolution.ToString() + " DPI");
        // Calculating the desired image size to cover the entire area;
        map.width  = Convert.ToInt32(e.PageBounds.Width * e.Graphics.DpiX / 100);
        map.height = Convert.ToInt32(e.PageBounds.Height * e.Graphics.DpiY / 100);

        Console.WriteLine("map size = " + map.width.ToString() + " * " + map.height.ToString() + " pixels");

        IntPtr hdc = e.Graphics.GetHdc();

        try
        {
            // Attach the device to the outputformat for drawing
            of.attachDevice(hdc);
            // Drawing directly to the GDI context
            using (imageObj image = map.draw()) { };
        }
        finally
        {
            of.attachDevice(IntPtr.Zero);
            e.Graphics.ReleaseHdc(hdc);
        }

        e.HasMorePages = false;
    }
Ejemplo n.º 2
0
    public static void Main(string[] args)
    {
        Console.WriteLine("");
        if (args.Length < 2)
        {
            usage();
        }

        mapObj map = new mapObj(args[0]);

        Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name);
        for (int i = 0; i < map.numlayers; i++)
        {
            Console.WriteLine("Layer [" + i + "] name: " + map.getLayer(i).name);
        }

        try
        {
            // Create the output format
            outputFormatObj of = new outputFormatObj("CAIRO/WINGDI", "cairowinGDI");
            map.appendOutputFormat(of);
            map.selectOutputFormat("cairowinGDI");

            Bitmap mapImage = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb);

            using (Graphics g = Graphics.FromImage(mapImage))
            {
                IntPtr hdc = g.GetHdc();
                try
                {
                    // Attach the device to the outputformat for drawing
                    of.attachDevice(hdc);
                    // Drawing directly to the GDI context
                    using (imageObj image = map.draw()) { };
                }
                finally
                {
                    of.attachDevice(IntPtr.Zero);
                    g.ReleaseHdc(hdc);
                }
            }

            mapImage.Save(args[1]);
        }
        catch (Exception ex)
        {
            Console.WriteLine("\nMessage ---\n{0}", ex.Message);
            Console.WriteLine(
                "\nHelpLink ---\n{0}", ex.HelpLink);
            Console.WriteLine("\nSource ---\n{0}", ex.Source);
            Console.WriteLine(
                "\nStackTrace ---\n{0}", ex.StackTrace);
            Console.WriteLine(
                "\nTargetSite ---\n{0}", ex.TargetSite);
        }
    }
Ejemplo n.º 3
0
  public static void Main(string[] args)
  {
    Console.WriteLine("");
	if (args.Length < 2) usage();
    
	mapObj map = new mapObj(args[0]);

    Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name);
    for (int i = 0; i < map.numlayers; i++) 
	{
        Console.WriteLine("Layer [" + i + "] name: " + map.getLayer(i).name);
	}

    try
    {
        // Create the output format
        outputFormatObj of = new outputFormatObj("CAIRO/WINGDI", "cairowinGDI");
        map.appendOutputFormat(of);
        map.selectOutputFormat("cairowinGDI");

        Bitmap mapImage = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb);

        using (Graphics g = Graphics.FromImage(mapImage))
        {
            IntPtr hdc = g.GetHdc();
            try
            {
                // Attach the device to the outputformat for drawing
                of.attachDevice(hdc);
                // Drawing directly to the GDI context
                using (imageObj image = map.draw()) { };
            }
            finally
            {
                of.attachDevice(IntPtr.Zero);
                g.ReleaseHdc(hdc);
            }
        }

        mapImage.Save(args[1]);
    } 
	catch (Exception ex) 
	{
                Console.WriteLine( "\nMessage ---\n{0}", ex.Message );
                Console.WriteLine( 
                    "\nHelpLink ---\n{0}", ex.HelpLink );
                Console.WriteLine( "\nSource ---\n{0}", ex.Source );
                Console.WriteLine( 
                    "\nStackTrace ---\n{0}", ex.StackTrace );
                Console.WriteLine( 
                    "\nTargetSite ---\n{0}", ex.TargetSite );	}	
  }
Ejemplo n.º 4
0
        /// <summary>
        /// Let the editor to update the modified values to the underlying object.
        /// </summary>
        public void UpdateValues()
        {
            if (map == null)
            {
                return;
            }

            if (dirtyFlag)
            {
                dirtyFlag = false;
                // general tab
                if (map.name != this.textBoxName.Text)
                {
                    map.name = this.textBoxName.Text;
                }
                if (map.shapepath != this.textBoxShapePath.Text)
                {
                    map.shapepath = this.textBoxShapePath.Text;
                }
                if (map.web.imagepath != this.textBoxImagepath.Text)
                {
                    map.web.imagepath = this.textBoxImagepath.Text;
                }
                if (map.fontset.filename != this.textBoxFontset.Text)
                {
                    if (this.textBoxFontset.Text != "" &&
                        File.Exists(this.textBoxFontset.Text))
                    {
                        map.setFontSet(this.textBoxFontset.Text);
                    }
                    else
                    {
                        map.setFontSet(null);
                    }
                }
                if (map.symbolset.filename != this.textBoxSymbolset.Text)
                {
                    if (this.textBoxSymbolset.Text != "" &&
                        File.Exists(this.textBoxSymbolset.Text))
                    {
                        try
                        {
                            map.setSymbolSet(this.textBoxSymbolset.Text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Invalid symbol file, " + ex.Message,
                                            "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            map.setSymbolSet(null);
                        }
                    }
                    else
                    {
                        map.setSymbolSet(null);
                    }
                }

                // image details tab
                this.colorPickerBackColor.ApplyTo(map.imagecolor);
                if (map.imagetype != comboBoxImageType.Text)
                {
                    map.selectOutputFormat(comboBoxImageType.Text);
                }

                map.resolution = Convert.ToDouble(this.textBoxResolution.Text);
                // coordinate space
                // need to recalculate the extent to point to the same visible area
                try
                {
                    // setting up the projection if it have been changed
                    if (map.getProjection() != this.textBoxProjection.Tag.ToString())
                    {
                        if (map.getProjection() != "" && this.textBoxProjection.Tag.ToString() != "" &&
                            map.extent.minx < map.extent.maxx && map.extent.miny < map.extent.maxy)
                        {
                            using (projectionObj oldProj = new projectionObj(map.getProjection()))
                            {
                                using (projectionObj newProj = new projectionObj(this.textBoxProjection.Tag.ToString()))
                                {
                                    using (rectObj rect = new rectObj(map.extent.minx, map.extent.miny, map.extent.maxx, map.extent.maxy, 0))
                                    {
                                        rect.project(oldProj, newProj);
                                        map.units = (MS_UNITS)this.comboBoxUnits.SelectedItem;
                                        if (rect.minx < rect.maxx && rect.miny < rect.maxy)
                                        {
                                            map.setExtent(rect.minx, rect.miny, rect.maxx, rect.maxy);
                                            dirtyFlagExtent = true;
                                            UpdateExtentValues();
                                        }
                                    }
                                }
                            }
                        }

                        if (this.textBoxProjection.Tag.ToString().Trim().StartsWith("+"))
                        {
                            map.setProjection(this.textBoxProjection.Tag.ToString());
                            map.setMetaData("coordsys_name", this.textBoxProjection.Text);
                        }
                        else
                        {
                            map.setProjection("+AUTO");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to set projection value, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (checkBoxTransparent.Checked)
                {
                    map.outputformat.transparent = mapscript.MS_TRUE;
                    if (map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGB)
                    {
                        map.outputformat.imagemode = (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA;
                    }
                }
                else
                {
                    map.outputformat.transparent = mapscript.MS_FALSE;
                    if (map.outputformat.imagemode == (int)MS_IMAGEMODE.MS_IMAGEMODE_RGBA)
                    {
                        map.outputformat.imagemode = (int)MS_IMAGEMODE.MS_IMAGEMODE_RGB;
                    }
                }

                if (target != null && !dirtyFlagExtent)
                {
                    target.RaisePropertyChanged(this);
                }
                SetDirty(false);
            }
            if (dirtyFlagExtent)
            {
                ApplyExtent();
                dirtyFlagExtent = false;
            }
        }
        /// <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)));
        }
Ejemplo n.º 6
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();
          }
          }
    }
Ejemplo n.º 7
0
        /// <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 = "";
                }
            }
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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();
            }
        }
    }
Ejemplo n.º 10
0
        /// <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)));
        }