示例#1
0
    public void testGetLayerObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj newLayer  = map.getLayer(1);
        layerObj reference = map.getLayer(1);

        assert(newLayer.refcount == 3, "testGetLayerObjDestroy precondition");
        //newLayer.Dispose(); // force the destruction needed for Mono on Windows
        newLayer = null;
        gc();
        assert(reference.refcount == 2, "testGetLayerObjDestroy");
    }
示例#2
0
        public static bool RenameDuplicatedNames(mapObj map)
        {
            bool hasDuplicate = false;

            for (int i = 0; i < map.numlayers; i++)
            {
                layerObj layer = map.getLayer(i);

                if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend")
                {
                    continue;
                }

                string originalName = layer.name;
                if (originalName == null)
                {
                    originalName = "layer";
                }
                layer.name = null;
                string versionedName = GetUniqueLayerName(map, originalName, 0);
                layer.name = originalName;
                if (originalName.Trim() != versionedName)
                {
                    hasDuplicate = true;
                    layer.name   = versionedName;
                }
            }
            return(hasDuplicate);
        }
示例#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
        {
        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 );	}
    }
示例#4
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);
        }
    }
示例#5
0
    public void testGetLayerObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj newLayer = map.getLayer(1);

        map = null;
        gc();
        assertNotNull(newLayer.map, "testGetLayerObj");
        assert(newLayer.refcount == 2, "testGetLayerObj refcount");
    }
示例#6
0
    public void testGetClassObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj newClass = layer.getClass(0);

        map = null; layer = null;
        gc();
        assertNotNull(newClass.layer, "testGetClassObj");
        assert(newClass.refcount == 2, "testGetClassObj refcount");
    }
示例#7
0
    public void testGetStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj style    = classobj.getStyle(0);

        map = null; layer = null; classobj = null;
        gc();
        assert(style.refcount == 2, "testGetStyleObj");
    }
示例#8
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
        {
            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);
        }
    }
示例#9
0
    public void testGetClassObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj newClass  = layer.getClass(0);
        classObj reference = layer.getClass(0);

        assert(newClass.refcount == 3, "testGetClassObjDestroy precondition");
        map = null; layer = null; newClass = null;
        gc();
        assert(reference.refcount == 2, "testGetClassObjDestroy");
    }
示例#10
0
    public void testLayerObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj newLayer  = new layerObj(map);
        layerObj reference = map.getLayer(map.numlayers - 1);

        assert(newLayer.refcount == 3, "testLayerObjDestroy precondition");
        newLayer.Dispose();         // force the destruction for Mono on Windows because of the constructor overload
        newLayer = null;
        gc();
        assert(reference.refcount == 2, "testLayerObjDestroy");
    }
示例#11
0
 public static void QueryByAttribute(string qstring, mapObj map, bool zoomToResults)
 {
     Console.WriteLine("\nPerforming QueryByAttribute:");
     try
     {
         layerObj layer;
         rectObj query_bounds = null;
         for (int i = 0; i < map.numlayers; i++)
         {
             layer = map.getLayer(i);
             if (layer.connection != null && IsLayerQueryable(layer))
             {
                 Console.WriteLine("Layer [" + i + "] name: " + layer.name);
                 BuildQuery(layer, qstring);
                 // zoom to the query results
                 using (resultCacheObj results = layer.getResults())
                 {
                     if (results != null && results.numresults > 0)
                     {
                         // calculating the extent of the results
                         if (query_bounds == null)
                             query_bounds = new rectObj(results.bounds.minx, results.bounds.miny,
                                 results.bounds.maxx, results.bounds.maxy,0);
                         else
                         {
                             if (results.bounds.minx < query_bounds.minx) query_bounds.minx = results.bounds.minx;
                             if (results.bounds.miny < query_bounds.miny) query_bounds.miny = results.bounds.miny;
                             if (results.bounds.maxx > query_bounds.maxx) query_bounds.maxx = results.bounds.maxx;
                             if (results.bounds.maxy > query_bounds.maxy) query_bounds.maxy = results.bounds.maxy;
                         }
                     }
                 }
             }
         }
         // setting the map extent to the result bounds
         if (query_bounds != null)
         {
             if (zoomToResults)
             {
                 map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
                 map.scaleExtent(1.2, 0, 0); // increasing the visible area
                 Console.WriteLine("Current map scale: 1:" + (int)map.scaledenom);
             }
         }
         else
             Console.WriteLine("The query returned 0 results ...");
     }
     catch (Exception e)
     {
         Console.WriteLine("QueryByAttribute: " + e.Message);
     }
 }
