コード例 #1
0
ファイル: WfsDeegreeSample.cs プロジェクト: lishxi/_SharpMap
    public static Map CreateMap()
    {
      const string getCapabilitiesURI = "http://192.168.25.120:8080/deegree-wfs/services";

      Map map = new SharpMap.Map(new Size(600, 600));
      map.MinimumZoom = 0.005;
      map.BackColor = Color.White;

      SharpMap.Layers.VectorLayer layer1 = new SharpMap.Layers.VectorLayer("Springs");

      WFS prov1 = new WFS(getCapabilitiesURI, "app1", "Springs", WFS.WFSVersionEnum.WFS1_1_0);

      prov1.QuickGeometries = false;
      // Important when connecting to an UMN MapServer
      prov1.GetFeatureGETRequest = true;
      // Ignore multi-geometries...
      prov1.MultiGeometries = false;

      layer1.DataSource = prov1;
      map.Layers.Add(layer1);

      map.ZoomToBox(new SharpMap.Geometries.BoundingBox(574290, 4275299, 702273, 4386402));
      
      return map;
    }
コード例 #2
0
        public void render2d(Project project, PictureBox picBox)
        {

            SharpMap.Map myMap = new SharpMap.Map();

            foreach (BuildLayer layer in project.getLayers())
            {
                Source source = layer.getSource();

                BoundingBox envelope = new BoundingBox(-1000.0, -1000.0, 1000.0, 1000.0);//TODO
                FeatureDataSet ds = new FeatureDataSet();
                source.DataSource.Open();
                source.DataSource.ExecuteIntersectionQuery(envelope, ds);
                source.DataSource.Close();

                FeatureDataTable features = (FeatureDataTable)ds.Tables[0];

                string label = "Trace test:\n";

                foreach (FeatureDataRow row in features)
                {
                    foreach (Object item in row.ItemArray)
                        label += " - " + item;
                    label += "\n";
                }

                setLabel(label);

                //Show map

                //Filters
                FilterGraph graph = project.getFilterGraph(source.getName());
                if (graph != null)
                {
                    foreach (FeatureFilter filter in graph.getFilters())
                    {
                        //aplicar filtro segun el tipo
                        Mogre.DefaultSceneManagerFactory dsmf = new DefaultSceneManagerFactory();
                        Mogre.SceneManager sm = dsmf.CreateInstance("scenemanager");
                        FilterEnv env = new FilterEnv(sm, "env");
                        foreach (MogreGis.Resource resource in project.getResources())
                        {
                            env.getSession().Resources.addResource(resource);
                        }
                        FeatureList list = Feature.DataTableToList(features);
                        filter.process(list, env);
                        //falta devolver la lista y procesarla ***************************************
                    }
                }

                SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer(layer.getName());
                myLayer.DataSource = source.DataSource;
                myMap.Layers.Add(myLayer);
            }

            myMap.Size = new Size(picBox.Width, picBox.Height);
            myMap.ZoomToExtents();
            picBox.Image = myMap.GetMap();
            this.map = myMap;
        }
コード例 #3
0
ファイル: Theming.cs プロジェクト: PedroMaitan/sharpmap
        public void TestSymbolSelectionTheming()
        {
            //Create a map
            SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360));

            //Create some random sample data
            SharpMap.Data.FeatureDataTable fdt =
                cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180),
                                                         cd.GetRandomOrdinates(80, -90, 90), null);

            //Add rotation column and fill with random rotation values
            fdt.Columns.Add("Symbol", typeof(System.Byte[]));
            foreach (SharpMap.Data.FeatureDataRow row in fdt.Rows)
                row["Symbol"] = RandomSymbol((int)System.Math.Floor(cd.RandomNumberGenerator.NextDouble() * 360d));

            //Create layer and datasource
            SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            //Create default style
            SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle();
            defaultStyle.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png");
            defaultStyle.SymbolScale = 0.5f;

            //Create theming class and apply to layer
            SymbolFromFeatureDataRowTheming srt = new SymbolFromFeatureDataRowTheming("Symbol", defaultStyle);
            vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol);

            map.Layers.Add(vl);
            map.ZoomToExtents();
            System.Drawing.Image mapImage = map.GetMap();
            mapImage.Save("SymbolFromFDR.bmp");
        }
コード例 #4
0
        public void TestListPointSymbolizer()
        {
            var fdt = TestData.CreatingData.CreatePointFeatureDataTableFromArrays(
                TestData.CreatingData.GetRandomOrdinates(50, -180, 180), TestData.CreatingData.GetRandomOrdinates(50, -90, 90), null);
            var geometryFeatureProvider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);
            var layer = new SharpMap.Layers.VectorLayer("randompoints", geometryFeatureProvider);
            var pps =
                SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(new System.Drawing.Pen(System.Drawing.Color.Red, 2),
                                                                    new System.Drawing.SolidBrush(
                                                                        System.Drawing.Color.DodgerBlue), 20);

            var cps = new SharpMap.Rendering.Symbolizer.CharacterPointSymbolizer
            {
                Halo = 1,
                HaloBrush = new System.Drawing.SolidBrush(System.Drawing.Color.WhiteSmoke),
                Foreground = new System.Drawing.SolidBrush(System.Drawing.Color.Black),
                Font = new System.Drawing.Font("Arial", 12),
                CharacterIndex = 65
            };

            var lps = new SharpMap.Rendering.Symbolizer.ListPointSymbolizer { pps, cps };

            layer.Style.PointSymbolizer = lps;
            var map = new SharpMap.Map(new System.Drawing.Size(720, 360));
            map.Layers.Add(layer);
            map.ZoomToExtents();
            map.GetMap().Save("ListPointSymbolizer1.bmp");
        }
コード例 #5
0
        public void TestCharacterPointSymbolizer()
        {
            var fdt = TestData.CreatingData.CreatePointFeatureDataTableFromArrays(
                TestData.CreatingData.GetRandomOrdinates(50, -180, 180), TestData.CreatingData.GetRandomOrdinates(50, -90, 90), null);
            var geometryFeatureProvider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);
            var layer = new SharpMap.Layers.VectorLayer("randompoints", geometryFeatureProvider);
            var cps  = new SharpMap.Rendering.Symbolizer.CharacterPointSymbolizer
                                              {
                                                  Halo = 1,
                                                  HaloBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Wheat),
                                                  //Font = new System.Drawing.Font("Arial", 12),
                                                  CharacterIndex = 0xcc,
                                              };
            layer.Style.PointSymbolizer = cps;
            var map = new SharpMap.Map(new System.Drawing.Size(720, 360));

            map.Layers.Add(layer);
            map.ZoomToExtents();
            map.GetMap().Save("CharacterPointSymbolizer1.bmp");

            cps.Rotation = -30;
            cps.Offset = new System.Drawing.PointF(4, 4);
            map.GetMap().Save("CharacterPointSymbolizer2.bmp");

            cps.Font = new System.Drawing.Font("Arial", 12);
            cps.Text = "ABC";
            cps.Offset = System.Drawing.PointF.Empty;
            cps.Rotation = -90;
            map.GetMap().Save("CharacterPointSymbolizer3.bmp");
        }
コード例 #6
0
ファイル: MainWindow.cs プロジェクト: PedroMaitan/sharpmap
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            try
            {
                GeoAPI.GeometryServiceProvider.Instance = new NtsGeometryServices();

                Build();

                Size mapSize = new Size(800, 500);
                myMap = new SharpMap.Map(mapSize);

                SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
                style.Outline = new Pen(Color.Green, 1);
                style.EnableOutline = true;
                SharpMap.Layers.VectorLayer layWorld = new SharpMap.Layers.VectorLayer("States");
                layWorld.DataSource =
                    new SharpMap.Data.Providers.ShapeFile(
                        @"data" + System.IO.Path.DirectorySeparatorChar + @"states.shp", true);
                layWorld.Style = style;

                myMap.Layers.Add(layWorld);
                myMap.MaximumZoom = 360;
                myMap.BackColor = Color.LightBlue;
                myMap.Center = new GeoAPI.Geometries.Coordinate(0, 0);
                myMap.Zoom = 360;

                Bitmap img = (Bitmap)myMap.GetMap();
                image3.Pixbuf = ImageToPixbuf(img);
            }
            catch (Exception ex)
            {
                label1.Text = ex.Message;
            }
        }
コード例 #7
0
ファイル: WfsGeusSample.cs プロジェクト: lishxi/_SharpMap
    public static Map InitializeMap()
    {
      const string getCapabilitiesURI = "http://steven:8080/eWaterWfsConnector/wfs";

      Map map = new SharpMap.Map(new System.Drawing.Size(600, 600));
      map.MinimumZoom = 0.005;
      map.BackColor = System.Drawing.Color.White;

      SharpMap.Layers.VectorLayer layer1 = new SharpMap.Layers.VectorLayer("test");
      
      WFS prov1 = new WFS(getCapabilitiesURI, "", "Well", WFS.WFSVersionEnum.WFS1_0_0);

      prov1.QuickGeometries = false;
      // Important when connecting to an UMN MapServer
      prov1.GetFeatureGETRequest = true;
      // Ignore multi-geometries...
      prov1.MultiGeometries = false;

      layer1.DataSource = prov1;
      map.Layers.Add(layer1);

      map.ZoomToBox(new SharpMap.Geometries.BoundingBox(574290, 4275299, 702273, 4386402));

      return map;
    }
コード例 #8
0
ファイル: Examples.cs プロジェクト: geobabbler/SharpMap
        public static void Example2()
        {
            var map = new SharpMap.Map(new Size(1280, 1084));

            SharpMap.Data.Providers.IProvider provider =
                new SharpMap.Data.Providers.ShapeFile(
                    @"C:\temp\Data\niedersachsen.shp\railways.shp");

            var style = new SharpMap.Styles.VectorStyle();
            style.Line.Brush = Brushes.White;
            style.Line.DashPattern = new float[] { 4f, 4f };
            style.Line.Width = 4;
            style.EnableOutline = true;
            style.Outline.Brush = Brushes.Black;
            style.Outline.Width = 6;

            var vl = new SharpMap.Layers.VectorLayer("Railways", provider)
                         {Style = style};


            map.Layers.Add(vl);

            var env = vl.Envelope;
            env.ExpandBy(-0.45f *env.Width, -0.45 * env.Height);
            
            map.ZoomToBox(env);

            var mapImage = map.GetMap();
            mapImage.Save("Example2.png",
                System.Drawing.Imaging.ImageFormat.Png);
        }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: lishxi/_SharpMap
        private void AddShapeLayer_OnClick(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();
            ofd.Filter = "Shapefiles (*.shp)|*.shp";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var ds = new SharpMap.Data.Providers.ShapeFile(ofd.FileName);
                var lay = new SharpMap.Layers.VectorLayer(System.IO.Path.GetFileNameWithoutExtension(ofd.FileName), ds);
                if (ds.CoordinateSystem != null)
                {
                    GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory fact =
                        new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();

                    lay.CoordinateTransformation = fact.CreateFromCoordinateSystems(ds.CoordinateSystem,
                        ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
                    lay.ReverseCoordinateTransformation = fact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator,
                        ds.CoordinateSystem);
                }
                WpfMap.MapLayers.Add(lay);
                if (WpfMap.MapLayers.Count == 1)
                {
                    Envelope env = lay.Envelope;
                    WpfMap.ZoomToEnvelope(env);
                }
            }
            e.Handled = true;
        }
