예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string filePath = ofd.FileName;
                ArcGISTileSource suyTile = new ArcGISTileSource(filePath);
                TileLayer suyTileLyr = new TileLayer(suyTile, "suy");
                //ArcGISTileCompactSource suyTile = new ArcGISTileCompactSource(filePath);
                //ArcGISTileCompactLayer suyTileLyr = new ArcGISTileCompactLayer(suyTile, "suy");
                this.mapImage1.Map.Layers.Add(suyTileLyr);
                this.mapImage1.Map.ZoomToExtents();
                this.mapImage1.Refresh();
                //SharpMap.Data.Providers.SpatiaLite sb = new SharpMap.Data.Providers.SpatiaLite("Data Source=" + ofd.FileName, "water", "Geometry", "PK_UID");
                //VectorLayer vecLyr = new VectorLayer("sqlSpatial");
                //vecLyr.DataSource = sb;
                //this.mapImage1.Map.Layers.Add(vecLyr);
                //this.mapImage1.Map.ZoomToExtents();
                //this.mapImage1.Refresh();

            }
            //BruTile.ITileProvider tileProvider =
            ////BruTile.TileSource ts = new BruTile.TileSource(
            //this.mapImage1.Map.Layers.Add();
        }
예제 #2
0
 public static Map Osm()
 {
     ILayer layer = new TileLayer(new OsmTileSource(), "BruTile-OSM") { SRID = 900913 };         
     Map map = new Map(new Size(1, 1));            
     map.Layers.Add(layer);            
     return map;
 }
예제 #3
0
        private static Map InitializeMapOsm()
        {
            Map map = new Map();

            TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM");
            map.Layers.Add(tileLayer);
            map.ZoomToBox(tileLayer.Envelope);
            return map;
        }
예제 #4
0
 public MapNewTileAvailableEventArgs(TileLayer sender, Envelope bbox, Bitmap bm, int sourceWidth,
     int sourceHeight, ImageAttributes imageAttributes)
 {
     Sender = sender;
     BoundingBox = bbox;
     Bitmap = bm;
     SourceWidth = sourceWidth;
     SourceHeight = sourceHeight;
     ImageAttributes = imageAttributes;
 }
예제 #5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            var osm = new SharpMap.Layers.TileLayer(
                BruTile.Predefined.KnownTileSources.Create(
                    BruTile.Predefined.KnownTileSource.OpenStreetMap), "Osm");

            mapBox1.Map.Center = new Coordinate(3805545.6472164583, 4534423.3788634948);
            mapBox1.Map.Zoom   = 778190;

            //mapBox1.Map.BackgroundLayer.Add(osm);
            mapBox1.Refresh();
        }
예제 #6
0
        public void TestIncompleteImage()
        {
            using (var map = new SharpMap.Map(new Size(2500, 2500)))
            {
                map.BackColor = Color.Magenta;
                var br = new BingRequest(BingRequest.UrlBing, "", BingMapType.Hybrid);
                var bts = new BingTileSource(br);
                var tl = new TileLayer(bts, "TileLayer - " + BingMapType.Hybrid.ToString(), Color.Transparent, true,
                                       System.IO.Path.Combine(_fileCacheRoot, "BingStaging"));
                map.Layers.Add(tl);

                map.ZoomToBox(new Envelope(829384.331338522, 837200.785470394, 7068020.31417922, 7072526.73926545)
                            /*new Envelope(-239839.49199841652, 78451.759683380573, -37033.0152981899, 106723.52879865949)*/);
                using (var image = map.GetMap())
                {
                    image.Save("TestIncompleteImage.png", ImageFormat.Png);
                }
            }
        }
예제 #7
0
파일: MapBox.cs 프로젝트: lishxi/_SharpMap
        void HandleMapNewTileAvaliable(TileLayer sender, BoundingBox box, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)
        {
            lock (_imageBackground)
            {
                try
                {
                    PointF min = _map.WorldToImage(new GeoPoint(box.Min.X, box.Min.Y));
                    PointF max = _map.WorldToImage(new GeoPoint(box.Max.X, box.Max.Y));

                    min = new PointF((float)Math.Round(min.X), (float)Math.Round(min.Y));
                    max = new PointF((float)Math.Round(max.X), (float)Math.Round(max.Y));

                    if (IsDisposed == false)
                    {
                        Graphics g = Graphics.FromImage(_imageBackground);

                        g.DrawImage(bm,
                            new Rectangle((int)min.X, (int)max.Y, (int)(max.X - min.X), (int)(min.Y - max.Y)),
                            0, 0,
                            sourceWidth, sourceHeight,
                            GraphicsUnit.Pixel,
                            imageAttributes);

                        g.Dispose();
                        UpdateImage(false);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    //this can be a GDI+ Hell Exception...
                }
            }


        }
예제 #8
0
        private static Map InitializeMapOsmWithXls(float angle)
        {
            Map map = new Map();

            TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS");
            map.Layers.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 epsg3785 = 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\",\"3785\"]]");
            var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785);
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                double[] coords = new double[] { 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 epsg3785 = new DotSpatial.Projections.ProjectionInfo();
            epsg3785.ReadEsriString("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\",\"3785\"]]");
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])};
                DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 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);
            xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol;
            
            //Add layer to map
            map.Layers.Add(xlsLayer);
            var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel");
            xlsLabelLayer.DataSource = xlsProvider;
            xlsLabelLayer.LabelColumn = "Name";
            xlsLabelLayer.PriorityColumn = "Population";
            xlsLabelLayer.Style.CollisionBuffer = new System.Drawing.SizeF(2f, 2f);
            xlsLabelLayer.Style.CollisionDetection = true;
            xlsLabelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
            map.Layers.Add(xlsLabelLayer);

            map.ZoomToBox(tileLayer.Envelope);

            return map;
        }
