Exemple #1
0
        /// <summary>
        /// Update the preview according to the changes
        /// </summary>
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                               map, layer, pictureBoxPreview.Width, pictureBoxPreview.Height))
                    {
                        styleclass.drawLegendIcon(map, layer,
                                                  pictureBoxPreview.Width - 10, pictureBoxPreview.Height - 10, image2, 4, 4);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxPreview.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            else
            {
                pictureBoxPreview.Image = null;
            }
        }
    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;
    }
        /// <summary>
        /// Update the list item according to a modified style
        /// </summary>
        /// <param name="index">the index of the lit item</param>
        /// <param name="style">the style object</param>
        private void UpdateStyleInList(int index)
        {
            layerObj layer;

            if (target.GetParent().GetType() == typeof(scalebarObj))
            {
                layer = new layerObj(null);
            }
            else
            {
                layer = target.GetParent().GetParent();
            }

            ListViewItem item  = listViewStyles.Items[index];
            styleObj     style = (styleObj)item.Tag;

            classObj styleclass = new classObj(null);

            styleclass.insertStyle(style, -1);
            // creating the list icon
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(map, layer, 30, 20))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        // modify the layer type in certain cases for drawing correct images
                        string geomtransform = style.getGeomTransform().ToLower();
                        if (geomtransform != null)
                        {
                            if (geomtransform.Contains("labelpoly"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            }
                            else if (geomtransform.Contains("labelpnt"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                            }
                        }
                        styleclass.drawLegendIcon(map, layer, 20, 10, image2, 5, 5);
                    }
                    finally
                    {
                        layer.type = type;
                    }

                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images[item.ImageIndex] = Image.FromStream(ms);
                    }


                    item.SubItems[1].Text = style.size.ToString();
                    item.SubItems[2].Text = style.width.ToString();
                    item.SubItems[3].Text = style.symbolname;
                }
            }
        }
Exemple #4
0
    public static void Main(string[] args)
    {
        Console.WriteLine("");
        if (args.Length < 3 || args.Length > 4)
        {
            usage();
        }

        bool ZoomToResults = (args.Length == 4 && args[3] == "-zoom");

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

        Console.WriteLine("# Map layers " + map.numlayers + "; Map name = " + map.name);

        QueryByAttribute(args[1], map, ZoomToResults);

        map.querymap.status = mapscript.MS_ON;
        map.querymap.color.setRGB(0, 0, 255, 255);
        map.querymap.style = (int)MS_QUERYMAP_STYLES.MS_HILITE;

        try
        {
            imageObj image = map.drawQuery();
            image.save(args[2], map);
        }
        catch (Exception ex)
        {
            Console.WriteLine("QueryMap: ", ex.Message);
        }
    }
    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);
        }
    }
 internal static HandleRef getCPtrAndSetReference(imageObj obj, object parent) {
   if (obj != null)
   {
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
 internal static HandleRef getCPtrAndDisown(imageObj obj, object parent) {
   if (obj != null)
   {
     obj.swigCMemOwn = false;
     obj.swigParentRef = parent;
     return obj.swigCPtr;
   }
   else
   {
     return new HandleRef(null, IntPtr.Zero);
   }
 }
Exemple #8
0
    public void testimageObj()
    {
        mapObj          map    = new mapObj(mapfile);
        imageObj        image  = map.draw();
        outputFormatObj format = image.format;

        format.setOption("INTERLACE", "OFF");

        map = null;
        gc();
        assert(format.getOption("INTERLACE", "") == "OFF", "testimageObj");
    }
    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
        {
            Bitmap    mapImage  = new Bitmap(map.width, map.height, PixelFormat.Format32bppRgb);
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            using (imageObj image = map.draw())
            {
                BitmapData bitmapData = mapImage.LockBits(new Rectangle(0, 0, image.width, image.height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
                try
                {
                    if (image.getRawPixels(bitmapData.Scan0) == (int)MS_RETURN_VALUE.MS_FAILURE)
                    {
                        Console.WriteLine("Unable to get image contents");
                    }
                }
                finally
                {
                    mapImage.UnlockBits(bitmapData);
                }

                Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

                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);
        }
    }
Exemple #10
0
        private ListViewItem AddListItem(styleObj classStyle, layerObj layer, string name)
        {
            ListViewItem item       = null;
            classObj     styleclass = new classObj(null);

            styleclass.insertStyle(classStyle, -1);
            mapObj map2 = map;

            if (layer.map != null)
            {
                map2 = layer.map;
            }
            // creating the listicons
            using (classObj def_class = new classObj(null)) // for drawing legend images
            {
                using (imageObj image2 = def_class.createLegendIcon(
                           map2, layer, imageList.ImageSize.Width, imageList.ImageSize.Height))
                {
                    MS_LAYER_TYPE type = layer.type;
                    try
                    {
                        //SETPH: actually we should not modify the type of the style(point line polygon) for the style category list, only for the preview
                        //// modify the layer type in certain cases for drawing correct images
                        //if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                        //layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                        //else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt"))
                        //layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;

                        styleclass.drawLegendIcon(map2, layer, 44, 44, image2, 2, 2);
                    }
                    finally
                    {
                        layer.type = type;
                    }
                    byte[] img = image2.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        imageList.Images.Add(Image.FromStream(ms));
                    }

                    // add new item
                    item             = new ListViewItem(name, imageList.Images.Count - 1);
                    item.ToolTipText = name;
                    item.Tag         = classStyle;
                    listView.Items.Add(item);
                }
            }
            return(item);
        }
Exemple #11
0
    public static void Main(string[] args)
    {
        Console.WriteLine("");
        if (args.Length < 2)
        {
            usage();
        }

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

        if (args.Length >= 3)
        {
            Console.WriteLine("Setting the imagetype to " + args[2]);
            m_obj.setImageType(args[2]);
        }

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

        imageObj i_obj = m_obj.draw();

        Console.WriteLine("Image URL = " + i_obj.imageurl + "; Image path = " + i_obj.imagepath);
        Console.WriteLine("Image height = " + i_obj.height + "; width = " + i_obj.width);
        try
        {
            i_obj.save(args[1], m_obj);
        }
        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);
        }
    }