コード例 #10
0
    public static Map CreateMap()
    {
      const string getCapabilitiesURI = "http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap?request=GetCapabilities&service=WFS&VERSION=1.0.0";

      Map demoMap = new SharpMap.Map(new Size(600, 600));
      demoMap.MinimumZoom = 0.005;
      demoMap.BackColor = Color.White;

      SharpMap.Layers.VectorLayer layer1 = new SharpMap.Layers.VectorLayer("prov_land");
      WFS prov1 = new WFS(getCapabilitiesURI, "", "prov_land", WFS.WFSVersionEnum.WFS1_1_0);
      layer1.Style.Fill = new SolidBrush(Color.IndianRed);    // States
      //// Options 
      // Defaults: MultiGeometries: true, QuickGeometries: false, GetFeatureGETRequest: false
      // Render with validation...
      prov1.QuickGeometries = false;
      // Important when connecting to an UMN MapServer
      //!!!prov1.GetFeatureGETRequest = true;
      // Ignore multi-geometries...
      prov1.MultiGeometries = false;
      layer1.DataSource = prov1;
      demoMap.Layers.Add(layer1);

      demoMap.ZoomToBox(new SharpMap.Geometries.BoundingBox(-3546709.473205, -869773.355764, 4444893.074820, 3923457.184829));

      return demoMap;
    }
コード例 #11
0
        public void TestPathPointSymbolizer()
        {
            var fdt = CreatingData.CreatePointFeatureDataTableFromArrays(
                CreatingData.GetRandomOrdinates(50, -180, 180), CreatingData.GetRandomOrdinates(50, -90, 90), null);
            var geometryFeatureProvider = new SharpMap.Data.Providers.FeatureProvider(fdt);
            var layer = new SharpMap.Layers.VectorLayer("randompoints", geometryFeatureProvider);
            var pps =
                SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(new System.Drawing.Pen(System.Drawing.Color.Red, 2),
                                                                    new System.Drawing.SolidBrush(
                                                                        System.Drawing.Color.DodgerBlue), 20);
            layer.Style.PointSymbolizer = pps;
            var map = new SharpMap.Map(new System.Drawing.Size(720, 360));
            map.Layers.Add(layer);
            map.ZoomToExtents();
            map.GetMap().Save("PathPointSymbolizer1.bmp");

            pps.Rotation = -30;
            map.GetMap().Save("PathPointSymbolizer2.bmp");

            pps.Rotation = 0f;
            pps.Offset = new System.Drawing.PointF(4, 4);
            map.GetMap().Save("PathPointSymbolizer3.bmp");

            var gpTriangle1 = new System.Drawing.Drawing2D.GraphicsPath();
            gpTriangle1.AddPolygon(new [] { new System.Drawing.Point(0, 0), new System.Drawing.Point(5, 10), new System.Drawing.Point(10, 0), new System.Drawing.Point(0, 0), });
            var gpTriangle2 = new System.Drawing.Drawing2D.GraphicsPath();
            gpTriangle2.AddPolygon(new[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(-5, -10), new System.Drawing.Point(-10, 0), new System.Drawing.Point(0, 0), });
            pps = new
                SharpMap.Rendering.Symbolizer.PathPointSymbolizer(new[]
                                                        {
                                                            new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition
                                                                {
                                                                    Path = gpTriangle1,
                                                                    Line =
                                                                        new System.Drawing.Pen(
                                                                        System.Drawing.Color.Red, 2),
                                                                    Fill =
                                                                        new System.Drawing.SolidBrush(
                                                                        System.Drawing.Color.DodgerBlue)
                                                                },
                                                            new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition
                                                                {
                                                                    Path = gpTriangle2,
                                                                    Line =
                                                                        new System.Drawing.Pen(
                                                                        System.Drawing.Color.DodgerBlue, 2),
                                                                    Fill =
                                                                        new System.Drawing.SolidBrush(
                                                                        System.Drawing.Color.Red)
                                                                }

                                                        }){ Rotation = 45 };

            layer.Style.PointSymbolizer = pps;
            map.GetMap().Save("PathPointSymbolizer4.bmp");
            pps.Rotation = 180;
            map.GetMap().Save("PathPointSymbolizer5.bmp");

        }
コード例 #12
0
ファイル: GdalSample.cs プロジェクト: lishxi/_SharpMap
    public static Map InitializeMap()
    {
      try
      {
        //Sample provided by Dan Brecht and Joel Wilson
        Map map = new Map();
        map.BackColor = Color.White;

        string relativePath = "GeoData/GeoTiff/";

        SharpMap.Layers.GdalRasterLayer layer;

        if (!File.Exists(relativePath + "format01-image_a.tif"))
        {
          throw new Exception("Make sure the data is in the relative directory: " + relativePath);
        }

        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif");
        map.Layers.Add(layer);
        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif");
        map.Layers.Add(layer);
        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif");
        map.Layers.Add(layer);
        layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif");
        map.Layers.Add(layer);

        SharpMap.Layers.VectorLayer shapeLayer;

        if (!File.Exists(relativePath + "outline.shp"))
        {
          throw new Exception("Make sure the data is in the relative directory: " + relativePath);
        }

        shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp"));
        shapeLayer.Style.Fill = Brushes.Transparent;
        shapeLayer.Style.Outline = Pens.Black;
        shapeLayer.Style.EnableOutline = true;
        shapeLayer.Style.Enabled = true;
        map.Layers.Add(shapeLayer);

        map.ZoomToExtents();

        return map;
      }
      catch (Exception ex)
      {
        if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.")
        {
          throw new Exception(String.Format("The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion));
        }
        throw;
      }

    }
コード例 #13
0
ファイル: AppEngine.cs プロジェクト: ZoneDesignSystems/zds
        /// <summary>
        /// Create SharpMap Layer
        /// </summary>
        /// <param name="ShapeFilePath"></param>
        /// <param name="ShapeName"></param>
        /// <returns></returns>
        public static SharpMap.Layers.VectorLayer CreateShpLayer(string shapeFilePath, 
            string shapeName)
        {
            _cLayer = new SharpMap.Layers.VectorLayer(shapeName);
              _cLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(shapeFilePath,true);
              _cLayer.Style.Fill = Brushes.LightGoldenrodYellow;
              _cLayer.Style.EnableOutline = true;
              _cLayer.Style.Outline = Pens.DarkBlue;

              return _cLayer;
        }
コード例 #14
0
 public GeometryVisualizer()
 {
     InitializeComponent();
     _geomFactory = new FgfGeometryFactory();
     _layer = new SharpMap.Layers.VectorLayer("Preview");
     _mapCtl = new SharpMap.Forms.MapImage();
     _mapCtl.Map = new SharpMap.Map();
     _mapCtl.Map.Layers.Add(_layer);
     _mapCtl.Dock = DockStyle.Fill;
     mapPanel.Controls.Add(_mapCtl);
 }
コード例 #15
0
ファイル: Form1.cs プロジェクト: oliverheilig/SharpMap.Ptv
        private void Form1_Load(object sender, EventArgs e)
        {
            // set up sharpmap
            // Note: The process must run as 32-bit! The data source for map&market and AM use Access with OleDB.

            // create sharp map
            map = new SharpMap.Map(pictureBox1.ClientSize);

            // add background layer
            map.Layers.Add(new XMapServerLayer("Background", Properties.Settings.Default.XMapServerUrl, XMapServerMode.BackGround)
            {
                User = "******", Password = Properties.Settings.Default.XMapToken
            });

            // create vector layer
            SharpMap.Layers.VectorLayer districts = new SharpMap.Layers.VectorLayer("Dístricts");
            
            // initialize data source
            districtsData = new Ptv.Controls.Map.MapMarket.MMProviderStatic(
                 @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +  System.AppDomain.CurrentDomain.BaseDirectory + @"\Data\Districts.mdb",
                 "KRE", "GID", "XMIN", "YMIN", "XMAX", "YMAX", "WKB_GEOMETRY");
            districts.DataSource = districtsData;

            // set style
            districts.Theme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);

            // insert into sharp map
            map.Layers.Add(districts);

            // add label layer
            map.Layers.Add(new XMapServerLayer("Labels", Properties.Settings.Default.XMapServerUrl, XMapServerMode.Overlay)
            {
                User = "******",
                Password = Properties.Settings.Default.XMapToken
            });

            // insert address monitor layers
            var rootPath = System.AppDomain.CurrentDomain.BaseDirectory + "Data";
            var bitmapPath = rootPath + "\\Bitmaps";
            string[] poiFiles = System.IO.Directory.GetFiles(rootPath, "*.poi");
            foreach (string poiFile in poiFiles)
            {
                var layer = AMLayerFactory.CreateLayer(poiFile, bitmapPath);
                layer.MaxVisible = 9999999999; // override the automatic display threshold
                map.Layers.Add(layer);
            }

            // set map extends
            ZoomToBox();
        }
コード例 #16
0
        public void TestWarpedLineSymbolizer()
        {
            var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);

            var l = new SharpMap.Layers.VectorLayer("roads", p);
            var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer();
            cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2) });
            cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetGreaterSeries(3, 3), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1) });
            l.Style.LineSymbolizer = cls;

            var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) {BackColor = System.Drawing.Color.Cornsilk};
            m.Layers.Add(l);

            m.ZoomToExtents();

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1.bmp");

            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetTriangleSeries(4, 7),
                Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
            };
            sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2.bmp");

            //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1];
            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
                                               {
                                                   Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetZigZag(4, 4),
                                                   Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                                                   //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                                               };
            sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads3.bmp");

        }
コード例 #17
0
ファイル: Examples.cs プロジェクト: geobabbler/SharpMap
        public static void Example1()
        {
            var map = new SharpMap.Map(new Size(1280, 1084));

            SharpMap.Data.Providers.IProvider provider =
                new SharpMap.Data.Providers.ShapeFile(
                    @"C:\temp\Data\niedersachsen.shp\railways.shp");
            var vl = new SharpMap.Layers.VectorLayer("Railways", provider);

            map.Layers.Add(vl);

            map.ZoomToBox(vl.Envelope);

            var mapImage = map.GetMap();
            mapImage.Save("Example1.png",
                System.Drawing.Imaging.ImageFormat.Png);
        }
コード例 #18
0
        public void GetItemByID()
        {
            var fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add(new DataColumn("ID", typeof(uint)));

            var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            for (var i = 0; i < 5; i++)
            {
                var row = fdt.NewRow();
                row[0] = (uint)i;
                row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i));
                fdt.AddRow(row);
            }
            var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            var res = layer.DataSource.GetFeature(0);
            NUnit.Framework.Assert.IsNotNull(res);
        }
コード例 #19
0
        public void TestFindGeoNearPoint()
        {
            var fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add(new DataColumn("ID", typeof(uint)));

            var gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            for (var i = 0; i < 5; i++)
            {
                var row = fdt.NewRow();
                row[0] = (uint)i;
                row.Geometry = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(i, i));
                fdt.AddRow(row);
            }
            var layer = new SharpMap.Layers.VectorLayer("TMP", new SharpMap.Data.Providers.GeometryFeatureProvider(fdt));

            var res = FindGeoNearPoint(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(0.1, 0.1)), layer, 0.2d);
            NUnit.Framework.Assert.IsNotNull(res);
            NUnit.Framework.Assert.AreEqual(0, (uint)res[0]);
        }