示例#12
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 );	}	
  }
示例#13
0
    public void testRemoveClassObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj newClass = new classObj(null);

        layer.insertClass(newClass, 0);
        layer.removeClass(0);

        map = null; layer = null;
        gc();
        assert(newClass.refcount == 1, "testRemoveClassObj");
    }
示例#14
0
    public void testClassObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj newClass  = new classObj(layer);
        classObj reference = layer.getClass(layer.numclasses - 1);

        assert(newClass.refcount == 3, "testClassObjDestroy precondition");
        newClass.Dispose();         // force the destruction for Mono on Windows because of the constructor overload
        map = null; layer = null; newClass = null;
        gc();
        assert(reference.refcount == 2, "testClassObjDestroy");
    }
示例#15
0
    public void testGetStyleObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj classobj  = layer.getClass(0);
        styleObj style     = classobj.getStyle(0);
        styleObj reference = classobj.getStyle(0);

        assert(style.refcount == 3, "testGetStyleObjDestroy precondition");
        map = null; layer = null; classobj = null; style = null;
        gc();
        assert(reference.refcount == 2, "testGetStyleObjDestroy");
    }
示例#16
0
    public void testInsertClassObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj newClass = new classObj(null);

        layer.insertClass(newClass, -1);

        assertNotNull(newClass.layer, "testInsertClassObj precondition");
        map = null; layer = null;
        gc();
        assertNotNull(newClass.layer, "testInsertClassObj");
        assert(newClass.refcount == 2, "testInsertClassObj refcount");
    }
示例#17
0
    public void testStyleObjDestroy()
    {
        mapObj   map       = new mapObj(mapfile);
        layerObj layer     = map.getLayer(1);
        classObj classobj  = layer.getClass(0);
        styleObj newStyle  = new styleObj(classobj);
        styleObj reference = classobj.getStyle(classobj.numstyles - 1);

        assert(newStyle.refcount == 3, "testStyleObjDestroy");
        newStyle.Dispose();         // force the destruction for Mono on Windows because of the constructor overload
        map = null; layer = null; classobj = null; newStyle = null;
        gc();
        assert(reference.refcount == 2, "testStyleObjDestroy");
    }
示例#18
0
    public void testRemoveStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj newStyle = new styleObj(null);

        classobj.insertStyle(newStyle, 0);
        classobj.removeStyle(0);

        map = null; layer = null; classobj = null;
        gc();
        assert(newStyle.refcount == 1, "testRemoveStyleObj");
    }
示例#19
0
    public void testInsertStyleObj()
    {
        mapObj   map      = new mapObj(mapfile);
        layerObj layer    = map.getLayer(1);
        classObj classobj = layer.getClass(0);
        styleObj newStyle = new styleObj(null);

        classobj.insertStyle(newStyle, -1);

        assert(newStyle.refcount == 2, "testInsertStyleObj precondition");
        map = null; layer = null; classobj = null;
        gc();
        assert(newStyle.refcount == 2, "testInsertStyleObj");
    }
示例#20
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
        {
        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 );	}
    }
示例#21
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);
        }
    }