예제 #9
0
        private static Map InitializeMapGoogle(GoogleMapType mt)
        {
            Map map = new Map();

            GoogleRequest req;
            ITileSource tileSource;
            TileLayer tileLayer;
           
            if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels))
            {
                req = new GoogleRequest(GoogleMapType.GoogleSatellite);
                tileSource = new GoogleTileSource(req);
                tileLayer = new TileLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite);
                map.Layers.Add(tileLayer);
                req = new GoogleRequest(GoogleMapType.GoogleLabels);
                tileSource = new GoogleTileSource(req);
                mt = GoogleMapType.GoogleLabels;
            }
            else
            {
                req = new GoogleRequest(mt);
                tileSource = new GoogleTileSource(req);
            }

            tileLayer = new TileLayer(tileSource, "TileLayer - " + mt);
            map.Layers.Add(tileLayer);
            map.ZoomToBox(tileLayer.Envelope);
            return map;
        }
예제 #10
0
        private static Map InitializeMapBing(BingMapType mt)
        {
            Map map = new Map();

            TileLayer tileLayer = new TileLayer(new BingTileSource(BingRequest.UrlBingStaging, "", mt) , "TileLayer - Bing " + mt);
            map.Layers.Add(tileLayer);
            map.ZoomToBox(tileLayer.Envelope);
            return map;
        }
예제 #11
0
        private static Map InitializeMapOsmWithVariableLayerCollection(float angle)
        {
            Map map = new Map();

            TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with VLC");
            map.Layers.Add(tileLayer);

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

            map.ZoomToBox(vl.Envelope);

            return map;
        }