コード例 #20
0
        public void TestPerformanceVectorLayer()
        {
            NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")),
                                          "Specified shapefile is not present!");

            var map = new SharpMap.Map(new System.Drawing.Size(1024, 768));

            var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"));
            var lyr = new SharpMap.Layers.VectorLayer("Roads", shp);

            map.Layers.Add(lyr);
            map.ZoomToExtents();

            RepeatedRendering(map, shp.GetFeatureCount(), NumberOfRenderCycles, out _msVector);

            var res = map.GetMap();
            var path = System.IO.Path.ChangeExtension(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), ".vector.png");
            res.Save(path, System.Drawing.Imaging.ImageFormat.Png);
            System.Console.WriteLine("\nResult saved at file://" + path.Replace('\\', '/'));
        }
コード例 #21
0
        public void TestCachedLineSymbolizerInTheme()
        {
            var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);

            var l = new SharpMap.Layers.VectorLayer("roads", p);
            var theme = new ClsTheme(l.Style);
            l.Theme = theme;

            var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) { BackColor = System.Drawing.Color.Cornsilk };
            m.Layers.Add(l);

            m.ZoomToExtents();

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1Theme.bmp");
        }
コード例 #22
0
        public void TestEnsureVisible()
        {
            //Create a map
            SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720,360));
            
            //Create some random sample data
            SharpMap.Data.FeatureDataTable fdt =
                cd.CreatePointFeatureDataTableFromArrays(cd.GetRandomOrdinates(80, -180, 180),
                                                         cd.GetRandomOrdinates(80, -90, 90), null);

            //Create layer and datasource
            SharpMap.Layers.VectorLayer vl = new SharpMap.Layers.VectorLayer("Points", new SharpMap.Data.Providers.FeatureProvider(fdt));
            
            //Create default style
            SharpMap.Styles.VectorStyle defaultStyle = new SharpMap.Styles.VectorStyle();
            defaultStyle.Symbol = new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png");
            defaultStyle.SymbolScale = 0.5f;

            //Create theming class and apply to layer
            var srt = new SymbolRotationTheming("Rotation", defaultStyle);
            vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(srt.GetRotatedSymol);


            map.Layers.Add(vl);
            map.ZoomToExtents();
            map.Zoom = 60; //2*30
            map.Center = new GeoAPI.Geometries.Coordinate(0,0);

            System.Console.WriteLine(map.Center);
            EnsureVisible(map, new GeoAPI.Geometries.Coordinate(-30, 0));
            System.Console.WriteLine(map.Center);
            System.Console.WriteLine();
            EnsureVisible(map, new GeoAPI.Geometries.Coordinate(15, 20));
            System.Console.WriteLine(map.Center);
            System.Console.WriteLine();
            EnsureVisible(map, new GeoAPI.Geometries.Coordinate(15, -20));
            System.Console.WriteLine(map.Center);
        }
コード例 #23
0
        public void TestBasicLineSymbolizer()
        {
            var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\roads.shp", false);
            var l = new SharpMap.Layers.VectorLayer("roads", p);
            //l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5);
            l.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1);
            l.Style.EnableOutline = false;
            var m = new SharpMap.Map(new System.Drawing.Size(1440,1080)) {BackColor = System.Drawing.Color.Cornsilk};
            m.Layers.Add(l);

            m.ZoomToExtents();

            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            m.GetMap();

            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
            sw.Reset();
            sw.Start();
            var bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("NDSRoads1.bmp");


            var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer();
            //cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) });
            cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 1) });

            l.Style.LineSymbolizer = cls;
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("NDSRoads2.bmp");

        }
コード例 #24
0
ファイル: FormViewer.cs プロジェクト: gerie-tanabe/rubix
        private void LoadParcels(List<PointD> pt, Color color, string labelname)
        {
            SharpMap.Map map = new SharpMap.Map();
            List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>();

            foreach (PointD i in pt)
            {
                GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate();
                p.X = i.X;
                p.Y = i.Y;
                vertices.Add(p);
            }
            GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate();
            l.X = pt[0].X;
            l.Y = pt[0].Y;
            vertices.Add(l);

            //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>();

            GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory();
            GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray());

            GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null);

            SharpMap.Data.Providers.GeometryProvider geomProvider= new SharpMap.Data.Providers.GeometryProvider(polygon);

            SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels");

            SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();

            style.Fill = new SolidBrush(Color.FromArgb(200,color));
            style.Outline = new Pen(new SolidBrush(color));

            layerParcels.Style = style;
            layerParcels.Style.EnableOutline = true;

            layerParcels.DataSource = geomProvider;
            layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;

            var fdt = new SharpMap.Data.FeatureDataTable();
            fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint)));
            fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string)));
            var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow();
            fdr.ItemArray = new object[] { 1, labelname };
            fdr.Geometry =  polygon;
            fdt.AddRow(fdr);

            var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);

            var ll = new SharpMap.Layers.LabelLayer("llayer");
            ll.DataSource = dataprovider;
            ll.LabelColumn = "label";
            ll.Style.Font = new Font("Eurostile Extended", 16,FontStyle.Bold);

            mapBox1.Map.Layers.Add(layerParcels);
            mapBox1.Map.Layers.Add(ll);

            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
        }
コード例 #25
0
        public static SharpMap.Map InitializeMap(float angle)
        {
            //Initialize a new map of size 'imagesize'
            SharpMap.Map map = new SharpMap.Map();

            //Set up the countries layer
            SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new SharpMap.Data.Providers.PostGIS(Properties.Settings.Default.PostGisConnectionString, "countries", "ogc_fid");

            //Set fill-style to green
            layCountries.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
            //Set the polygons to have a black outline
            layCountries.Style.Outline = System.Drawing.Pens.Black;
            layCountries.Style.EnableOutline = true;

            //Set up a river layer
            SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SharpMap.Data.Providers.PostGIS(Properties.Settings.Default.PostGisConnectionString, "rivers", "ogc_fid");
            //Define a blue 1px wide pen
            layRivers.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);

            //Set up a river layer
            SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource = new SharpMap.Data.Providers.PostGIS(Properties.Settings.Default.PostGisConnectionString, "cities", "ogc_fid");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible = 40;

            //Set up a country label layer
            SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels")
            {
                DataSource = layCountries.DataSource,
                Enabled = true,
                LabelColumn = "Name",
                MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                PriorityColumn = "popdens",
                Style = new SharpMap.Styles.LabelStyle()
                {
                    ForeColor = System.Drawing.Color.White,
                    Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 12),
                    BackColor = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 255, 0, 0)),
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center,
                    CollisionDetection = true,
                    MaxVisible = 90,
                    MinVisible = 30
                }
            };

            //Set up a city label layer
            SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels")
            {
                DataSource = layCities.DataSource,
                Enabled = true,
                LabelColumn = "name",
                PriorityColumn = "population",
                PriorityDelegate = delegate(SharpMap.Data.FeatureDataRow fdr)
                {
                    Int32 retVal = 10000000 * (Int32)( (String)fdr["capital"] == "Y" ? 1 : 0 );
                    return  retVal + Convert.ToInt32(fdr["population"]);
                },
                TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
                SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                Style = new SharpMap.Styles.LabelStyle()
                {
                    ForeColor = System.Drawing.Color.White,
                    Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 11),
                    MaxVisible = layLabel.MinVisible,
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset = new System.Drawing.PointF(3, 3),
                    Halo = new System.Drawing.Pen(System.Drawing.Color.Black, 2),
                    CollisionDetection = true
                }
            };

            //Add the layers to the map object.
            //The order we add them in are the order they are drawn, so we add the rivers last to put them on top
            map.Layers.Add(layCountries);
            map.Layers.Add(layRivers);
            map.Layers.Add(layCities);
            map.Layers.Add(layLabel);
            map.Layers.Add(layCityLabel);

            //limit the zoom to 360 degrees width
            map.MaximumZoom = 360;
            map.BackColor = System.Drawing.Color.LightBlue;

            map.ZoomToExtents(); // = 360;
            map.Center = new GeoAPI.Geometries.Coordinate(0, 0);

            Matrix mat = new Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            return map;
        }
コード例 #26
0
        public static SharpMap.Map InitializeMap(float angle)
        {
            //Initialize a new map of size 'imagesize'
            SharpMap.Map map = new SharpMap.Map();

            //Set up the countries layer
            SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new SharpMap.Data.Providers.PostGIS(Properties.Settings.Default.PostGisConnectionString, "countries", "ogc_fid");

            //Set fill-style to green
            layCountries.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
            //Set the polygons to have a black outline
            layCountries.Style.Outline       = System.Drawing.Pens.Black;
            layCountries.Style.EnableOutline = true;

            //Set up a river layer
            SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SharpMap.Data.Providers.PostGIS(Properties.Settings.Default.PostGisConnectionString, "rivers", "ogc_fid");
            //Define a blue 1px wide pen
            layRivers.Style.Line = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);

            //Set up a river layer
            SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource        = new SharpMap.Data.Providers.PostGIS(Properties.Settings.Default.PostGisConnectionString, "cities", "ogc_fid");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible        = 40;

            //Set up a country label layer
            SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels")
            {
                DataSource  = layCountries.DataSource,
                Enabled     = true,
                LabelColumn = "Name",
                MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                LabelFilter    = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                PriorityColumn = "popdens",
                Style          = new SharpMap.Styles.LabelStyle()
                {
                    ForeColor           = System.Drawing.Color.White,
                    Font                = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 12),
                    BackColor           = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 255, 0, 0)),
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center,
                    CollisionDetection  = true,
                    MaxVisible          = 90,
                    MinVisible          = 30
                }
            };

            //Set up a city label layer
            SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels")
            {
                DataSource       = layCities.DataSource,
                Enabled          = true,
                LabelColumn      = "name",
                PriorityColumn   = "population",
                PriorityDelegate = delegate(GeoAPI.Features.IFeature fdr)
                {
                    Int32 retVal = 10000000 * (Int32)((String)fdr.Attributes["capital"] == "Y" ? 1 : 0);
                    return(retVal + Convert.ToInt32(fdr.Attributes["population"]));
                },
                TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
                SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
                LabelFilter       = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                Style             = new SharpMap.Styles.LabelStyle()
                {
                    ForeColor           = System.Drawing.Color.White,
                    Font                = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 11),
                    MaxVisible          = layLabel.MinVisible,
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment   = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset              = new System.Drawing.PointF(3, 3),
                    Halo                = new System.Drawing.Pen(System.Drawing.Color.Black, 2),
                    CollisionDetection  = true
                }
            };

            //Add the layers to the map object.
            //The order we add them in are the order they are drawn, so we add the rivers last to put them on top
            map.Layers.Add(layCountries);
            map.Layers.Add(layRivers);
            map.Layers.Add(layCities);
            map.Layers.Add(layLabel);
            map.Layers.Add(layCityLabel);

            //limit the zoom to 360 degrees width
            map.MaximumZoom = 360;
            map.BackColor   = System.Drawing.Color.LightBlue;

            map.ZoomToExtents(); // = 360;
            map.Center = new GeoAPI.Geometries.Coordinate(0, 0);

            Matrix mat = new Matrix();

            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;

            return(map);
        }