示例#22
0
        /// <summary>
        /// Generates an unique layer name within a map
        /// </summary>
        /// <param name="map">The map object</param>
        /// <param name="desiredName">The desired layer name</param>
        /// <returns></returns>
        public static string GetUniqueLayerName(mapObj map, string desiredName, int version)
        {
            string versionedName = desiredName.Trim();

            if (version > 0)
            {
                versionedName += " (" + version + ")";
            }

            for (int i = 0; i < map.numlayers; i++)
            {
                layerObj layer = map.getLayer(i);
                if (layer.name != null && layer.name.Trim() == versionedName)
                {
                    string desiredBaseName = Regex.Match(versionedName, @"(.*(?=\s\(\d+\))|.*(?!\s\(\d+\)))").Value;
                    return(GetUniqueLayerName(map, desiredBaseName, version + 1));
                }
            }
            return(versionedName);
        }
    public static void Main(string[] args)
    {
        Console.WriteLine("");
        if (args.Length < 2)
        {
            usage();
        }

        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
        {
            PrintDocument doc = new PrintDocument();

            doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);

            // Specify the printer to use.
            doc.PrinterSettings.PrinterName = args[1];

            doc.Print();
        }
        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);
        }
    }
示例#24
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 );	}	
  }
示例#25
0
	public void testInsertStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,-1);
		
		assert(newStyle.refcount == 2, "testInsertStyleObj precondition");
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 2, "testInsertStyleObj");
	}
示例#26
0
	public void testInsertClassObj() {
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(null);
		layer.insertClass(newClass,-1);
		
		assertNotNull(newClass.layer, "testInsertClassObj precondition");
		map=null; layer=null;
		gc();
		assertNotNull(newClass.layer, "testInsertClassObj");
		assert(newClass.refcount == 2, "testInsertClassObj refcount");
	}
示例#27
0
	public void testRemoveClassObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(null);
		layer.insertClass(newClass,0);
		layer.removeClass(0);
		
		map=null; layer=null;
		gc();
		assert(newClass.refcount == 1, "testRemoveClassObj");
	}
示例#28
0
	public void testGetLayerObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=map.getLayer(1);
		layerObj reference = map.getLayer(1);
		
		assert(newLayer.refcount == 3, "testGetLayerObjDestroy precondition");
		//newLayer.Dispose(); // force the destruction needed for Mono on Windows
		newLayer=null;
		gc();
		assert(reference.refcount == 2, "testGetLayerObjDestroy");
	}
示例#29
0
	public void testClassObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(layer);
		classObj reference=layer.getClass(layer.numclasses-1);
		
		assert(newClass.refcount == 3, "testClassObjDestroy precondition");
		newClass.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		map=null; layer=null; newClass=null;
		gc();
		assert(reference.refcount == 2, "testClassObjDestroy");
	}
示例#30
0
	public void testInsertLayerObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=new layerObj(null);
		map.insertLayer(newLayer,0);
		layerObj reference = map.getLayer(0);

		assert(newLayer.refcount == 3, "testInsertLayerObjDestroy precondition");
		newLayer.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		newLayer=null;
		gc();
		assert(reference.refcount == 2, "testInsertLayerObjDestroy");
	}
示例#31
0
	public void testGetLayerObj() {
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=map.getLayer(1);
		
		map=null;
		gc();
		assertNotNull(newLayer.map, "testGetLayerObj");
		assert(newLayer.refcount == 2, "testGetLayerObj refcount");
	}
示例#32
0
	public void testGetClassObj() {
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=layer.getClass(0);
		
		map=null; layer=null;
		gc();
		assertNotNull(newClass.layer, "testGetClassObj");
		assert(newClass.refcount == 2, "testGetClassObj refcount");
	}
示例#33
0
        public static bool RenameDuplicatedNames(mapObj map)
        {
            bool hasDuplicate = false;
            for (int i = 0; i < map.numlayers; i++)
            {
                layerObj layer = map.getLayer(i);

                if (layer.name == "__embed__scalebar" || layer.name == "__embed__legend")
                    continue;

                string originalName = layer.name;
                if (originalName == null)
                    originalName = "layer";
                layer.name = null;
                string versionedName = GetUniqueLayerName(map, originalName, 0);
                layer.name = originalName;
                if (originalName.Trim() != versionedName)
                {
                    hasDuplicate = true;
                    layer.name = versionedName;
                }
            }
            return hasDuplicate;
        }
示例#34
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();
        }
示例#35
0
	public void testRemoveStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,0);
		classobj.removeStyle(0);
		
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 1, "testRemoveStyleObj");
	}