예제 #12
0
파일: MapBox.cs 프로젝트: lishxi/_SharpMap
        private void HandleMapNewTileAvaliable(TileLayer sender, Envelope box, Bitmap bm, int sourceWidth,
                                               int sourceHeight, ImageAttributes imageAttributes)
        {
            lock (_backgroundImagesLocker)
            {
                try
                {
                    var min = Point.Round(_map.WorldToImage(box.Min()));
                    var max = Point.Round(_map.WorldToImage(box.Max()));

                    if (IsDisposed == false && _isDisposed == false)
                    {

                        using (var g = Graphics.FromImage(_imageBackground))
                        {

                            g.DrawImage(bm,
                                        new Rectangle(min.X, max.Y, (max.X - min.X), (min.Y - max.Y)),
                                        0, 0,
                                        sourceWidth, sourceHeight,
                                        GraphicsUnit.Pixel,
                                        imageAttributes);

                        }

                        UpdateImage(false);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warn(ex.Message, ex);
                    //this can be a GDI+ Hell Exception...
                }

            }

        }
예제 #13
0
파일: Map.cs 프로젝트: lishxi/_SharpMap
 //ToDo: fill in the blanks
 /// <summary>
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="bbox"></param>
 /// <param name="bm"></param>
 /// <param name="sourceWidth"></param>
 /// <param name="sourceHeight"></param>
 /// <param name="imageAttributes"></param>
 public void MapNewTileAvaliableHandler(TileLayer sender, Envelope bbox, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)
 {
     var e = MapNewTileAvaliable;
     if (e != null)
         e(sender, bbox, bm,sourceWidth,sourceHeight,imageAttributes);
 }
예제 #14
0
        private void btnThemeUnique_Click(object sender, EventArgs e)
        {
            UGCThemeLayer ugcThemeLayer = new UGCThemeLayer();
            ugcThemeLayer.Type = LayerType.UGC;
            ugcThemeLayer.Visible = true;
            ugcThemeLayer.UgcLayerType = UGCLayerType.THEME;
            ugcThemeLayer.DatasetInfo = new DatasetInfo();
            ugcThemeLayer.DatasetInfo.DataSourceName = "Jingjin";
            ugcThemeLayer.DatasetInfo.Name = "BaseMap_R";
            ugcThemeLayer.DatasetInfo.Type = DatasetType.REGION;

            //theme.graduatedMode = SuperMap.Web.iServerJava6R.GraduatedMode.SQUAREROOT;
            //theme.graphAxes.axesDisplayed = true;
            //theme.graphSize.maxGraphSize = 1;
            //theme.graphSize.minGraphSize = 0.35;
            //theme.graphText.graphTextDisplayed = true;
            //theme.graphText.graphTextFormat = SuperMap.Web.iServerJava6R.ThemeGraphTextFormat.VALUE;
            //theme.graphType = SuperMap.Web.iServerJava6R.ThemeGraphType.BAR3D;

            ThemeGraph themeGraph = new ThemeGraph();
            themeGraph.Type = ThemeType.GRAPH;
            themeGraph.GraphType = ThemeGraphType.BAR3D;
            themeGraph.GraduatedMode = GraduatedMode.SQUAREROOT;
            themeGraph.AxesDisplayed = true;
            themeGraph.MaxGraphSize = 1;
            themeGraph.MinGraphSize = 0.35;
            themeGraph.GraphTextDisplayed = true;
            themeGraph.GraphTextFormat = GraphTextFormat.VALUE;
            themeGraph.BarWidth = 0.03;

            var item1 = new ThemeGraphItem();
            item1.Caption = "1";
            item1.GraphExpression = "Pop_Rate95";
            var style1 = new SuperMap.Connector.Utility.Style();
            style1.FillForeColor = new SuperMap.Connector.Utility.Color(211, 111, 240);
            item1.UniformStyle = style1;

            var item2 = new ThemeGraphItem();
            item2.Caption = "人口";
            item2.GraphExpression = "Pop_Rate99";
            var style2 = new SuperMap.Connector.Utility.Style();
            style2.FillForeColor = new SuperMap.Connector.Utility.Color(92, 73, 234);
            item2.UniformStyle = style2;

            themeGraph.Items = new ThemeGraphItem[] { item1, item2 };

            ugcThemeLayer.Theme = themeGraph;
            SuperMap.Connector.Map map = new SuperMap.Connector.Map("http://localhost:8090/iserver/services/map-jingjin");
            MapParameter defaultMapParameter = map.GetDefaultMapParameter("京津地区人口分布图_专题图");
            List<SuperMap.Connector.Utility.Layer> layers = new List<SuperMap.Connector.Utility.Layer>();
            layers.Add(ugcThemeLayer);
            //layers.Add(defaultMapParameter.Layers[11]);
            //layers.Add(defaultMapParameter.Layers[12]);
            MapParameter requestMapParameter = new MapParameter();
            requestMapParameter.Name = "京津地区人口分布图_专题图";
            requestMapParameter.Bounds = new SuperMap.Connector.Utility.Rectangle2D(defaultMapParameter.Bounds);
            requestMapParameter.CacheEnabled = false;
            requestMapParameter.ColorMode = MapColorMode.DEFAULT;
            requestMapParameter.RectifyType = RectifyType.BYCENTERANDMAPSCALE;

            requestMapParameter.CoordUnit = Unit.METER;
            requestMapParameter.OverlapDisplayed = true;
            requestMapParameter.PaintBackground = true;
            //requestMapParameter.MaxVisibleVertex = 3600000;
            requestMapParameter.Layers = layers;

            double defaultScale = defaultMapParameter.Scale;
            double[] scales = new double[] {defaultScale/16,defaultScale/14,defaultScale/12,defaultScale/10,
                defaultScale/8,defaultScale/6,defaultScale/4,defaultScale/2, defaultScale,defaultScale*2,
            defaultScale*4,defaultScale*6,defaultScale*8,defaultScale*10,defaultScale*12,defaultScale*14,defaultScale*16};
            SuperMapTileSource tileSource =
                new SuperMapTileSource("http://localhost:8090/iserver/services/map-jingjin", "京津地区人口分布图_专题图",
                256, "png", scales, requestMapParameter);
            TileLayer layer = new TileLayer(tileSource);
            layer.LayerName = "京津地区人口分布图_专题图1";

            mapControl.Map = CreateMap(layer);
        }
예제 #15
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string mapName = this.comboBox1.Text;
            SuperMap.Connector.Map map = new SuperMap.Connector.Map(this._serviceUrl);
            MapParameter mapParameter = map.GetDefaultMapParameter(mapName);
            double defaultScale = mapParameter.Scale;
            double[] scales = new double[] {defaultScale/16,defaultScale/14,defaultScale/12,defaultScale/10,
                defaultScale/8,defaultScale/6,defaultScale/4,defaultScale/2, defaultScale,defaultScale*2,
            defaultScale*4,defaultScale*6,defaultScale*8,defaultScale*10,defaultScale*12,defaultScale*14,defaultScale*16};
            SuperMapTileSource tileSource =
                new SuperMapTileSource(this._serviceUrl, mapName,
                256, "png", scales);
            TileLayer layer = new TileLayer(tileSource);
            layer.LayerName = mapName;

            mapControl.Map = CreateMap(layer);
        }