コード例 #27
0
        public static Map InitializeMap()
        {
            //Initialize a new map based on the simple map
              Map map = new Map();

              //Set up countries layer
              SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
              //Set the datasource to a shapefile in the App_data folder
              layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile("GeoData/World/countries.shp", true);
              //Set fill-style to green
              layCountries.Style.Fill = new SolidBrush(Color.Green);
              //Set the polygons to have a black outline
              layCountries.Style.Outline = System.Drawing.Pens.Black;
              layCountries.Style.EnableOutline = true;
              layCountries.SRID = 4326;
              map.Layers.Add(layCountries);

              //set up cities layer
              SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
              //Set the datasource to a shapefile in the App_data folder
              layCities.DataSource = new SharpMap.Data.Providers.ShapeFile("GeoData/World/cities.shp", true);
              layCities.Style.SymbolScale = 0.8f;
              layCities.MaxVisible = 40;
              layCities.SRID = 4326;
              map.Layers.Add(layCities);

              //Set up a country label layer
              SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels");
              layLabel.DataSource = layCountries.DataSource;
              layLabel.Enabled = true;
              layLabel.LabelColumn = "Name";
              layLabel.Style = new SharpMap.Styles.LabelStyle();
              layLabel.Style.ForeColor = Color.White;
              layLabel.Style.Font = new Font(FontFamily.GenericSerif, 12);
              layLabel.Style.BackColor = new System.Drawing.SolidBrush(Color.FromArgb(128, 255, 0, 0));
              layLabel.MaxVisible = 90;
              layLabel.MinVisible = 30;
              layLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
              layLabel.SRID = 4326;
              layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
              map.Layers.Add(layLabel);

              //Set up a city label layer
              SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels");
              layCityLabel.DataSource = layCities.DataSource;
              layCityLabel.Enabled = true;
              layCityLabel.LabelColumn = "Name";
              layCityLabel.Style = new SharpMap.Styles.LabelStyle();
              layCityLabel.Style.ForeColor = Color.Black;
              layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
              layCityLabel.MaxVisible = layLabel.MinVisible;
              layCityLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
              layCityLabel.Style.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
              layCityLabel.Style.Offset = new PointF(3, 3);
              layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
              layCityLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
              layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
              layCityLabel.SRID = 4326;
              layCityLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
              layCityLabel.Style.CollisionDetection = true;
              map.Layers.Add(layCityLabel);

              //Set a gradient theme on the countries layer, based on Population density
              //First create two styles that specify min and max styles
              //In this case we will just use the default values and override the fill-colors
              //using a colorblender. If different line-widths, line- and fill-colors where used
              //in the min and max styles, these would automatically get linearly interpolated.
              VectorStyle min = new VectorStyle();
              VectorStyle max = new VectorStyle();
              //Create theme using a density from 0 (min) to 400 (max)
              GradientTheme popdens = new GradientTheme("PopDens", 0, 400, min, max);
              //We can make more advanced coloring using the ColorBlend'er.
              //Setting the FillColorBlend will override any fill-style in the min and max fills.
              //In this case we just use the predefined Rainbow colorscale
              popdens.FillColorBlend = SharpMap.Rendering.Thematics.ColorBlend.Rainbow5;
              layCountries.Theme = popdens;

              //Lets scale the labels so that big countries have larger texts as well
              LabelStyle lblMin = new LabelStyle();
              LabelStyle lblMax = new LabelStyle();
              lblMin.ForeColor = Color.Black;
              lblMin.Font = new Font(FontFamily.GenericSerif, 6);
              lblMax.ForeColor = Color.Blue;
              lblMax.BackColor = new SolidBrush(Color.FromArgb(128, 255, 255, 255));
              lblMin.BackColor = lblMax.BackColor;
              lblMax.Font = new Font(FontFamily.GenericSerif, 9);
              layLabel.Theme = new GradientTheme("PopDens", 0, 400, lblMin, lblMax);

              //Lets scale city icons based on city population
              //cities below 1.000.000 gets the smallest symbol, and cities with more than 5.000.000 the largest symbol
              VectorStyle citymin = new VectorStyle();
              VectorStyle citymax = new VectorStyle();
              string iconPath = "Images/icon.png";
              if (!File.Exists(iconPath))
              {
            throw new Exception(String.Format("Error file '{0}' could not be found, make sure it is at the expected location", iconPath));
              }

              citymin.Symbol = new Bitmap(iconPath);
              citymin.SymbolScale = 0.5f;
              citymax.Symbol = new Bitmap(iconPath);
              citymax.SymbolScale = 1f;
              layCities.Theme = new GradientTheme("Population", 1000000, 5000000, citymin, citymax);

              //limit the zoom to 360 degrees width
              map.MaximumZoom = 360;
              map.BackColor = Color.LightBlue;

              map.Zoom = 30;
              map.Center = new SharpMap.Geometries.Point(0, 0);

              return map;
        }
コード例 #28
0
        private static SharpMap.Map InitializeMapOsmWithXls(float angle)
        {
            var map = new SharpMap.Map();

            var tileLayer = new SharpMap.Layers.TileAsyncLayer(
                KnownTileSources.Create(KnownTileSource.OpenStreetMap), "TileLayer - OSM with XLS");

            map.BackgroundLayer.Add(tileLayer);

            //Get data from excel
            var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls", Properties.Settings.Default.OleDbProvider);
            var ds      = new System.Data.DataSet("XLS");

            using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath))
            {
                cn.Open();
                using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn)))
                    da.Fill(ds);
            }

            //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection
            var ctf      = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var cf       = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var epsg4326 = cf.CreateFromWkt("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");
            var epsg3857 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]");
            var ct       = ctf.CreateFromCoordinateSystems(epsg4326, epsg3857);

            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value)
                {
                    continue;
                }
                var coords = new[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"]) };
                coords   = ct.MathTransform.Transform(coords);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }

            //Add Rotation Column
            ds.Tables[0].Columns.Add("Rotation", typeof(float));
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                row["Rotation"] = -angle;
            }

            //Set up provider
            var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y");
            var xlsLayer    = new SharpMap.Layers.VectorLayer("XLS", xlsProvider)
            {
                Style = { Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol }
            };

            //Add layer to map
            map.Layers.Add(xlsLayer);
            var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel")
            {
                DataSource     = xlsProvider,
                LabelColumn    = "Name",
                PriorityColumn = "Population",
                Style          =
                {
                    CollisionBuffer    = new System.Drawing.SizeF(2f, 2f),
                    CollisionDetection = true
                },
                LabelFilter =
                    SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection
            };

            xlsLabelLayer.Theme = new SharpMap.Rendering.Thematics.FontSizeTheme(xlsLabelLayer, map)
            {
                FontSizeScale = 1000f
            };

            map.Layers.Add(xlsLabelLayer);

            map.ZoomToBox(tileLayer.Envelope);

            return(map);
        }
コード例 #29
0
ファイル: TileLayerSample.cs プロジェクト: lishxi/_SharpMap
        private static SharpMap.Map InitializeMapOsmWithXls(float angle)
        {
            var map = new SharpMap.Map();

            var tileLayer = new SharpMap.Layers.TileAsyncLayer(new BruTile.Web.OsmTileSource(), "TileLayer - OSM with XLS");
            map.BackgroundLayer.Add(tileLayer);

            //Get data from excel
            var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls");
            var ds = new System.Data.DataSet("XLS");
            using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath))
            {
                cn.Open();
                using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn)))
                    da.Fill(ds);
            }

#if !DotSpatialProjections

            //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection
            var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var epsg4326 = cf.CreateFromWkt("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");
            var epsg3857 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]");
            var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3857);
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                var coords = new[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])};
                coords = ct.MathTransform.Transform(coords);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }

#else
            var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            var epsg3857 = DotSpatial.Projections.ProjectionInfo.FromEsriString("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3857\"]]");
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                var coords = new[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])};
                DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3857, 0, 1);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }

#endif
            //Add Rotation Column
            ds.Tables[0].Columns.Add("Rotation", typeof (float));
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                row["Rotation"] = -angle;

            //Set up provider
            var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y");
            var xlsLayer = new SharpMap.Layers.VectorLayer("XLS", xlsProvider)
                               {Style = {Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol}};

            //Add layer to map
            map.Layers.Add(xlsLayer);
            var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel")
                                    {
                                        DataSource = xlsProvider,
                                        LabelColumn = "Name",
                                        PriorityColumn = "Population",
                                        Style =
                                            {
                                                CollisionBuffer = new System.Drawing.SizeF(2f, 2f),
                                                CollisionDetection = true
                                            },
                                        LabelFilter =
                                            SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection
                                    };
            map.Layers.Add(xlsLabelLayer);

            map.ZoomToBox(tileLayer.Envelope);

            return map;
        }
コード例 #30
0
        public void TestWarpedLineSymbolizer()
        {
            var p = new SharpMap.Data.Providers.ShapeFile(GetTestFile(), false);

            var l = new SharpMap.Layers.VectorLayer("roads", p);

            var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer();

            cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler
            {
                Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2)
            });

            var wls = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern =
                    SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.
                    GetGreaterSeries(3, 3),
                Line       = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1)
                , Interval = 20
            };

            cls.LineSymbolizeHandlers.Add(wls);
            l.Style.LineSymbolizer = cls;

            var m = new SharpMap.Map(new System.Drawing.Size(720, 540))
            {
                BackColor = System.Drawing.Color.Cornsilk
            };

            m.Layers.Add(l);

            m.ZoomToExtents();

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var bmp = m.GetMap();

            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1.bmp");

            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern =
                    SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.
                    GetTriangle(4, 0),
                Line       = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                Fill       = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                , Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-0.bmp");

            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern =
                    SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.
                    GetTriangle(4, 1),
                Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-1.bmp");
            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern =
                    SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.
                    GetTriangle(4, 2),
                Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-2.bmp");

            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern =
                    SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.
                    GetTriangle(4, 3),
                Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                ,
                Interval = 10
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2-3.bmp");


            //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1];
            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern =
                    SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetZigZag(4, 4),
                Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
            };
            sw.Reset(); sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads3.bmp");
        }