示例#36
0
        /// <summary>
        /// Validating event handler of the scintillaControlSymbolset control.
        /// </summary>
        /// <param name="sender">The source object of this event.</param>
        /// <param name="layer">The selected layer.</param>
        private void scintillaControlSymbolset_Validating(object sender, CancelEventArgs e)
        {
            if (symbolsetChanged)
            {
                // validating
                string fileName = Path.GetTempFileName();
                try
                {
                    File.WriteAllText(fileName, scintillaControlSymbolset.Text);
                    // test whether we can parse the symbolset
                    symbolSetObj s = new symbolSetObj(fileName);
                    // make sure we have all symbol references
                    Hashtable symbolNames = new Hashtable();
                    for (int i = 0; i < s.numsymbols; i++)
                    {
                        string symbolName = s.getSymbol(i).name;
                        if (symbolName != null && !symbolNames.ContainsKey(symbolName))
                        {
                            symbolNames.Add(symbolName, symbolName);
                        }
                    }
                    mapObj map = StyleLibrary.Styles;
                    s = map.symbolset;
                    for (int i = 0; i < s.numsymbols; i++)
                    {
                        symbolObj sym        = s.getSymbol(i);
                        string    symbolName = sym.name;
                        if (symbolName != null && sym.inmapfile == mapscript.MS_TRUE && !symbolNames.ContainsKey(symbolName))
                        {
                            symbolNames.Add(symbolName, symbolName);
                        }
                    }

                    for (int i = 0; i < map.numlayers; i++)
                    {
                        layerObj layer = map.getLayer(i);
                        for (int j = 0; j < layer.numclasses; j++)
                        {
                            classObj classobj = layer.getClass(j);
                            for (int k = 0; k < classobj.numstyles; k++)
                            {
                                string symbolName = classobj.getStyle(k).symbolname;
                                if (symbolName != null && !symbolNames.ContainsKey(symbolName))
                                {
                                    throw new Exception("Symbol name '" + symbolName + "' is missing from the symbolset file!");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show(ex.Message + "\n\rPress OK to correct the errors or Cancel to ignore the changes!", "MapManager", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                    {
                        e.Cancel = true;
                    }
                    else
                    {
                        LoadSymbolset();
                    }

                    return;
                }
                finally
                {
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }

                // validation ok, ask whether to save or not
                DialogResult res = MessageBox.Show("Do you wish to save the modifications of the symbolset?", "MapManager", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (res == DialogResult.Yes)
                {
                    SaveSymbolset();
                    // the symbolset has changed, need to reload view
                    timerRefresh.Enabled = true;
                }
                else if (res == DialogResult.No)
                {
                    LoadSymbolset();
                }
                else if (res == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
        }
示例#37
0
        /// <summary>
        /// Refresh the controls according to the underlying object.
        /// </summary>
        public void RefreshView()
        {
            if (style == null)
            {
                return;
            }
            //STEPH: set first load flag to make sure values are not updated by listView_SelectedIndexChanged event
            firstLoad = true;
            checkBoxAntialias.Checked = (style.antialias == mapscript.MS_TRUE);

            if (style.size < 0) // set default size (#4339)
            {
                textBoxSize.Text = "8";
            }
            else
            {
                textBoxSize.Text = style.size.ToString();
            }
            styleBindingControllerSize.InitializeBinding(target);

            textBoxMinSize.Text = style.minsize.ToString();
            textBoxMaxSize.Text = style.maxsize.ToString();
            textBoxWidth.Text   = style.width.ToString();
            styleBindingControllerWidth.InitializeBinding(target);
            textBoxAngle.Text = style.angle.ToString();
            styleBindingControllerAngle.InitializeBinding(target);
            textBoxMinWidth.Text = style.minwidth.ToString();
            textBoxMaxWidth.Text = style.maxwidth.ToString();
            textBoxOffsetX.Text  = style.offsetx.ToString();
            textBoxOffsetY.Text  = style.offsety.ToString();

            this.colorPickerColor.SetColor(style.color);
            styleBindingControllerColor.InitializeBinding(target);
            this.colorPickerBackColor.SetColor(style.backgroundcolor);
            this.colorPickerOutlineColor.SetColor(style.outlinecolor);
            styleBindingControllerOutlineColor.InitializeBinding(target);
            trackBarOpacity.Value    = style.opacity;
            labelOpacityPercent.Text = trackBarOpacity.Value + "%";

            checkBoxAutoAngle.Checked = (style.autoangle == mapscript.MS_TRUE);

            comboBoxGeomTransform.Items.Clear();
            if (isLabelStyle)
            {
                comboBoxGeomTransform.Items.AddRange(new string[] { "labelpnt", "labelpoly" });
            }
            else
            {
                comboBoxGeomTransform.Items.AddRange(new string[] { "start", "end", "vertices", "bbox", "centroid" });
            }

            comboBoxGeomTransform.Text = style.getGeomTransform();
            textBoxGap.Text            = style.gap.ToString();

            textBoxPattern.Text = GetPattenString(style.pattern);

            if (style.minscaledenom >= 0)
            {
                textBoxMinZoom.Text = style.minscaledenom.ToString();
            }
            else
            {
                textBoxMinZoom.Text = "";
            }
            if (style.maxscaledenom >= 0)
            {
                textBoxMaxZoom.Text = style.maxscaledenom.ToString();
            }
            else
            {
                textBoxMaxZoom.Text = "";
            }

            // populate the category combo
            mapObj styles           = StyleLibrary.Styles;
            string selectedCategory = null;
            bool   isStyleSelected  = false;

            for (int i = styles.numlayers - 1; i > -1; i--)
            {
                layerObj stylelayer = styles.getLayer(i);
                if (isLabelStyle)
                {
                    // for label styles add polygon and point categories
                    if (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                        stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                    {
                        comboBoxCategory.Items.Add(stylelayer.name);
                    }
                    if (selectedCategory == null && ((stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON && style.getGeomTransform().Contains("labelpoly")) ||
                                                     (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT && style.getGeomTransform().Contains("labelpnt"))))
                    {
                        selectedCategory = stylelayer.name; // for label style select default
                    }
                }
                else if ((layer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                          layer.type == MS_LAYER_TYPE.MS_LAYER_CIRCLE) &&
                         (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POLYGON ||
                          stylelayer.type == MS_LAYER_TYPE.MS_LAYER_LINE))
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for polygon layers select default
                    }
                }
                else if (layer.type == MS_LAYER_TYPE.MS_LAYER_LINE &&
                         stylelayer.type == MS_LAYER_TYPE.MS_LAYER_LINE)
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for line layers select default
                    }
                }
                else if (stylelayer.type == MS_LAYER_TYPE.MS_LAYER_POINT)
                {
                    comboBoxCategory.Items.Add(stylelayer.name);
                    if (selectedCategory == null)
                    {
                        selectedCategory = stylelayer.name; // for point layers select default
                    }
                }

                // select the style
                if (style.symbolname != null)
                {
                    for (int c = 0; c < stylelayer.numclasses; c++)
                    {
                        classObj styleclass = stylelayer.getClass(c);
                        styleObj libstyle   = styleclass.getStyle(0);

                        if (style.symbolname == libstyle.symbolname)
                        {
                            selectedCategory = stylelayer.name;
                            isStyleSelected  = true;
                            break;
                        }
                    }
                }
            }
            // check if we have inline symbols added to the map file
            bool inlineAdded = false;

            for (int i = 0; i < map.symbolset.numsymbols; i++)
            {
                symbolObj symbol = map.symbolset.getSymbol(i);
                if (symbol.inmapfile == mapscript.MS_TRUE &&
                    !StyleLibrary.HasSymbol(symbol.name))
                {
                    if (!inlineAdded)
                    {
                        comboBoxCategory.Items.Add("Inline Symbols");
                        inlineAdded = true;
                    }
                    if (!isStyleSelected && style.symbolname == symbol.name)
                    {
                        selectedCategory = "Inline Symbols";
                    }
                }
            }

            if (selectedCategory != null)
            {
                comboBoxCategory.SelectedItem = selectedCategory;
            }
            else if (comboBoxCategory.Items.Count > 0)
            {
                comboBoxCategory.SelectedIndex = 0;
            }

            SetDirty(false);
        }
示例#38
0
	public void testGetStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj style=classobj.getStyle(0);
		
		map=null; layer=null; classobj=null;
		gc();
		assert(style.refcount == 2, "testGetStyleObj");
	}
示例#39
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 = "";
                }
            }
        }
示例#40
0
        /// <summary>
        /// Generates an unique layer name within a map
        /// </summary>
        /// <param name="map">The map object</param>
        /// <param name="desiredName">The desired layer name</param>
        /// <returns></returns>
        public static string GetUniqueLayerName(mapObj map, string desiredName, int version)
        {
            string versionedName = desiredName.Trim();
            if (version > 0)
                versionedName += " (" + version + ")";

            for (int i = 0; i < map.numlayers; i++)
            {
                layerObj layer = map.getLayer(i);
                if (layer.name != null && layer.name.Trim() == versionedName)
                {
                    string desiredBaseName = Regex.Match(versionedName, @"(.*(?=\s\(\d+\))|.*(?!\s\(\d+\)))").Value;
                    return GetUniqueLayerName(map, desiredBaseName, version + 1);
                }
            }
            return versionedName;
        }
示例#41
0
	public void testInsertStyleObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,0);
		styleObj reference = classobj.getStyle(0);
		
		assert(newStyle.refcount == 3, "testInsertStyleObjDestroy precondition");
		newStyle.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		map=null; layer=null; classobj=null; newStyle=null;
		gc();
		assert(reference.refcount == 2, "testInsertStyleObjDestroy");
	}
