求sharpmap如何渲染MS SQL Server等格式的GIS数据?
我现在有仓库、仓位两张表,其中仓位是属于某个仓库的。
仓位区域为灰色。
如果某个仓位区域上有可容,那么该处为黄色;如果满了,为红色;否则,为绿色。我现在如何利用这两张表和sharpmap生成一张满足需求的地图?
或者用过这两张表生成shp文件?
希望有用过sharpmap的高手能提供帮助,谢谢!

解决方案 »

  1.   

    1、加载Shapefile文件     public void LoadShapefile()
            {
                //为图层设置数据源
                string sDataFile = System.IO.Path.Combine(DATAPATH, "countries.shp");
                SharpMap.Data.Providers.ShapeFile.ShapeFileProvider oShapeFile = new SharpMap.Data.Providers.ShapeFile.ShapeFileProvider(sDataFile);
                SharpMap.Layers.ILayer oLayer = new GeometryLayer("country", oShapeFile);            //设置图层样式
                SharpMap.Styles.VectorStyle oStyle = new SharpMap.Styles.VectorStyle();
                oStyle.Fill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Chocolate);
                oStyle.Outline.BackgroundBrush = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.Blue);
                oStyle.SelectFill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.White);
                oStyle.HighlightFill = new SharpMap.Styles.SolidStyleBrush(SharpMap.Styles.StyleColor.White);
                oStyle.AreFeaturesSelectable = true;
                oLayer.Style = oStyle;            //打开数据源
                oShapeFile.Open();            //重建索引
                if (!oShapeFile.IsSpatiallyIndexed)
                    oShapeFile.RebuildSpatialIndex();            //添加图层到map中
                _map.Layers.Add(oLayer);
                this.mapControl.ZoomToExtents();
                oShapeFile.Close();
            } 2、加载PostGIS空间数据:     从PostGIS数据库中读取空间数据,利用了PostgreSqlClient类库,其操作方式和Shapefile类似           string sConn = "Server=127.0.0.1;Port=5432;User Id=postgres;Password=password;Database=PostGIS;";
               string sTableName = "t_rivers";
               string sUniqueId = "geoid";           PostGis.PostGisProvider oPostGIS = new PostGisProvider(sConn,sTableName,sUniqueId);
               SharpMap.Layers.GeometryLayer oGeometryLayer = new SharpMap.Layers.GeometryLayer("postgis", oPostGIS);       ..... ..... (下面的操作和shapefile一样) 3、加载MsSQLServer空间数据:    从MsSQLServer数据库中读取空间数据,利用了MsSqlSpatial 类库,其操作方式和Shapefile类似          string sConnStr = @"Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|GeoDatabase.mdf;Integrated Security=True;User Instance=True";          SharpMap.Data.Providers.MsSql oMsSql = new SharpMap.Data.Providers.MsSql(ConnStr, "myTable");SharpMap.Layers.GeometryLayer oGeometryLayer =  new SharpMap.Layers.GeometryLayer("postgis", oMsSql );          ..... ..... (下面的操作和shapefile一样) 4、加载OracleSpatial空间数据      string sConnStr = "Server=127.0.0.1;Port=5432;User Id=userid;Password=password;Database=myGisDb;"; 
    SharpMap.Extensions.Data.Providers.Oracle.OracleSpatialProvider dataSource = new OracleSpatialProvider(sConnStr, "myTable", "GeomColumn", "OidColumn");
      SharpMap.Layers.VectorLayer myLayer = new VectorLayer("My layer", dataSource); ..... ..... (下面的操作和shapefile一样) 5、加载MapInfo地图文件: 加载mapInfo图层利用了OGR类库  SharpMap.Layers.VectorLayer vLayerOgr = new SharpMap.Layers.VectorLayer("MapInfoLayer");
      vLayerOgr.DataSource = new SharpMap.Data.Providers.Ogr(@"D:GeoDatamyWorld.tab");..... ..... (下面的操作和shapefile一样) 6、加载栅格图片 加载栅格图片利用了OGAL类库     GdalRasterLayer layGdal = new GdalRasterLayer("Blue Marble", @"C:datasrtm30plus.tif");
         myMap.Layers.Add(layGdal);
         myMap.ZoomToExtents();