コード例 #31
0
        public Form1()
        {
            InitializeComponent();

            string        currentDir      = Directory.GetCurrentDirectory();
            string        tutFile         = @"\ShapeFiles\states_ugl.shp";
            string        worldBorders    = @"\ShapeFiles\TM_WORLD_BORDERS-0.3.shp";
            List <string> texasShapeFiles = new List <string>();


            SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("world");

            // Load information from ShapeFiles
            vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(currentDir + worldBorders, true);

            //Create the style
            VectorStyle defaultStyle = new VectorStyle();

            //Create the style for regions
            VectorStyle africa       = new VectorStyle();
            VectorStyle antartica    = new VectorStyle();
            VectorStyle australia    = new VectorStyle();
            VectorStyle northAmerica = new VectorStyle();
            VectorStyle asia         = new VectorStyle();
            VectorStyle europe       = new VectorStyle();

            // Set Random Colors
            Random rnd = new Random();


            // Add styles to List
            styles.Add(999, defaultStyle);
            styles.Add(0, antartica);
            styles.Add(2, africa);
            styles.Add(9, australia);
            styles.Add(19, northAmerica);
            styles.Add(142, asia);
            styles.Add(150, europe);

            foreach (KeyValuePair <int, IStyle> style in styles)
            {
                var o = style.Value as VectorStyle;
                o.EnableOutline = true;
                rnd.Next(0, 256);

                var r = rnd.Next(0, 256);
                var g = rnd.Next(0, 256);
                var b = rnd.Next(0, 256);
                o.Fill = new SolidBrush(Color.FromArgb(r, g, b));
            }

            //Assign the theme
            vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme <int>("region", styles, defaultStyle);

            // Add the layer to the mapBox control
            mapBox1.Map.Layers.Add(vlay);

            // Get US Cities from WMS Server
            SharpMap.Layers.WmsLayer wmsL =
                new SharpMap.Layers.WmsLayer("US Cities",
                                             "http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer");

            //Force PNG format. Else we can't see through
            wmsL.SetImageFormat("image/png");
            //Force version 1.1.0
            wmsL.Version = "1.1.0";
            //Add layer named 2 in the service (Cities)
            wmsL.AddLayer("2");
            //Set the SRID
            wmsL.SRID = 4326;
            mapBox1.Map.Layers.Add(wmsL);

            // mapBox1.Map.Layers.Add(vlay);
            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
            mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
        }
コード例 #32
0
        public void render2d(Project project, PictureBox picBox)
        {
            SharpMap.Map myMap = new SharpMap.Map();

            foreach (BuildLayer layer in project.getLayers())
            {
                Source source = layer.getSource();

                BoundingBox    envelope = new BoundingBox(-1000.0, -1000.0, 1000.0, 1000.0);//TODO
                FeatureDataSet ds       = new FeatureDataSet();
                source.DataSource.Open();
                source.DataSource.ExecuteIntersectionQuery(envelope, ds);
                source.DataSource.Close();

                FeatureDataTable features = (FeatureDataTable)ds.Tables[0];

                string label = "Trace test:\n";

                foreach (FeatureDataRow row in features)
                {
                    foreach (Object item in row.ItemArray)
                    {
                        label += " - " + item;
                    }
                    label += "\n";
                }

                setLabel(label);

                //Show map

                //Filters
                FilterGraph graph = project.getFilterGraph(source.getName());
                if (graph != null)
                {
                    foreach (FeatureFilter filter in graph.getFilters())
                    {
                        //aplicar filtro segun el tipo
                        Mogre.DefaultSceneManagerFactory dsmf = new DefaultSceneManagerFactory();
                        Mogre.SceneManager sm  = dsmf.CreateInstance("scenemanager");
                        FilterEnv          env = new FilterEnv(sm, "env");
                        foreach (MogreGis.Resource resource in project.getResources())
                        {
                            env.getSession().Resources.addResource(resource);
                        }
                        FeatureList list = Feature.DataTableToList(features);
                        filter.process(list, env);
                        //falta devolver la lista y procesarla ***************************************
                    }
                }

                SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer(layer.getName());
                myLayer.DataSource = source.DataSource;
                myMap.Layers.Add(myLayer);
            }

            myMap.Size = new Size(picBox.Width, picBox.Height);
            myMap.ZoomToExtents();
            picBox.Image = myMap.GetMap();
            this.map     = myMap;
        }
コード例 #33
0
ファイル: GdalSample.cs プロジェクト: ivkrivanov/datadesign
        private static SharpMap.Map InitializeGeoTiff(int index, float angle)
        {
            try
            {
                //Sample provided by Dan Brecht and Joel Wilson
                var map = new SharpMap.Map();
                map.BackColor = System.Drawing.Color.White;
                const string relativePath = "GeoData/GeoTiff/";

                SharpMap.Layers.GdalRasterLayer layer;

                switch (index)
                {
                case 2:
                    layer             = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.tif");
                    layer.UseRotation = true;
                    map.Layers.Add(layer);
                    break;

                case 3:
                    layer             = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.jp2");
                    layer.UseRotation = true;
                    map.Layers.Add(layer);
                    break;

                case 4:
                    layer             = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "world_raster_mod.tif");
                    layer.UseRotation = true;
                    map.Layers.Add(layer);
                    break;

                default:
                    if (!System.IO.File.Exists(relativePath + "format01-image_a.tif"))
                    {
                        throw new System.Exception("Make sure the data is in the relative directory: " + relativePath);
                    }

                    layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif");
                    map.Layers.Add(layer);
                    layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif");
                    map.Layers.Add(layer);
                    layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif");
                    map.Layers.Add(layer);
                    layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif");
                    map.Layers.Add(layer);

                    SharpMap.Layers.VectorLayer shapeLayer;

                    if (!System.IO.File.Exists(relativePath + "outline.shp"))
                    {
                        throw new System.Exception("Make sure the data is in the relative directory: " + relativePath);
                    }

                    shapeLayer                     = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp"));
                    shapeLayer.Style.Fill          = System.Drawing.Brushes.Transparent;
                    shapeLayer.Style.Outline       = System.Drawing.Pens.Black;
                    shapeLayer.Style.EnableOutline = true;
                    shapeLayer.Style.Enabled       = true;
                    map.Layers.Add(shapeLayer);
                    break;
                }

                map.ZoomToExtents();

                System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                mat.RotateAt(angle, map.WorldToImage(map.Center));
                map.MapTransform = mat;

                if (_num > 5)
                {
                    _num = 1;
                }
                _gdalSampleDataset = "GeoTiff" + _num;
                return(map);
            }
            catch (System.TypeInitializationException ex)
            {
                if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.")
                {
                    throw new System.Exception(
                              string.Format(
                                  "The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
                                  SharpMap.Layers.GdalRasterLayer.FWToolsVersion));
                }
                throw;
            }
        }
コード例 #34
0
        private void LoadParcels(List <PointD> pt, Color color, string labelname)
        {
            SharpMap.Map map = new SharpMap.Map();
            List <GeoAPI.Geometries.Coordinate> vertices = new List <GeoAPI.Geometries.Coordinate>();


            foreach (PointD i in pt)
            {
                GeoAPI.Geometries.Coordinate p = new GeoAPI.Geometries.Coordinate();
                p.X = i.X;
                p.Y = i.Y;
                vertices.Add(p);
            }
            GeoAPI.Geometries.Coordinate l = new GeoAPI.Geometries.Coordinate();
            l.X = pt[0].X;
            l.Y = pt[0].Y;
            vertices.Add(l);

            //Collection<GeoAPI.Geometries.IGeometry> geom = new Collection<GeoAPI.Geometries.IGeometry>();



            GeometryFactory gf = new NetTopologySuite.Geometries.GeometryFactory();

            GeoAPI.Geometries.ILinearRing shell = gf.CreateLinearRing(vertices.ToArray());

            GeoAPI.Geometries.IPolygon polygon = gf.CreatePolygon(shell, null);


            SharpMap.Data.Providers.GeometryProvider geomProvider = new SharpMap.Data.Providers.GeometryProvider(polygon);

            SharpMap.Layers.VectorLayer layerParcels = new SharpMap.Layers.VectorLayer("Parcels");

            SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();



            style.Fill    = new SolidBrush(Color.FromArgb(200, color));
            style.Outline = new Pen(new SolidBrush(color));

            layerParcels.Style = style;
            layerParcels.Style.EnableOutline = true;


            layerParcels.DataSource    = geomProvider;
            layerParcels.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;

            var fdt = new SharpMap.Data.FeatureDataTable();

            fdt.Columns.Add(new System.Data.DataColumn("id", typeof(uint)));
            fdt.Columns.Add(new System.Data.DataColumn("label", typeof(string)));
            var fdr = (SharpMap.Data.FeatureDataRow)fdt.NewRow();

            fdr.ItemArray = new object[] { 1, labelname };
            fdr.Geometry  = polygon;
            fdt.AddRow(fdr);

            var dataprovider = new SharpMap.Data.Providers.GeometryFeatureProvider(fdt);

            var ll = new SharpMap.Layers.LabelLayer("llayer");

            ll.DataSource  = dataprovider;
            ll.LabelColumn = "label";
            ll.Style.Font  = new Font("Eurostile Extended", 16, FontStyle.Bold);



            mapBox1.Map.Layers.Add(layerParcels);
            mapBox1.Map.Layers.Add(ll);



            mapBox1.Map.ZoomToExtents();
            mapBox1.Refresh();
        }