示例#42
0
 public static void QueryByAttribute(string qstring, mapObj map, bool zoomToResults)
 {
     Console.WriteLine("\nPerforming QueryByAttribute:");
     try
     {
         layerObj layer;
         rectObj  query_bounds = null;
         for (int i = 0; i < map.numlayers; i++)
         {
             layer = map.getLayer(i);
             if (layer.connection != null && IsLayerQueryable(layer))
             {
                 Console.WriteLine("Layer [" + i + "] name: " + layer.name);
                 BuildQuery(layer, qstring);
                 // zoom to the query results
                 using (resultCacheObj results = layer.getResults())
                 {
                     if (results != null && results.numresults > 0)
                     {
                         // calculating the extent of the results
                         if (query_bounds == null)
                         {
                             query_bounds = new rectObj(results.bounds.minx, results.bounds.miny,
                                                        results.bounds.maxx, results.bounds.maxy, 0);
                         }
                         else
                         {
                             if (results.bounds.minx < query_bounds.minx)
                             {
                                 query_bounds.minx = results.bounds.minx;
                             }
                             if (results.bounds.miny < query_bounds.miny)
                             {
                                 query_bounds.miny = results.bounds.miny;
                             }
                             if (results.bounds.maxx > query_bounds.maxx)
                             {
                                 query_bounds.maxx = results.bounds.maxx;
                             }
                             if (results.bounds.maxy > query_bounds.maxy)
                             {
                                 query_bounds.maxy = results.bounds.maxy;
                             }
                         }
                     }
                 }
             }
         }
         // setting the map extent to the result bounds
         if (query_bounds != null)
         {
             if (zoomToResults)
             {
                 map.setExtent(query_bounds.minx, query_bounds.miny, query_bounds.maxx, query_bounds.maxy);
                 map.scaleExtent(1.2, 0, 0);                     // increasing the visible area
                 Console.WriteLine("Current map scale: 1:" + (int)map.scaledenom);
             }
         }
         else
         {
             Console.WriteLine("The query returned 0 results ...");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("QueryByAttribute: " + e.Message);
     }
 }
示例#43
0
	public void testGetClassObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=layer.getClass(0);
		classObj reference = layer.getClass(0);
		
		assert(newClass.refcount == 3, "testGetClassObjDestroy precondition");
		map=null; layer=null; newClass=null;
		gc();
		assert(reference.refcount == 2, "testGetClassObjDestroy");
	}