Exemple #12
0
    public static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            usage();
        }

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

            using (imageObj image = map.draw())
            {
                // solution 1
                Console.WriteLine("Drawing map: '" + map.name + "' using imageObj.getBytes");

                byte[] img = image.getBytes();
                using (MemoryStream ms = new MemoryStream(img))
                {
                    Image mapimage = Image.FromStream(ms);
                    mapimage.Save(args[1]);
                }

                // solution 2
                Console.WriteLine("Drawing map: '" + map.name + "' using imageObj.write");

                using (FileStream fs = File.Open("_" + args[1], FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    image.write(fs);
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("GetBytes: ", ex.Message);
        }
    }
Exemple #13
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 = "";
                }
            }
        }
 public int setImage(imageObj image) {
   int ret = mapscriptPINVOKE.symbolObj_setImage(swigCPtr, imageObj.getCPtr(image));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Exemple #15
0
        private void GenerateTile(double startX, double startY, double initTileGap, int imageSize, int imageBuffer, string savePath, int z, int x, int y, string imageFormat)
        {
            try
            {
                // active map variable
                map.setSize(imageSize + (imageBuffer * 2), imageSize + (imageBuffer * 2));

                // 0/0/0 tile variables
                double startPointX = startX;
                double startPointY = startY;
                double initGap     = initTileGap; // inital distance between tiles, for level 0 is max meters - min meters

                // meta-buffer to fix labeling as a multiplier
                double buffer = 1 + ((double)imageBuffer / (double)imageSize);

                // find the spacing between each tile for level
                double gap = (initGap / Math.Pow(2, z));

                // buffer in meters for each level
                double buffermeters = (gap * buffer) - gap;

                // set map extents for tile x values
                map.extent.minx = (startPointX + (gap * x)) - buffermeters;
                map.extent.maxx = (startPointX + (gap * x) + gap) + buffermeters;

                // set map extents for tile y values
                map.extent.miny = (startPointY + (gap * y)) - buffermeters;
                map.extent.maxy = (startPointY + (gap * y) + gap) + buffermeters;

                // generate map image
                using (imageObj image = map.draw())
                {
                    Image mapImage;

                    byte[] img = image.getBytes();
                    using (MemoryStream ms = new MemoryStream(img))
                    {
                        mapImage = Image.FromStream(ms);
                        ms.Flush();

                        // clip buffer area off generated image
                        if (!(buffer == 0))
                        {
                            Rectangle cropRect = new Rectangle(imageBuffer, imageBuffer, imageSize, imageSize);
                            Bitmap    bmpImage = new Bitmap(mapImage);
                            Bitmap    bmpCrop  = bmpImage.Clone(cropRect, bmpImage.PixelFormat);
                            mapImage = (Image)(bmpCrop);
                        }

                        // save image to disk in TMS format location
                        System.IO.Directory.CreateDirectory(savePath + "\\" + z + "\\" + x);
                        if (imageFormat == "png")
                        {
                            mapImage.Save(savePath + "\\" + z + "\\" + x + "\\" + y + "." + imageFormat, ImageFormat.Png);
                        }
                        if (imageFormat == "jpg")
                        {
                            mapImage.Save(savePath + "\\" + z + "\\" + x + "\\" + y + "." + imageFormat, ImageFormat.Jpeg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionDump(ex);
            }
        }
Exemple #16
0
        /// <summary>
        /// Update the Sample image according to the selected element
        /// </summary>
        /// <param name="target">Selected element</param>
        private void UpdateSample(MapObjectHolder target)
        {
            layerObj layer    = null;
            mapObj   map      = null;
            classObj classobj = null;

            if (target.GetType() == typeof(layerObj))
            {
                layer    = target;
                map      = layer.map;
                classobj = layer.getClass(0);
            }
            else if (target.GetType() == typeof(classObj))
            {
                classobj = target;
                if (classobj != null)
                {
                    layer = classobj.layer;
                }
                if (layer != null)
                {
                    map = layer.map;
                }
            }
            if (map == null || layer == null || classobj == null)
            {
                pictureBoxSample.Image = null;
                return;
            }

            styleObj style = classobj.getStyle(0);
            double   size  = style.size;

            // collect all fonts specified in the fontset file
            Hashtable fonts = new Hashtable();
            string    key   = null;

            while ((key = this.map.fontset.fonts.nextKey(key)) != null)
            {
                fonts.Add(key, key);
            }
            textBoxInfo.Text = "";
            if (style.symbol >= 0)
            {
                string font = ((mapObj)StyleLibrary.Styles).symbolset.getSymbol(style.symbol).font;
                if (font != null && !fonts.ContainsKey(font))
                {
                    textBoxInfo.Text = "WARNING: The fontset of the map doesn't contain " + font + " font. This symbol will not be selectable on the map.";
                }
            }

            if (layer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
            {
                // apply magnification for point styles
                style.size = size * trackBarMagnify.Value / 4;
            }

            try
            {
                using (classObj def_class = new classObj(null)) // for drawing legend image
                {
                    using (imageObj image2 = def_class.createLegendIcon(map, layer,
                                                                        pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        classobj.drawLegendIcon(map, layer,
                                                pictureBoxSample.Width, pictureBoxSample.Height, image2, 5, 5);
                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
            finally
            {
                style.size = size;
            }
        }
 public int draw(mapObj map, layerObj layer, imageObj image) {
   int ret = mapscriptPINVOKE.shapeObj_draw(swigCPtr, mapObj.getCPtr(map), layerObj.getCPtr(layer), imageObj.getCPtr(image));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public static int msSaveImage(mapObj map, imageObj img, string filename) {
   int ret = mapscriptPINVOKE.msSaveImage(mapObj.getCPtr(map), imageObj.getCPtr(img), filename);
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public static void msFreeImage(imageObj img) {
   mapscriptPINVOKE.msFreeImage(imageObj.getCPtr(img));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
 }
 internal static HandleRef getCPtr(imageObj obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Exemple #21
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();
            }
        }
    }
 public int drawLegendIcon(mapObj map, layerObj layer, int width, int height, imageObj dstImage, int dstX, int dstY) {
   int ret = mapscriptPINVOKE.classObj_drawLegendIcon(swigCPtr, mapObj.getCPtr(map), layerObj.getCPtr(layer), width, height, imageObj.getCPtr(dstImage), dstX, dstY);
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public int draw(mapObj map, layerObj layer, imageObj image, int classindex, string text) {
   int ret = mapscriptPINVOKE.rectObj_draw(swigCPtr, mapObj.getCPtr(map), layerObj.getCPtr(layer), imageObj.getCPtr(image), classindex, text);
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Exemple #24
0
        private void UpdatePreview()
        {
            if (style != null && enablePreview)
            {
                styleObj pstyle = style.clone();
                Update(pstyle);

                // apply current settings (opacity) to colors
                colorPickerColor.SetColor(pstyle.color);
                colorPickerBackColor.SetColor(pstyle.backgroundcolor);
                colorPickerOutlineColor.SetColor(pstyle.outlinecolor);

                // select the proper map containing symbols
                mapObj stylemap = map;
                if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Text != "Default")
                {
                    if (comboBoxCategory.Text != "Inline Symbols")
                    {
                        stylemap = StyleLibrary.Styles;
                    }
                    styleObj classStyle = (styleObj)listView.SelectedItems[0].Tag;
                    pstyle.setSymbolByName(stylemap, classStyle.symbolname);
                }
                else
                {
                    pstyle.symbol     = 0;
                    pstyle.symbolname = null;
                }

                classObj styleclass = new classObj(null);
                styleclass.insertStyle(pstyle, -1);

                using (classObj def_class = new classObj(null)) // for drawing legend images
                {
                    using (imageObj image2 = def_class.createLegendIcon(
                               stylemap, layer, pictureBoxSample.Width, pictureBoxSample.Height))
                    {
                        MS_LAYER_TYPE type = layer.type;
                        try
                        {
                            // modify the layer type in certain cases for drawing correct images
                            if (comboBoxGeomTransform.Text.ToLower().Contains("labelpoly"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                            }
                            else if (comboBoxGeomTransform.Text.ToLower().Contains("labelpnt") || comboBoxGeomTransform.Text.ToLower().Contains("centroid"))
                            {
                                layer.type = MS_LAYER_TYPE.MS_LAYER_POINT;
                            }

                            styleclass.drawLegendIcon(stylemap, layer,
                                                      pictureBoxSample.Width - 10, pictureBoxSample.Height - 10, image2, 4, 4);
                        }
                        finally
                        {
                            layer.type = type;
                        }

                        byte[] img = image2.getBytes();
                        using (MemoryStream ms = new MemoryStream(img))
                        {
                            pictureBoxSample.Image = Image.FromStream(ms);
                        }
                    }
                }
            }
        }
 public int drawLabelCache(imageObj image) {
   int ret = mapscriptPINVOKE.mapObj_drawLabelCache(swigCPtr, imageObj.getCPtr(image));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
 public int embedLegend(imageObj image) {
   int ret = mapscriptPINVOKE.mapObj_embedLegend(swigCPtr, imageObj.getCPtr(image));
   if (mapscriptPINVOKE.SWIGPendingException.Pending) throw mapscriptPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
Exemple #27
0
        /// <summary>
        /// Export a legend image with specific requirements (bug 1015)
        /// </summary>
        /// <param name="map">The map object</param>
        /// <param name="width">The desired legend width</param>
        /// <param name="height">The desired legend height</param>
        /// <returns></returns>
        public static byte[] ExportLegend(mapObj map)
        {
            int      width  = 10;
            int      height = 10;
            Bitmap   bmp    = null;
            Graphics g      = null;

            for (int phase = 0; phase < 2; phase++)
            {
                if (phase == 0)
                {
                    bmp = new Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                }
                else
                {
                    bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                }

                g = Graphics.FromImage(bmp);

                Stack groupPositions = new Stack();              // for storing the group text positions

                Font legendFont = new Font("MS Sans Sherif", 8); // set default font

                g.Clear(Color.White);                            // clear the background

                int xPos    = 5;                                 // padding
                int yPos    = 5;
                int xOffset = 24;                                // legend indent in pixels
                int yOffset = 18;                                // item height in pixels

                // force the recalculation of the current scale
                map.setExtent(map.extent.minx, map.extent.miny, map.extent.maxx, map.extent.maxy);

                // start drawing the legend in reverse layer order
                using (intarray ar = map.getLayersDrawingOrder())
                {
                    for (int i = map.numlayers - 1; i >= 0; i--)
                    {
                        layerObj layer = map.getLayer(ar.getitem(i));

                        if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend" ||
                            layer.status == mapscript.MS_OFF || layer.name.StartsWith("~"))
                        {
                            continue;
                        }


                        if (map.scaledenom > 0)
                        {
                            if (layer.maxscaledenom > 0 && map.scaledenom > layer.maxscaledenom)
                            {
                                continue;
                            }
                            if (layer.minscaledenom > 0 && map.scaledenom <= layer.minscaledenom)
                            {
                                continue;
                            }
                        }

                        if (layer.maxscaledenom <= 0 && layer.minscaledenom <= 0)
                        {
                            if (layer.maxgeowidth > 0 && ((map.extent.maxx - map.extent.minx) > layer.maxgeowidth))
                            {
                                continue;
                            }
                            if (layer.mingeowidth > 0 && ((map.extent.maxx - map.extent.minx) < layer.mingeowidth))
                            {
                                continue;
                            }
                        }

                        // draw raster or WMS layers
                        if (layer.type == MS_LAYER_TYPE.MS_LAYER_RASTER)
                        {
                            if (phase == 1)
                            {
                                g.DrawIcon(global::MapLibrary.Properties.Resources.raster, xPos, yPos);
                                g.DrawString(layer.name, legendFont, Brushes.Black, xPos + 30, yPos + 2);
                            }

                            SizeF size = g.MeasureString(layer.name, legendFont);
                            if (xPos + 30 + size.Width + 5 > width)
                            {
                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                            }

                            yPos += yOffset;
                            continue;
                        }

                        int    numClasses  = 0;
                        Image  legendImage = null;
                        string legendText  = null;

                        for (int j = 0; j < layer.numclasses; j++)
                        {
                            classObj layerclass = layer.getClass(j);

                            if (layerclass.name == "EntireSelection" || layerclass.name == "CurrentSelection")
                            {
                                continue;
                            }

                            if (layerclass.status == mapscript.MS_OFF)
                            {
                                continue;
                            }

                            if (map.scaledenom > 0)
                            {  /* verify class scale here */
                                if (layerclass.maxscaledenom > 0 && (map.scaledenom > layerclass.maxscaledenom))
                                {
                                    continue;
                                }
                                if (layerclass.minscaledenom > 0 && (map.scaledenom <= layerclass.minscaledenom))
                                {
                                    continue;
                                }
                            }

                            if (numClasses == 1)
                            {
                                // draw subclasses
                                xPos += xOffset;

                                if (phase == 1)
                                {
                                    // drawing the first class item (same as the layer)
                                    g.DrawImage(legendImage, xPos, yPos);
                                    g.DrawString(legendText, legendFont,
                                                 Brushes.Black, xPos + 30, yPos + 2);
                                }

                                SizeF size = g.MeasureString(legendText, legendFont);
                                if (xPos + 30 + size.Width + 5 > width)
                                {
                                    width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                }

                                yPos += yOffset;
                            }

                            ++numClasses; // number of visible classes

                            // creating the treeicons
                            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
                                    layerclass.drawLegendIcon(map, layer, 20, 10, image, 5, 5);
                                    byte[] img = image.getBytes();
                                    using (MemoryStream ms = new MemoryStream(img))
                                    {
                                        legendImage = Image.FromStream(ms);
                                        legendText  = layerclass.name;

                                        if (phase == 1)
                                        {
                                            g.DrawImage(legendImage, xPos, yPos);
                                        }
                                        if (numClasses > 1)
                                        {
                                            // draw the class item
                                            if (phase == 1)
                                            {
                                                g.DrawString(layerclass.name, legendFont,
                                                             Brushes.Black, xPos + 30, yPos + 3);
                                            }

                                            SizeF size = g.MeasureString(layerclass.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                            {
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                            }
                                        }
                                        else
                                        {
                                            // draw the layer item
                                            if (phase == 1)
                                            {
                                                g.DrawString(layer.name, legendFont,
                                                             Brushes.Black, xPos + 30, yPos + 3);
                                            }

                                            SizeF size = g.MeasureString(layer.name, legendFont);
                                            if (xPos + 30 + size.Width + 5 > width)
                                            {
                                                width = Convert.ToInt32(xPos + 30 + size.Width + 5);
                                            }

                                            if (string.Compare(layer.styleitem, "AUTO", true) == 0)
                                            {
                                                yPos += yOffset;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            yPos += yOffset;
                        }

                        if (numClasses > 1)
                        {
                            xPos -= xOffset;
                        }
                    }
                }
                height = yPos + 5;
            }

            g.Flush();
            MemoryStream ms2 = new MemoryStream();

            bmp.Save(ms2, System.Drawing.Imaging.ImageFormat.Png);
            return(ms2.ToArray());
        }
Exemple #28
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
        {
            WriteableBitmap mapImage  = new WriteableBitmap(map.width, map.height, 96, 96, PixelFormats.Bgr32, null);
            Stopwatch       stopwatch = new Stopwatch();
            stopwatch.Start();
            using (imageObj image = map.draw())
            {
                // Reserve the back buffer for updates.
                mapImage.Lock();
                try
                {
                    if (image.getRawPixels(mapImage.BackBuffer) == (int)MS_RETURN_VALUE.MS_FAILURE)
                    {
                        Console.WriteLine("Unable to get image contents");
                    }
                    // Specify the area of the bitmap that changed.
                    mapImage.AddDirtyRect(new Int32Rect(0, 0, map.width, map.height));
                }
                finally
                {
                    // Release the back buffer and make it available for display.
                    mapImage.Unlock();
                }

                Console.WriteLine("Rendering time: " + stopwatch.ElapsedMilliseconds + "ms");

                // Save the bitmap into a file.
                using (FileStream stream = new FileStream(args[1], FileMode.Create))
                {
                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(mapImage));
                    encoder.Save(stream);
                }
            }
        }
        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);
        }
    }