コード例 #35
0
ファイル: MapImage.cs プロジェクト: zhangweixing00/ZB_Client
        private void MapImage_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (_Map != null)
            {
                if (MouseUp != null)
                {
                    MouseUp(this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)), e);
                }

                if (e.Button == MouseButtons.Left)
                {
                    switch (this.ActiveTool)
                    {
                    case Tools.ZoomOut:
                        double scale = 0.5;
                        if (!mousedragging)
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - mousedrag.Y < 0)     //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                            }
                            else     //Zoom in
                            {
                                scale = 1 + (e.Y - mousedrag.Y) * 0.1;
                            }
                        }
                        _Map.Zoom *= 1 / scale;
                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(_Map.Zoom);
                        }
                        Refresh();

                        break;

                    case Tools.ZoomIn:
                        double scale1 = 2;
                        if (!mousedragging)
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - mousedrag.Y < 0)     //Zoom out
                            {
                                scale1 = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                            }
                            else     //Zoom in
                            {
                                scale1 = 1 + (e.Y - mousedrag.Y) * 0.1;
                            }
                        }
                        _Map.Zoom *= 1 / scale1;
                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(_Map.Zoom);
                        }
                        Refresh();

                        break;

                    case Tools.Pan:
                        if (mousedragging)
                        {
                            System.Drawing.Point pnt = new System.Drawing.Point(this.Width / 2 + (mousedrag.X - e.Location.X), this.Height / 2 + (mousedrag.Y - e.Location.Y));
                            _Map.Center = this._Map.ImageToWorld(pnt);
                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            //取消左键单击定位地图中心的功能
                            //_Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            //if (MapCenterChanged != null)
                            //    MapCenterChanged(_Map.Center);
                        }
                        Refresh();

                        break;

                    case Tools.Query:
                        if (_Map.Layers.Count > _queryLayerIndex && _queryLayerIndex > -1)
                        {
                            if (_Map.Layers[_queryLayerIndex].GetType() == typeof(SharpMap.Layers.VectorLayer))
                            {
                                SharpMap.Layers.VectorLayer     layer = _Map.Layers[_queryLayerIndex] as SharpMap.Layers.VectorLayer;
                                SharpMap.Geometries.BoundingBox bbox  = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)).GetBoundingBox().Grow(_Map.PixelSize * 5);
                                SharpMap.Data.FeatureDataSet    ds    = new SharpMap.Data.FeatureDataSet();
                                layer.DataSource.Open();
                                layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
                                layer.DataSource.Close();
                                if (ds.Tables.Count > 0)
                                {
                                    if (MapQueried != null)
                                    {
                                        MapQueried(ds.Tables[0], e.Location, e.Button);
                                    }
                                    else
                                    if (MapQueried != null)
                                    {
                                        MapQueried(new SharpMap.Data.FeatureDataTable(), e.Location, e.Button);
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("对不起,您当前查询的图层为空。请您先选择一个需要查询的图层后再进行查询。", "地图查询", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        break;

                    case Tools.Distance:

                        break;

                    case Tools.BasicPoint:

                        break;
                    }
                }

                //if (this.ActiveTool == Tools.ZoomOut)
                //{
                //    double scale = 0.5;
                //    if (!mousedragging)
                //    {
                //        _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                //        if (MapCenterChanged != null)
                //            MapCenterChanged(_Map.Center);
                //    }
                //    else
                //    {
                //        if (e.Y - mousedrag.Y < 0) //Zoom out
                //            scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                //        else //Zoom in
                //            scale = 1 + (e.Y - mousedrag.Y) * 0.1;
                //    }
                //    _Map.Zoom *= 1 / scale;
                //    if (MapZoomChanged != null)
                //        MapZoomChanged(_Map.Zoom);
                //    Refresh();
                //}
                //else if (this.ActiveTool == Tools.ZoomIn)
                //{
                //    double scale = 2;
                //    if (!mousedragging)
                //    {
                //        _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                //        if (MapCenterChanged != null)
                //            MapCenterChanged(_Map.Center);
                //    }
                //    else
                //    {
                //        if (e.Y - mousedrag.Y < 0) //Zoom out
                //            scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                //        else //Zoom in
                //            scale = 1 + (e.Y - mousedrag.Y) * 0.1;
                //    }
                //    _Map.Zoom *= 1 / scale;
                //    if (MapZoomChanged != null)
                //        MapZoomChanged(_Map.Zoom);
                //    Refresh();
                //}
                //else if (this.ActiveTool == Tools.Pan)
                //{
                //    if (mousedragging)
                //    {
                //        System.Drawing.Point pnt = new System.Drawing.Point(this.Width / 2 + (mousedrag.X - e.Location.X), this.Height / 2 + (mousedrag.Y - e.Location.Y));
                //        _Map.Center = this._Map.ImageToWorld(pnt);
                //        if (MapCenterChanged != null)
                //            MapCenterChanged(_Map.Center);
                //    }
                //    else
                //    {
                //        _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                //        if (MapCenterChanged != null)
                //            MapCenterChanged(_Map.Center);
                //    }
                //    Refresh();
                //}
                //else if (this.ActiveTool == Tools.Query)
                //{
                //    if (_Map.Layers.Count > _queryLayerIndex && _queryLayerIndex > -1)
                //    {
                //        if (_Map.Layers[_queryLayerIndex].GetType() == typeof(SharpMap.Layers.VectorLayer))
                //        {
                //            SharpMap.Layers.VectorLayer layer = _Map.Layers[_queryLayerIndex] as SharpMap.Layers.VectorLayer;
                //            SharpMap.Geometries.BoundingBox bbox = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)).GetBoundingBox().Grow(_Map.PixelSize * 5);
                //            SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
                //            layer.DataSource.Open();
                //            layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
                //            layer.DataSource.Close();
                //            if (ds.Tables.Count > 0)
                //                if (MapQueried != null) MapQueried(ds.Tables[0],e.Location);
                //                else
                //                    if (MapQueried != null) MapQueried(new SharpMap.Data.FeatureDataTable(),e.Location);
                //        }
                //    }
                //    else
                //        MessageBox.Show("没有可供选择的图层。请先选择一个图层后再进行查询。");
                //}

                if (mousedragImg != null)
                {
                    mousedragImg.Dispose();
                    mousedragImg = null;
                }
                mousedragging = false;
            }
        }
コード例 #36
0
ファイル: TileLayerSample.cs プロジェクト: lishxi/_SharpMap
        private static SharpMap.Map InitializeMapOsmWithVariableLayerCollection(float angle)
        {
            var map = new SharpMap.Map();

            var tileLayer = new SharpMap.Layers.TileAsyncLayer(new BruTile.Web.OsmTileSource(), "TileLayer - OSM with VLC");
            map.BackgroundLayer.Add(tileLayer);

            var vl = new SharpMap.Layers.VectorLayer("Vilnius Transport Data - Bus", 
                new VilniusTransportData(VilniusTransportData.TransportType.Bus));
            var pttBus = new PublicTransportTheme(System.Drawing.Brushes.DarkGreen);
            vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(pttBus.GetStyle);
            vl.CoordinateTransformation = GetCoordinateTransformation();
            map.VariableLayers.Add(vl);
            vl = new SharpMap.Layers.VectorLayer("Vilnius Transport Data - Trolley", 
                new VilniusTransportData(VilniusTransportData.TransportType.TrolleyBus));
            var pttTrolley = new PublicTransportTheme(System.Drawing.Brushes.Red);
            vl.Theme = new SharpMap.Rendering.Thematics.CustomTheme(pttTrolley.GetStyle);
            vl.CoordinateTransformation = GetCoordinateTransformation();
            map.VariableLayers.Add(vl);
            SharpMap.Layers.VariableLayerCollection.Interval = 5000;

            map.ZoomToBox(vl.Envelope);

            return map;
        }
コード例 #37
0
        public static SharpMap.Map InitializeMap(float angle)
        {
            //Initialize a new map of size 'imagesize'
            SharpMap.Map map = new SharpMap.Map();

            //Set up the countries layer
            SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new SharpMap.Data.Providers.SpatiaLite(
                DataSource, "countries", "geom", "PK_UID");

            //Set fill-style to green
            layCountries.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
            //Set the polygons to have a black outline
            layCountries.Style.Outline       = System.Drawing.Pens.Black;
            layCountries.Style.EnableOutline = true;

            //Set up a river layer
            SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SharpMap.Data.Providers.SpatiaLite(
                DataSource, "rivers", "geom", "PK_UID");
            //Define a blue 3px wide pen
            layRivers.Style.Line = new System.Drawing.Pen(System.Drawing.Color.LightBlue, 2);
            layRivers.Style.Line.CompoundArray = new[] { 0.2f, 0.8f };
            layRivers.Style.Outline            = new System.Drawing.Pen(System.Drawing.Color.DarkBlue, 3);
            layRivers.Style.EnableOutline      = true;

            //Set up a cities layer
            SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
            //Set the datasource to the spatialite table
            layCities.DataSource = new SharpMap.Data.Providers.SpatiaLite(
                DataSource, "cities", "geom", "PK_UID");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible        = 40;

            //Set up a country label layer
            SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels")
            {
                DataSource  = layCountries.DataSource,
                LabelColumn = "NAME",
                MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                LabelFilter    = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                PriorityColumn = "POPDENS",
                Style          = new SharpMap.Styles.LabelStyle
                {
                    ForeColor           = System.Drawing.Color.White,
                    Font                = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 12),
                    BackColor           = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 255, 0, 0)),
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center,
                    MaxVisible          = 90,
                    MinVisible          = 30,
                    CollisionDetection  = true
                }
            };

            //Set up a city label layer
            SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels")
            {
                DataSource       = layCities.DataSource,
                LabelColumn      = "name",
                PriorityColumn   = "population",
                PriorityDelegate = delegate(SharpMap.Data.FeatureDataRow fdr)
                {
                    System.Int32 retVal = 10000000 * ((System.String)fdr["capital"] == "Y" ? 1 : 0);
                    return(retVal + System.Convert.ToInt32(fdr["population"]));
                },
                TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
                SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
                LabelFilter       = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                Style             = new SharpMap.Styles.LabelStyle
                {
                    ForeColor           = System.Drawing.Color.Black,
                    Font                = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 11),
                    MaxVisible          = layLabel.MinVisible,
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment   = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset              = new System.Drawing.PointF(3, 3),
                    Halo                = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2),
                    CollisionDetection  = true
                }
            };

            var layRiverLabels = new SharpMap.Layers.LabelLayer("RiverLabels");

            layRiverLabels.DataSource       = layRivers.DataSource;
            layRiverLabels.LabelColumn      = "Name";
            layRiverLabels.PriorityDelegate = GetRiverLength;
            layRiverLabels.Style            = new SharpMap.Styles.LabelStyle
            {
                Font               = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold),
                Halo               = new System.Drawing.Pen(System.Drawing.Color.Azure, 2),
                ForeColor          = System.Drawing.Color.DarkCyan,
                IgnoreLength       = true,
                Enabled            = true,
                CollisionDetection = true,
            };
            layRiverLabels.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;

            //Add the layers to the map object.
            //The order we add them in are the order they are drawn, so we add the rivers last to put them on top
            map.Layers.Add(layCountries);
            map.Layers.Add(layRivers);
            map.Layers.Add(layCities);
            map.Layers.Add(layRiverLabels);
            map.Layers.Add(layLabel);
            map.Layers.Add(layCityLabel);

            //limit the zoom to 360 degrees width
            map.MaximumZoom = 360;
            map.BackColor   = System.Drawing.Color.LightBlue;

            map.ZoomToExtents(); // = 360;
            //map.Center = new SharpMap.Geometries.Point(0, 0);
            var mat = new System.Drawing.Drawing2D.Matrix();

            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;
            return(map);
        }