示例#44
0
        public static void ExpandFontStyles()
        {
            string        symbolSetFileContents = File.ReadAllText(symbolsetFileName);
            string        fontSetFileContents   = File.ReadAllText(fontsetFileName);
            StringBuilder newSymbols            = new StringBuilder();
            StringBuilder newFonts = new StringBuilder();

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

                            if (!symbolSetFileContents.Contains(symbolname))
                            {
                                symbolObj sym = new symbolObj(symbolname, null);
                                sym.character = "&#" + c.ToString() + ";";
                                sym.antialias = mapscript.MS_TRUE;
                                sym.type      = (int)MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE;
                                sym.font      = classobj.name;
                                sym.inmapfile = 0;
                                map.symbolset.appendSymbol(sym);
                                newSymbols.Append(String.Format("SYMBOL{0}  NAME \"{1}\"{0}  TYPE TRUETYPE{0}  ANTIALIAS TRUE{0}  CHARACTER \"{2}\"{0}  FONT \"{3}\"{0}END{0}", Environment.NewLine, symbolname, sym.character, sym.font));
                            }
                            if (c > 33)
                            {
                                // the first class is already inserted
                                classObj class2 = classobj.clone();
                                class2.name = symbolname;
                                styleObj style2 = class2.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                                layer.insertClass(class2, -1);
                            }
                            else
                            {
                                styleObj style2 = classobj.getStyle(0);
                                style2.setSymbolByName(map, symbolname);
                            }
                        }
                        if (!classobj.name.EndsWith("-33"))
                        {
                            classobj.name += "-33";
                        }
                    }
                    layer.removeMetaData("character-count");
                }
            }
            if (newSymbols.Length > 0)
            {
                // writing the new symbols to the symbolset file
                int lastpos = symbolSetFileContents.LastIndexOf("END", StringComparison.InvariantCultureIgnoreCase);
                symbolSetFileContents = symbolSetFileContents.Substring(0, lastpos) + newSymbols.ToString() + "END";
                File.WriteAllText(symbolsetFileName, symbolSetFileContents);
            }
            if (newFonts.Length > 0)
            {
                // writing the new fonts to the fontset file
                File.WriteAllText(fontsetFileName, fontSetFileContents + newFonts.ToString());
            }
        }