コード例 #38
0
        public override void Initialize(System.Collections.Hashtable properties)
        {
            string configFile = null;

            //Get Config file directory from .omi file
            if (properties.ContainsKey("ConfigFile"))
            {
                configFile = (string)properties["ConfigFile"];
            }
            if (properties.ContainsKey("OutDir"))
            {
                _outDir = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), (string)properties["OutDir"]);
            }

            //Set variables
            SetVariablesFromConfigFile(configFile);
            SetValuesTableFields();

            //get input exchange item attributes
            int num_inputs = this.GetInputExchangeItemCount();

            for (int i = 0; i < num_inputs; i++)
            {
                inputs.Add(this.GetInputExchangeItem(i));
            }


            //get output exchange item attributes
            int num_outputs = this.GetOutputExchangeItemCount();

            for (int i = 0; i < num_outputs; i++)
            {
                outputs.Add(this.GetOutputExchangeItem(i));
            }


            // --- setup elementValues DataTable to store element attributes from elements.shp
            _elementValues.Columns.Add("Gauge_IDs", typeof(double));
            _elementValues.Columns.Add("Longitude", typeof(double));
            _elementValues.Columns.Add("Latitude", typeof(double));
            _elementValues.Columns.Add("kc1", typeof(double));
            _elementValues.Columns.Add("kc2", typeof(double));
            _elementValues.Columns.Add("kc3", typeof(double));
            _elementValues.Columns.Add("kc4", typeof(double));
            _elementValues.Columns.Add("kc5", typeof(double));
            _elementValues.Columns.Add("kc6", typeof(double));
            _elementValues.Columns.Add("kc7", typeof(double));
            _elementValues.Columns.Add("kc8", typeof(double));
            _elementValues.Columns.Add("kc9", typeof(double));
            _elementValues.Columns.Add("kc10", typeof(double));
            _elementValues.Columns.Add("kc11", typeof(double));
            _elementValues.Columns.Add("kc12", typeof(double));
            _elementValues.Columns.Add("RefVegType", typeof(double));
            _elementValues.Columns.Add("Elevation", typeof(double));

            //Get shapefile path
            XmlDocument doc = new XmlDocument();

            doc.Load(configFile);
            XmlElement root          = doc.DocumentElement;
            XmlNode    elementSet    = root.SelectSingleNode("//InputExchangeItem//ElementSet");
            string     shapefilePath = elementSet["ShapefilePath"].InnerText;

            //Get watershed properties from elements.shp
            SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer("elements_layer");
            myLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(shapefilePath);
            myLayer.DataSource.Open();

            for (uint i = 0; i < myLayer.DataSource.GetFeatureCount(); i++)
            {
                SharpMap.Data.FeatureDataRow feat = myLayer.DataSource.GetFeature(i);
                //DataTable att = feat.Table;

                object GaugeId   = feat.ItemArray[feat.Table.Columns.IndexOf("GaugeIDs")];
                object Longitute = feat.ItemArray[feat.Table.Columns.IndexOf("X")];
                object Latitude  = feat.ItemArray[feat.Table.Columns.IndexOf("Y")];
                object Kc1       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc1")];
                object Kc2       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc2")];
                object Kc3       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc3")];
                object Kc4       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc4")];
                object Kc5       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc5")];
                object Kc6       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc6")];
                object Kc7       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc7")];
                object Kc8       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc8")];
                object Kc9       = feat.ItemArray[feat.Table.Columns.IndexOf("Kc9")];
                object Kc10      = feat.ItemArray[feat.Table.Columns.IndexOf("Kc10")];
                object Kc11      = feat.ItemArray[feat.Table.Columns.IndexOf("Kc11")];
                object Kc12      = feat.ItemArray[feat.Table.Columns.IndexOf("Kc12")];
                object RefVeg    = feat.ItemArray[feat.Table.Columns.IndexOf("RefVeg")];
                object Elevation = feat.ItemArray[feat.Table.Columns.IndexOf("Elev")];
                _elementValues.LoadDataRow(new object[] { GaugeId, Longitute, Latitude, Kc1, Kc2, Kc3, Kc4, Kc5, Kc6, Kc7, Kc8, Kc9, Kc10, Kc11, Kc12, RefVeg, Elevation }, true);
            }
        }
コード例 #39
0
ファイル: MapWindow.cs プロジェクト: agustinsantos/Sxta
        public void LoadAndDrawData()
        {
            this.MainMapImage.Map.BackColor = Color.LightBlue;
            this.MainMapImage.Map.Center    = new SharpMap.Geometries.Point(-4, 40); //Set center of map
            this.MainMapImage.Map.Zoom      = 12;                                    //Set zoom level
            this.MainMapImage.Map.Size      = new System.Drawing.Size(1000, 1000);   //Set output size

            //Set up the countries layer
            SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\coastlines.shp");
            //Set fill-style to green
            layCountries.Style.Fill = new SolidBrush(Color.Black);
            //Set the polygons to have a black outline
            layCountries.Style.Outline       = System.Drawing.Pens.Black;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4321;

            //Set up a political area layer
            SharpMap.Layers.VectorLayer layArea = new SharpMap.Layers.VectorLayer("Areas");
            //Set the datasource to a shapefile in the App_data folder
            layArea.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\areas.shp");
            //Define a blue 1px wide pen
            layArea.Style.Line = new Pen(Color.Red, 10.4f);
            layArea.Style.Fill = new SolidBrush(Color.Beige);
            layArea.SRID       = 4322;

            //Set up a road layer
            SharpMap.Layers.VectorLayer layRoads = new SharpMap.Layers.VectorLayer("Roads");
            //Set the datasource to a shapefile in the App_data folder
            layRoads.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\roads.shp");
            //Define a blue 1px wide pen
            layRoads.Style.Line = new Pen(Color.Red, 2.0f);
            layRoads.MaxVisible = 15;
            layRoads.SRID       = 4323;
            SharpMap.Rendering.Thematics.CustomTheme iTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetRoadCustomStyle);
            SharpMap.Styles.VectorStyle defaultstyle        = new SharpMap.Styles.VectorStyle(); //Create default renderstyle
            defaultstyle.Line   = new Pen(Color.Red, 0.5f);
            iTheme.DefaultStyle = defaultstyle;
            layRoads.Theme      = iTheme;

            SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\cities.shp");
            //Define a blue 1px wide pen
            layCities.Style.Symbol      = new Bitmap(@"Data\city.png");
            layCities.Style.SymbolScale = 1.8f;
            layCities.MaxVisible        = 10;
            layCities.SRID = 4324;

            //Set up a river layer
            SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SharpMap.Data.Providers.ShapeFile(@"Data\rivers.shp");
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 0.4f);
            layRivers.MaxVisible = 7;
            layRivers.SRID       = 4325;

            //Add the layers to the map object.
            //The order we add them in are the order they are drawn, so we add the rivers last to put them on top
            MainMapImage.Map.Layers.Add(layCountries);
            MainMapImage.Map.Layers.Add(layArea);
            MainMapImage.Map.Layers.Add(layRivers);
            MainMapImage.Map.Layers.Add(layRoads);
            MainMapImage.Map.Layers.Add(layCities);

            MainMapImage.Map.Center         = new SharpMap.Geometries.Point(-4, 40); //Set center of map
            MainMapImage.Map.Zoom           = 12;                                    //Set zoom level
            MainMapImage.Map.Size           = new System.Drawing.Size(1000, 1000);   //Set output size
            MainMapImage.ActiveTool         = SharpMap.Forms.MapImage.Tools.Pan;
            MainMapImage.WheelZoomMagnitude = 1.5;
            MainMapImage.Refresh();
        }
コード例 #40
0
ファイル: SpatiaLiteSample.cs プロジェクト: lishxi/_SharpMap
        public static SharpMap.Map InitializeMap(float angle)
        {
            //Initialize a new map of size 'imagesize'
            SharpMap.Map map = new SharpMap.Map();

            //Set up the countries layer
            SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new SharpMap.Data.Providers.SpatiaLite(
                DataSource, "countries", "geom", "PK_UID");

            //Set fill-style to green
            layCountries.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
            //Set the polygons to have a black outline
            layCountries.Style.Outline = System.Drawing.Pens.Black;
            layCountries.Style.EnableOutline = true;

            //Set up a river layer
            SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SharpMap.Data.Providers.SpatiaLite(
                DataSource, "rivers", "geom", "PK_UID");
            //Define a blue 3px wide pen
            layRivers.Style.Line = new System.Drawing.Pen(System.Drawing.Color.LightBlue, 2);
            layRivers.Style.Line.CompoundArray = new[] { 0.2f, 0.8f };
            layRivers.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.DarkBlue, 3);
            layRivers.Style.EnableOutline = true;

            //Set up a cities layer
            SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
            //Set the datasource to the spatialite table
            layCities.DataSource = new SharpMap.Data.Providers.SpatiaLite(
                DataSource, "cities", "geom", "PK_UID");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible = 40;

            //Set up a country label layer
            SharpMap.Layers.LabelLayer layLabel = new SharpMap.Layers.LabelLayer("Country labels") 
            {
                DataSource = layCountries.DataSource,
                LabelColumn = "NAME",
                MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                PriorityColumn = "POPDENS",
                Style = new SharpMap.Styles.LabelStyle
                {
                    ForeColor = System.Drawing.Color.White,
                    Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 12),
                    BackColor = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 255, 0, 0)),
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center,
                    MaxVisible = 90,
                    MinVisible = 30,
                    CollisionDetection = true
                }
            };

            //Set up a city label layer
            SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City labels")
            {
                DataSource = layCities.DataSource,
                LabelColumn = "name",
                PriorityColumn = "population",
                PriorityDelegate = delegate(SharpMap.Data.FeatureDataRow fdr) 
                { 
                    System.Int32 retVal = 10000000 * ( (System.String)fdr["capital"] == "Y" ? 1 : 0 );
                    return  retVal + System.Convert.ToInt32(fdr["population"]);
                },
                TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
                SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection,
                Style = new SharpMap.Styles.LabelStyle
                {
                    ForeColor = System.Drawing.Color.Black,
                    Font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 11),
                    MaxVisible = layLabel.MinVisible,
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset = new System.Drawing.PointF(3, 3),
                    Halo = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2),
                    CollisionDetection = true
                }
            };

            var layRiverLabels = new SharpMap.Layers.LabelLayer("RiverLabels");
            layRiverLabels.DataSource = layRivers.DataSource;
            layRiverLabels.LabelColumn = "Name";
            layRiverLabels.PriorityDelegate = GetRiverLength;
            layRiverLabels.Style = new SharpMap.Styles.LabelStyle
                                       {
                                           Font = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold),
                                           Halo = new System.Drawing.Pen(System.Drawing.Color.Azure, 2),
                                           ForeColor = System.Drawing.Color.DarkCyan,
                                           IgnoreLength = true,
                                           Enabled = true,
                                           CollisionDetection = true,
                                          
                                       };
            layRiverLabels.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;

            //Add the layers to the map object.
            //The order we add them in are the order they are drawn, so we add the rivers last to put them on top
            map.Layers.Add(layCountries);
            map.Layers.Add(layRivers);
            map.Layers.Add(layCities);
            map.Layers.Add(layRiverLabels);
            map.Layers.Add(layLabel);
            map.Layers.Add(layCityLabel);

            //limit the zoom to 360 degrees width
            map.MaximumZoom = 360;
            map.BackColor = System.Drawing.Color.LightBlue;

            map.ZoomToExtents(); // = 360;
            //map.Center = new SharpMap.Geometries.Point(0, 0);
            var mat = new System.Drawing.Drawing2D.Matrix();
            mat.RotateAt(angle, map.WorldToImage(map.Center));
            map.MapTransform = mat;
            return map;

        }
コード例 #41
0
        public void TestPathPointSymbolizer()
        {
            var fdt = CreatingData.CreatePointFeatureDataTableFromArrays(
                CreatingData.GetRandomOrdinates(50, -180, 180), CreatingData.GetRandomOrdinates(50, -90, 90), null);
            var geometryFeatureProvider = new SharpMap.Data.Providers.FeatureProvider(fdt);
            var layer = new SharpMap.Layers.VectorLayer("randompoints", geometryFeatureProvider);
            var pps   =
                SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(new System.Drawing.Pen(System.Drawing.Color.Red, 2),
                                                                               new System.Drawing.SolidBrush(
                                                                                   System.Drawing.Color.DodgerBlue), 20);

            layer.Style.PointSymbolizer = pps;
            var map = new SharpMap.Map(new System.Drawing.Size(720, 360));

            map.Layers.Add(layer);
            map.ZoomToExtents();
            map.GetMap().Save("PathPointSymbolizer1.bmp");

            pps.Rotation = -30;
            map.GetMap().Save("PathPointSymbolizer2.bmp");

            pps.Rotation = 0f;
            pps.Offset   = new System.Drawing.PointF(4, 4);
            map.GetMap().Save("PathPointSymbolizer3.bmp");

            var gpTriangle1 = new System.Drawing.Drawing2D.GraphicsPath();

            gpTriangle1.AddPolygon(new [] { new System.Drawing.Point(0, 0), new System.Drawing.Point(5, 10), new System.Drawing.Point(10, 0), new System.Drawing.Point(0, 0), });
            var gpTriangle2 = new System.Drawing.Drawing2D.GraphicsPath();

            gpTriangle2.AddPolygon(new[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(-5, -10), new System.Drawing.Point(-10, 0), new System.Drawing.Point(0, 0), });
            pps = new
                  SharpMap.Rendering.Symbolizer.PathPointSymbolizer(new[]
            {
                new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition
                {
                    Path = gpTriangle1,
                    Line =
                        new System.Drawing.Pen(
                            System.Drawing.Color.Red, 2),
                    Fill =
                        new System.Drawing.SolidBrush(
                            System.Drawing.Color.DodgerBlue)
                },
                new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition
                {
                    Path = gpTriangle2,
                    Line =
                        new System.Drawing.Pen(
                            System.Drawing.Color.DodgerBlue, 2),
                    Fill =
                        new System.Drawing.SolidBrush(
                            System.Drawing.Color.Red)
                }
            })
            {
                Rotation = 45
            };

            layer.Style.PointSymbolizer = pps;
            map.GetMap().Save("PathPointSymbolizer4.bmp");
            pps.Rotation = 180;
            map.GetMap().Save("PathPointSymbolizer5.bmp");
        }
コード例 #42
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (m_Map != null)
            {
                if (MouseUp != null)
                {
                    MouseUp(m_Map.ImageToWorld(new Point(e.X, e.Y)), e);
                }

                if (e.Button == MouseButtons.Left)
                {
                    if (m_ActiveTool == Tools.ZoomOut)
                    {
                        double scale = 0.5;
                        if (m_Dragging)
                        {
                            if (e.Y - m_DragStartPoint.Y < 0) //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(m_DragStartPoint.Y - e.Y), 0.5);
                            }
                            else //Zoom in
                            {
                                scale = 1 + (e.Y - m_DragStartPoint.Y) * 0.1;
                            }
                        }
                        else
                        {
                            m_Map.Center = m_Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));

                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(m_Map.Center);
                            }
                        }

                        m_Map.Zoom /= scale;

                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(m_Map.Zoom);
                        }
                    }
                    else if (m_ActiveTool == Tools.ZoomIn)
                    {
                        double scale = 2;
                        if (m_Dragging)
                        {
                            if (e.Y - m_DragStartPoint.Y < 0) //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(m_DragStartPoint.Y - e.Y), 0.5);
                            }
                            else //Zoom in
                            {
                                scale = 1 + (e.Y - m_DragStartPoint.Y) * 0.1;
                            }
                        }
                        else
                        {
                            m_Map.Center = m_Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));

                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(m_Map.Center);
                            }
                        }

                        m_Map.Zoom *= 1 / scale;

                        if (MapZoomChanged != null)
                        {
                            MapZoomChanged(m_Map.Zoom);
                        }
                    }
                    else if (m_ActiveTool == Tools.Pan)
                    {
                        if (m_Dragging)
                        {
                            System.Drawing.Point point = new System.Drawing.Point(ClientSize.Width / 2 + (m_DragStartPoint.X - e.Location.X), ClientSize.Height / 2 + (m_DragStartPoint.Y - e.Location.Y));
                            m_Map.Center = m_Map.ImageToWorld(point);

                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(m_Map.Center);
                            }
                        }
                        else
                        {
                            m_Map.Center = m_Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));

                            if (MapCenterChanged != null)
                            {
                                MapCenterChanged(m_Map.Center);
                            }
                        }
                    }
                    else if (m_ActiveTool == Tools.Query)
                    {
                        if (m_Map.Layers.Count > m_QueryLayerIndex && m_QueryLayerIndex > -1)
                        {
                            if (m_Map.Layers[m_QueryLayerIndex].GetType() == typeof(SharpMap.Layers.VectorLayer))
                            {
                                SharpMap.Layers.VectorLayer     layer = m_Map.Layers[m_QueryLayerIndex] as SharpMap.Layers.VectorLayer;
                                SharpMap.Geometries.BoundingBox bounding;

                                if (m_Dragging)
                                {
                                    SharpMap.Geometries.Point lowerLeft;
                                    SharpMap.Geometries.Point upperRight;
                                    GetBounds(m_Map.ImageToWorld(m_DragStartPoint), m_Map.ImageToWorld(m_DragEndPoint), out lowerLeft, out upperRight);

                                    bounding = new SharpMap.Geometries.BoundingBox(lowerLeft, upperRight);
                                }
                                else
                                {
                                    bounding = m_Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)).GetBoundingBox().Grow(m_Map.PixelSize * 5);
                                }

                                SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
                                layer.DataSource.Open();
                                layer.DataSource.ExecuteIntersectionQuery(bounding, ds);
                                layer.DataSource.Close();

                                if (MapQueried != null)
                                {
                                    MapQueried((ds.Tables.Count > 0 ? ds.Tables[0] : new SharpMap.Data.FeatureDataTable()));
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("No active layer to query");
                        }
                    }
                    else if (m_ActiveTool == Tools.ZoomWindow)
                    {
                        if (m_Rectangle.Width > 0 && m_Rectangle.Height > 0)
                        {
                            SharpMap.Geometries.Point lowerLeft;
                            SharpMap.Geometries.Point upperRight;
                            GetBounds(m_Map.ImageToWorld(m_DragStartPoint), m_Map.ImageToWorld(m_DragEndPoint), out lowerLeft, out upperRight);

                            m_Map.ZoomToBox(new SharpMap.Geometries.BoundingBox(lowerLeft, upperRight));
                        }
                    }
                }

                if (m_DragImage != null)
                {
                    m_DragImage.Dispose();
                    m_DragImage = null;
                }

                if (m_Dragging)
                {
                    m_Dragging = false;

                    if (m_ActiveTool == Tools.Query)
                    {
                        Invalidate(m_Rectangle);
                    }

                    if (m_ActiveTool == Tools.ZoomWindow || m_ActiveTool == Tools.Query)
                    {
                        m_Rectangle = Rectangle.Empty;
                    }

                    Refresh();
                }
                else if (m_ActiveTool == Tools.ZoomIn || m_ActiveTool == Tools.ZoomOut || m_ActiveTool == Tools.Pan)
                {
                    Refresh();
                }
            }
        }
コード例 #43
0
        private void MapBox_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (_Map != null)
            {
                if (this.MouseUp != null)
                {
                    this.MouseUp(this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)), e);
                }

                if (e.Button == MouseButtons.Left)
                {
                    if (this.ActiveTool == Tools.ZoomOut)
                    {
                        double scale = 0.5;
                        if (!mousedragging)
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (this.MapCenterChanged != null)
                            {
                                this.MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - mousedrag.Y < 0)                             //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                            }
                            else                             //Zoom in
                            {
                                scale = 1 + (e.Y - mousedrag.Y) * 0.1;
                            }
                        }
                        _Map.Zoom *= 1 / scale;
                        if (this.MapZoomChanged != null)
                        {
                            this.MapZoomChanged(_Map.Zoom);
                        }
                        this.Refresh();
                    }
                    else if (this.ActiveTool == Tools.ZoomIn)
                    {
                        double scale = 2;
                        if (!mousedragging)
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (this.MapCenterChanged != null)
                            {
                                this.MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            if (e.Y - mousedrag.Y < 0)                             //Zoom out
                            {
                                scale = (float)Math.Pow(1 / (float)(mousedrag.Y - e.Y), 0.5);
                            }
                            else                             //Zoom in
                            {
                                scale = 1 + (e.Y - mousedrag.Y) * 0.1;
                            }
                        }
                        _Map.Zoom *= 1 / scale;
                        if (this.MapZoomChanged != null)
                        {
                            this.MapZoomChanged(_Map.Zoom);
                        }
                        this.Refresh();
                    }
                    else if (this.ActiveTool == Tools.Pan)
                    {
                        if (mousedragging)
                        {
                            System.Drawing.Point pnt = new System.Drawing.Point(this.MapBox.Width / 2 + (mousedrag.X - e.Location.X), this.MapBox.Height / 2 + (mousedrag.Y - e.Location.Y));
                            _Map.Center = this._Map.ImageToWorld(pnt);
                            if (this.MapCenterChanged != null)
                            {
                                this.MapCenterChanged(_Map.Center);
                            }
                        }
                        else
                        {
                            _Map.Center = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
                            if (this.MapCenterChanged != null)
                            {
                                this.MapCenterChanged(_Map.Center);
                            }
                        }
                        Refresh();
                    }
                    else if (this.ActiveTool == Tools.Query)
                    {
                        if (_Map.Layers.Count > _queryLayerIndex && _queryLayerIndex > -1)
                        {
                            if (_Map.Layers[_queryLayerIndex].GetType() == typeof(SharpMap.Layers.VectorLayer))
                            {
                                SharpMap.Layers.VectorLayer     layer = _Map.Layers[_queryLayerIndex] as SharpMap.Layers.VectorLayer;
                                SharpMap.Geometries.BoundingBox bbox  = this._Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)).GetBoundingBox().Grow(_Map.PixelSize * 5);
                                SharpMap.Data.FeatureDataSet    ds    = new SharpMap.Data.FeatureDataSet();
                                layer.DataSource.Open();
                                layer.DataSource.ExecuteIntersectionQuery(bbox, ds);
                                layer.DataSource.Close();
                                if (ds.Tables.Count > 0)
                                {
                                    if (this.MapQueried != null)
                                    {
                                        this.MapQueried(ds.Tables[0]);
                                    }
                                    else
                                    if (this.MapQueried != null)
                                    {
                                        this.MapQueried(new SharpMap.Data.FeatureDataTable());
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("No active layer to query");
                        }
                    }
                }
                if (mousedragImg != null)
                {
                    mousedragImg.Dispose();
                    mousedragImg = null;
                }
                mousedragging = false;
            }
        }
コード例 #44
-1
        public static SharpMap.Map InitializeMap(float angle)
        {
            var dataSource = new SharpMap.Data.Providers.ShapeFile(
                string.Format("{0}/roads.shp", ShapefileSample.PathOsm), true);
            
            var fds = new SharpMap.Data.FeatureDataSet();
            dataSource.Open();
            dataSource.ExecuteIntersectionQuery(dataSource.GetExtents(), fds);
            dataSource.Close();

            var gfp = new SharpMap.Data.Providers.GeometryFeatureProvider(fds.Tables[0]);
            var vl = new SharpMap.Layers.VectorLayer("roads", gfp)
                         {
                             CoordinateTransformation = LayerTools.Dhdn2ToWgs84
                         };
            var ll = new SharpMap.Layers.LabelLayer("labels")
                         {
                             DataSource = gfp,
                             CoordinateTransformation = LayerTools.Dhdn2ToWgs84,
                             LabelColumn = "name",
                             MultipartGeometryBehaviour =
                                 SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                         };
            ll.Style.Halo = new System.Drawing.Pen(System.Drawing.Color.Red);
            //ll.Style.IgnoreLength = true;

            var map = new SharpMap.Map();
            map.Layers.Add(vl);
            map.Layers.Add(ll);

            map.Layers.Add(vl);
            map.ZoomToExtents();
            return map;
        }