示例#45
0
	public void testGetStyleObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj style=classobj.getStyle(0);
		styleObj reference=classobj.getStyle(0);
		
		assert(style.refcount == 3, "testGetStyleObjDestroy precondition");
		map=null; layer=null; classobj=null; style=null;
		gc();
		assert(reference.refcount == 2, "testGetStyleObjDestroy");
	}
示例#46
0
        /// <summary>
        /// Add the layers of an entire mapfile
        /// </summary>
        /// <param name="mapfile">Path to the mapfile should be opened</param>
        private void AddMapFileLayers(string mapfile)
        {
            try
            {
                layerObj currentLayer = null;
                if (CurrentTree.SelectedNode != null)
                {
                    MapObjectHolder selected = (MapObjectHolder)CurrentTree.SelectedNode.Tag;
                    if (selected.GetType() == typeof(layerObj))
                        currentLayer = selected;
                    else if (selected.GetType() == typeof(classObj))
                        currentLayer = selected.GetParent();
                    else if (selected.GetType() == typeof(styleObj))
                        currentLayer = selected.GetParent().GetParent();
                    else if (selected.GetType() == typeof(labelObj))
                        currentLayer = selected.GetParent().GetParent();
                }

                mapObj map2 = new mapObj(mapfile);
                for (int i = 0; i < map2.numlayers; i++)
                {

                    layerObj layer = map2.getLayer(i).clone();
                    layer.status = mapscript.MS_OFF;
                    if (currentLayer != null)
                    {
                        if (currentLayer.index < map.numlayers -1)
                            map.insertLayer(layer, currentLayer.index + 1);
                        else
                            map.insertLayer(layer, -1);

                        currentLayer = layer;
                    }
                    else
                    {
                        map.insertLayer(layer, -1);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#47
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());
        }
示例#48
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);
        }
    }
  public static void Main(string[] args)
  {
    Console.WriteLine("");
	if (args.Length < 2) usage();
    
	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
    {
        PrintDocument doc = new PrintDocument();

        doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);

        // Specify the printer to use.
        doc.PrinterSettings.PrinterName = args[1];

        doc.Print();
    } 
    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 );	}	
    }