A map layer of feature labels.
Inheritance: SharpMap.Layers.FeatureLayer
Example #1
1
 public void AddLabellayer(string name, string columnName, IProvider dataProvider)
 {
     LabelLayer labelLayer = new LabelLayer(name);
     labelLayer.DataSource = dataProvider;
     labelLayer.LabelColumn = columnName;
     labelLayer.Style.CollisionDetection = true;
     //labelLayer.Style.CollisionBuffer = new SizeF(10, 10);
     labelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
     labelLayer.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
     labelLayer.Style.Font = new Font(FontFamily.GenericSansSerif, 8);
 }
Example #2
0
        /// <summary>
        /// little util wich just adds one vector layer to the map and assigns it a random theme.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="m"></param>
        public static void SetupMap(HttpContext context, Map m)
        {
            var l = new VectorLayer(
                "Countries",
                new ShapeFile(context.Server.MapPath(ConfigurationManager.AppSettings["shpfilePath"])));

            l.Style = RandomStyle.RandomVectorStyleNoSymbols();
            l.Theme = new CustomTheme<IVectorStyle>(
                delegate { return RandomStyle.RandomVectorStyleNoSymbols(); });
            m.Layers.Add(l);

            FeatureDataTable labelData = new FeatureDataTable();
            labelData.Columns.Add("Name", typeof (string));
            FeatureDataRow r = labelData.NewRow();
            r["Name"] = "My Lair";
            r.Geometry = new Point(5, 5);
            labelData.AddRow(r);

            LabelLayer labelLayer = new LabelLayer("labelLayer")
                            {
                                DataSource = new GeometryFeatureProvider(labelData),
                                Enabled = true,
                                LabelColumn = "Name",
                                Style = new LabelStyle
                                            {
                                                BackColor = new SolidBrush(Color.Black),
                                                ForeColor = Color.White,
                                                Halo = new Pen(Color.Yellow, 0.1F),
                                                CollisionDetection = false,
                                                Font = new Font("Arial", 10, GraphicsUnit.Point)
                                            }
                            };

            m.Layers.Add(labelLayer);
        }
Example #3
0
 private void setLabel(CheckBox chk, SharpMap.Layers.LabelLayer myLabel)
 {
     chk.Style.Add("font-family", myLabel.Style.Font.FontFamily.Name);
     chk.Style.Add("color", ColorToHex(myLabel.Style.ForeColor));
     chk.Style.Add("background-color", ColorToHex((myLabel.Style.BackColor as SolidBrush).Color));
     chk.Style.Add("font-weight", myLabel.Style.Font.Style.ToString());
     chk.Style.Add("font-size", myLabel.Style.Font.Size.ToString() + "px");
 }
Example #4
0
        /// <summary>
        /// Creates an instance of this class
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="map"></param>
        public FontSizeTheme(LabelLayer layer, Map map)
        {
            _labelLayer = layer;
            _map = map;

            _currentStyle = layer.Style.Clone();
            _currentSize = _currentStyle.Font.Size;
            _labelLayer.StyleChanged += HandleStyleChanged;
        }
Example #5
0
        public static Map InitializeMapOrig(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            VectorLayer layRoads = new VectorLayer("Roads");
            //Set the datasource to a shapefile in the App_data folder
            layRoads.DataSource = new ShapeFile("GeoData/World/shp_textonpath/DeMo_Quan5.shp", false);
            (layRoads.DataSource as ShapeFile).Encoding = Encoding.UTF8;
            //Set fill-style to green
            layRoads.Style.Fill = new SolidBrush(Color.Yellow);
            layRoads.Style.Line = new Pen(Color.Yellow, 4);
            //Set the polygons to have a black outline
            layRoads.Style.Outline = new Pen(Color.Black, 5); ;
            layRoads.Style.EnableOutline = true;
            layRoads.SRID = 4326;

            //Set up a country label layer
            LabelLayer layLabel = new LabelLayer("Roads labels");
            layLabel.DataSource = layRoads.DataSource;
            layLabel.Enabled = true;
            layLabel.LabelColumn = "tenduong";
            layLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
            layLabel.Style = new LabelStyle();
            layLabel.Style.ForeColor = Color.White;
            layLabel.Style.Font = new Font(FontFamily.GenericSerif, 9f, FontStyle.Bold);
            layLabel.Style.Halo = new Pen(Color.Black, 2f);
            layLabel.Style.IsTextOnPath = true;
            layLabel.Style.CollisionDetection = true;
            //layLabel.Style.BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0));
            //layLabel.MaxVisible = 90;
            //layLabel.MinVisible = 30;
            layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            layLabel.SRID = 4326;
            //layLabel.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;

          
            //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(layRoads);          
            map.Layers.Add(layLabel);        


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

            map.ZoomToExtents();

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

            return map;
        }
        private void AddSineCurveLayers(Map map, LabelLayerMode mode,
                                        LabelStyle.HorizontalAlignmentEnum hzAlign,
                                        LabelStyle.VerticalAlignmentEnum vtAlign)
        {
            string text;

            switch (mode)
            {
            case LabelLayerMode.SineCurveExtended:
                text =
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam";    //", quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
                break;

            default:
                text = "Lorem ipsum olor sit amet, consectetur adipisici elit";
                break;
            }

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

            fdt.BeginInit();
            fdt.Columns.Add(new System.Data.DataColumn("ID", typeof(int)));
            fdt.Columns.Add(new System.Data.DataColumn("LABEL", typeof(string)));
            fdt.PrimaryKey = new[] { fdt.Columns[0] };
            fdt.EndInit();
            fdt.BeginLoadData();
            var fdr = (SharpMap.Data.FeatureDataRow)fdt.LoadDataRow(new object[] { 1, text }, true);

            fdr.Geometry = CreateSineLine(new GeoAPI.Geometries.Coordinate(10, 10));
            fdt.EndLoadData();

            var vLyr = new SharpMap.Layers.VectorLayer("Geometry", new GeometryFeatureProvider(fdt));

            vLyr.Style.Line    = new System.Drawing.Pen(System.Drawing.Color.Black, 4);
            vLyr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            vLyr.SRID          = map.SRID;
            map.Layers.Add(vLyr);

            var lLyr = new SharpMap.Layers.LabelLayer("Label")
            {
                DataSource = vLyr.DataSource, LabelColumn = "LABEL"
            };

            lLyr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            lLyr.Style.ForeColor   = System.Drawing.Color.Cyan;
            lLyr.Style.BackColor   = new SolidBrush(Color.FromArgb(128, Color.LightSlateGray));
            //lLyr.Style.Halo = new Pen(Color.Yellow, 4);
            lLyr.Style.IgnoreLength        = mode == LabelLayerMode.SineCurveExtended;
            lLyr.Style.HorizontalAlignment = hzAlign;
            lLyr.Style.VerticalAlignment   = vtAlign;
            //ll.Style.IsTextOnPath = textOnPath;
            map.Layers.Add(lLyr);
        }
Example #7
0
    public static SharpMap.Map InitializeWmsMap(System.Drawing.Size size)
    {
        HttpContext.Current.Trace.Write("Initializing Wms map...");

        //Initialize a new map of size 'imagesize'
        SharpMap.Map             map    = new SharpMap.Map(size);
        SharpMap.Layers.WmsLayer layWms = GetWmsLayer();
        //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(HttpContext.Current.Server.MapPath(@"~\App_data\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.Yellow;
        layCountries.Style.EnableOutline = true;
        layCountries.SRID = 4326;

        //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, 8);
        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;

        //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(layWms);
        map.Layers.Add(layCountries);
        map.Layers.Add(layLabel);

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

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

        HttpContext.Current.Trace.Write("Map initialized");
        return(map);
    }
Example #8
0
 public static LabelLayer CreateLabelLayer(VectorLayer originalLayer, string labelColumnName)
 {
     SharpMap.Layers.LabelLayer labelLayer = new SharpMap.Layers.LabelLayer(originalLayer.LayerName + ":Labels");
     labelLayer.DataSource  = originalLayer.DataSource;
     labelLayer.LabelColumn = labelColumnName;
     labelLayer.Style.CollisionDetection = true;
     labelLayer.Style.CollisionBuffer    = new SizeF(10F, 10F);
     labelLayer.LabelFilter  = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
     labelLayer.Style.Offset = new PointF(0, -5F);
     labelLayer.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.CommonCenter;
     labelLayer.Style.Font               = new Font(FontFamily.GenericSansSerif, 12);
     labelLayer.MaxVisible               = originalLayer.MaxVisible;
     labelLayer.MinVisible               = originalLayer.MinVisible;
     labelLayer.Style.Halo               = new Pen(Color.White, 2);
     labelLayer.SmoothingMode            = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     labelLayer.CoordinateTransformation = originalLayer.CoordinateTransformation;
     return(labelLayer);
 }
Example #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Set up the map. We use the method in the App_Code folder for initializing the map
        myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

        SharpMap.Layers.VectorLayer GeomLayer = this.CreateGeometryLayer();

        SharpMap.Layers.LabelLayer layGeomProviderLabel = new SharpMap.Layers.LabelLayer("LabelOfTheCityMayence");
        layGeomProviderLabel.DataSource = GeomLayer.DataSource;
        layGeomProviderLabel.Enabled = true;
        layGeomProviderLabel.LabelColumn = "Name";
        layGeomProviderLabel.Style = new SharpMap.Styles.LabelStyle();
        layGeomProviderLabel.Style.ForeColor = System.Drawing.Color.AliceBlue;
        layGeomProviderLabel.Style.Font = new System.Drawing.Font("ArialB", 14);
        layGeomProviderLabel.Style.Offset = new System.Drawing.PointF(4, 4);
        layGeomProviderLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
        layGeomProviderLabel.Style.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
        layGeomProviderLabel.SRID = 4326;

        myMap.Layers.Add(GeomLayer);
        myMap.Layers.Add(layGeomProviderLabel);

        myMap.Center = new SharpMap.Geometries.Point(8, 50);
        myMap.Zoom = 10;


        if (Page.IsPostBack)
        {
            //Page is post back. Restore center and zoom-values from viewstate
            myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];
            myMap.Zoom = (double)ViewState["mapZoom"];

        }
        else
        {
            //This is the initial view of the map. Zoom to the extents of the map:
            //myMap.ZoomToExtents();
            //or center on 0,0 and zoom to full earth (360 degrees)
            //myMap.Center = new SharpMap.Geometries.Point(0,0);
            //myMap.Zoom = 360;
            //Create the map
            GenerateMap();
        }
    }
        private Map CreateMap()
        {
            var map = new Map(ClientSize);

            //var p1 = new MatrixRelationProvider(_matrix) { ScaleFactor = 0.1d, ScaleMethod = ScaleMethod.Linear };
            //map.Layers.Add(new VectorLayer(p1.ProviderName, p1)
            //{
            //    Style =
            //        new VectorStyle { Outline = new Pen(Brushes.Black, 1), Fill = new SolidBrush(Color.DarkSalmon), EnableOutline = true }
            //});

            var p2 = new MatrixRelationProvider(_matrix) { ScaleFactor = 0.1d, ScaleMethod = ScaleMethod.Linear, RestrictId = 1 };
            map.Layers.Add(new VectorLayer(p2.ProviderName, p2)
            {
                Style =
                    new VectorStyle { Outline = new Pen(Brushes.Black, 1), Fill = new SolidBrush(Color.BlueViolet), EnableOutline = true }
            });

            var p3 = new MatrixODSumProvider(_matrix, ODMatrixVector.Both) { ScaleFactor = 0.1d, ScaleMethod = ScaleMethod.Linear };
            map.Layers.Add(new VectorLayer(p3.ProviderName, p3)
                               {
                                   Style =
                                       new VectorStyle { Outline = new Pen(Brushes.Black, 1), Fill = new SolidBrush(Color.DarkSeaGreen), EnableOutline = true }
                               });

            var ll = new LabelLayer(string.Format("Label {0}", p3.ProviderName));
            ll.DataSource = p3;
            ll.LabelStringDelegate = d => string.Format("Oid:{0}\nVal:{1:n}", d[0], d[1]);
            ll.Style.Halo = Pens.AliceBlue;
            ll.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            ll.PriorityColumn = "Value";
            ll.Style.CollisionBuffer = new SizeF(2, 2);
            ll.Style.CollisionDetection = true;
            map.Layers.Add(ll);

            //var extent = map.GetExtents();
            var center = _matrix[1];

            var box = center.EnvelopeInternal;
            box.ExpandBy(25);
            map.ZoomToBox(box);
            return map;
        }
Example #11
0
        public void MultiLineCenterAlignedTest()
        {
            using (var m = new SharpMap.Map(new Size(600, 400)))
            {
                m.BackColor = Color.SeaShell;
                //_featureDataTable.Clear();
                var gfp = new GeometryFeatureProvider(_featureDataTable);
                var vl = new VectorLayer("VL", gfp);
                var ll = new LabelLayer("MultiLineCenterAligned") {DataSource = gfp};
                ll.Theme = CreateTheme();
                ll.LabelColumn = "LABEL";
                m.Layers.Add(vl);
                m.Layers.Add(ll);

                m.ZoomToExtents();
                using (var mapImage = m.GetMap())
                    mapImage.Save("MultiLineCenterAligned.png", ImageFormat.Png);
            }
        }
Example #12
0
 private static LabelLayer CrearCapaEtiq(VectorLayer capaBase)
 {
     if (!(capaBase == null))
     {
         LabelLayer capaEtiq = new SharpMap.Layers.LabelLayer(NOMCAPA_ETIQUETAS);
         capaEtiq.DataSource          = capaBase.DataSource;
         capaEtiq.LabelStringDelegate = delegate(SharpMap.Data.FeatureDataRow fdr)
         { return(fdr["codigo"].ToString().Substring(6)); };
         capaEtiq.Style = new SharpMap.Styles.LabelStyle();
         capaEtiq.Style.CollisionDetection = true;
         capaEtiq.Style.CollisionBuffer    = new SizeF(10, 10);
         capaEtiq.Style.ForeColor          = Color.Black;
         capaEtiq.Style.Font = new Font(FontFamily.GenericSerif, 8);
         capaEtiq.MaxVisible = 180;
         capaEtiq.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
         return(capaEtiq);
     }
     else
     {
         return(null);
     }
 }
Example #13
0
 public static LabelLayer CreateLabelLayer(VectorLayer src, string column)
 {
     string name = String.Format("{0}:Labels", src.LayerName);
     LabelLayer layer = new LabelLayer(name)
         {
             DataSource = src.DataSource,
             LabelColumn = column,
             LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
             MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.CommonCenter,
             MaxVisible = src.MaxVisible,
             MinVisible = src.MinVisible,
             Style =
                 {
                     CollisionDetection = true,
                     CollisionBuffer = new SizeF(10F, 10F),
                     Offset = new PointF(0, -5F),
                     Font = new Font(FontFamily.GenericSansSerif, 12),
                     Halo = new Pen(Color.White, 2)
                 },
             SmoothingMode = SmoothingMode.HighQuality,
             CoordinateTransformation = src.CoordinateTransformation
         };
     return layer;
 }
Example #14
0
        private static Map InitializeMapWithSymbolizerLayers(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            var layCountries = new SharpMap.Layers.Symbolizer.PolygonalVectorLayer(
                "Countries",
                new ShapeFileEx("GeoData/World/countries.shp", true),
                new BasicPolygonSymbolizer {Fill = new SolidBrush(Color.Green), Outline = Pens.Black,}
                ) {SRID = 4326};

            //Set up a river layer
            var symbolizer = new CachedLineSymbolizer();
            symbolizer.LineSymbolizeHandlers.AddRange( new [] {
                new PlainLineSymbolizeHandler { Line = new Pen(Color.Blue, 3) { LineJoin = LineJoin.Round } },
                new PlainLineSymbolizeHandler{ Line = new Pen(Color.Aqua, 1)}, });

            var layRivers = new SharpMap.Layers.Symbolizer.LinealVectorLayer("Rivers")
                                {
                                    //Set the datasource to a shapefile in the App_data folder
                                    DataSource = new ShapeFileEx("GeoData/World/rivers.shp", true),
                                    //Define a blue 2px wide pen
                                    Symbolizer = symbolizer,
                                    SRID = 4326
                                };

            //Set up a cities layer
            var layCities = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("Cities")
                                {
                                    //Set the datasource to a shapefile in the App_data folder
                                    DataSource = new ShapeFileEx("GeoData/World/cities.shp", true),
                                    Symbolizer = new RasterPointSymbolizer() { Scale = 0.8f },
                                    MaxVisible = 40
                                } ;

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

                               };

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

            //Setup River label
            var layRiverLabel = new LabelLayer("River labels")
                                   {
                                       DataSource = layRivers.DataSource,
                                       Enabled = true,
                                       LabelColumn = "Name",
                                       TextRenderingHint = TextRenderingHint.AntiAlias,
                                       SmoothingMode = SmoothingMode.AntiAlias,
                                       SRID = 4326,
                                       LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
                                       MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.All,
                                       Style =
                                           new LabelStyle
                                               {
                                                   ForeColor = Color.DarkBlue,
                                                   Font = new Font("Arial", 11),
                                                   HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
                                                   VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Middle,
                                                   //CollisionDetection = true,
                                                   Halo = new Pen(Color.Azure, 2), 
                                                   IgnoreLength =  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(layRiverLabel);
            map.Layers.Add(layLabel);
            map.Layers.Add(layCityLabel);


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

            map.Zoom = 360;
            map.Center = new Point(0, 0);

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

            return map;
        }
Example #15
0
    public static Map InitializeMapPostGis(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        string connectionString = ConfigurationManager.ConnectionStrings["postgis"].ConnectionString;

        //Initialize a new map of size 'imagesize'
        SharpMap.Map map = new SharpMap.Map(size);

        //Set up the countries layer
        SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
        //Set the datasource to a new MsSqlSpatialProvider
        layCountries.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "countries", "wkb_geometry", "ogc_fid");

        //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;

        //Set up a river layer
        SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
        //Set the datasource to a new MsSqlSpatialProvider
        layRivers.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "rivers", "wkb_geometry", "ogc_fid");
        //Define a blue 1px wide pen
        layRivers.Style.Line = new Pen(Color.Blue, 1);

        //Set up a river layer
        SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
        //Set the datasource to a new MsSqlSpatialProvider
        layCities.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "cities", "wkb_geometry", "ogc_fid");;
        //Define a blue 1px wide pen
        //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        layCities.Style.SymbolScale = 0.8f;
        layCities.MaxVisible        = 40;

        //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.MaxVisible  = 90;
        layLabel.MinVisible  = 30;
        layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
        layLabel.LabelFilter               = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
        layLabel.PriorityColumn            = "popdens";
        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.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
        layLabel.Style.CollisionDetection  = true;

        //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.PriorityColumn   = "population";
        layCityLabel.PriorityDelegate = delegate(SharpMap.Data.FeatureDataRow fdr)
        {
            Int32 retVal = 10000000 * (Int32)((String)fdr["capital"] == "Y" ? 1 : 0);
            return(retVal + Convert.ToInt32(fdr["population"]));
        };
        layCityLabel.TextRenderingHint         = System.Drawing.Text.TextRenderingHint.AntiAlias;
        layCityLabel.SmoothingMode             = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        layCityLabel.LabelFilter               = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
        layCityLabel.Style                     = new SharpMap.Styles.LabelStyle();
        layCityLabel.Style.ForeColor           = Color.Black;
        layCityLabel.Style.Font                = new Font(FontFamily.GenericSerif, 11);
        layCityLabel.Style.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.Style.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   = Color.LightBlue;

        map.Zoom   = 360;
        map.Center = new Point(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return(map);
    }
Example #16
0
        private void optSpatial_Click(object sender, EventArgs e)
        {
            // reset map layers
            MapBox.Map.Layers.Clear();

            SharpMap.Layers.VectorLayer spatialLyr;

            string spatialTable;
            string geomColumn;
            SqlServerSpatialObjectType geomType;
            Brush symBrush;

            if (optSpatialGeog.Checked)
            {
                spatialTable  = SqlServerSample.GeogTable;
                geomColumn    = "Geog4326";
                geomType      = SqlServerSpatialObjectType.Geography;
                symBrush      = new SolidBrush(optDataProviderWKB.Checked ? Color.Orange : Color.DeepSkyBlue);
                labTable.Text = "Table: " + SqlServerSample.GeogTable;
            }
            else
            {
                // ensure checked
                optSpatialGeom.Checked = true;
                spatialTable           = SqlServerSample.GeomTable;
                geomColumn             = "Geom4326";
                geomType      = SqlServerSpatialObjectType.Geometry;
                symBrush      = new SolidBrush(optDataProviderWKB.Checked ? Color.Red : Color.DodgerBlue);
                labTable.Text = "Table: " + SqlServerSample.GeomTable;

                chkSpatialValidate.Enabled = true;
            }

            spatialLyr = new SharpMap.Layers.VectorLayer("Spatial");
            if (optDataProviderWKB.Checked)
            {
                spatialLyr.DataSource = new SqlServer2008(ConnectionString, spatialTable, geomColumn, "Id", geomType, 4326, SqlServer2008ExtentsMode.QueryIndividualFeatures);
            }
            else
            {
                spatialLyr.DataSource = new SqlServer2008Ex(ConnectionString, spatialTable, geomColumn, "Id", geomType, 4326, SqlServer2008ExtentsMode.QueryIndividualFeatures);
            }

            spatialLyr.SRID       = spatialLyr.DataSource.SRID;
            spatialLyr.TargetSRID = 3857;

            spatialLyr.Style.PointColor = symBrush;

            //Set up a label layer
            var labelLyr = new SharpMap.Layers.LabelLayer("Labels")
            {
                DataSource = spatialLyr.DataSource,
                //SRID=4326,
                TargetSRID  = 3857,
                Enabled     = true,
                LabelColumn = "Name",
                //MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest,
                LabelFilter = SharpMap.Rendering.LabelCollisionDetection.QuickAccurateCollisionDetectionMethod,
                Style       = new SharpMap.Styles.LabelStyle()
                {
                    ForeColor = System.Drawing.Color.DarkSlateGray,
                    Font      = new System.Drawing.Font(System.Drawing.FontFamily.GenericSerif, 8),
                    //BackColor = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(128, 255, 0, 0)),
                    HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left,
                    CollisionDetection  = true,
                    Offset = new PointF(10, 0)
                             //MaxVisible = 90,
                             //MinVisible = 30
                }
            };


            MapBox.Map.Layers.Add(spatialLyr);
            MapBox.Map.Layers.Add(labelLyr);

            // configure data provider options
            chkSpatialValidate_Click(null, null);
            optExtents_Click(null, null);
            chkHints_Click(null, null);
            optDefQuery_Click(null, null);

            MapBox.Refresh();
        }
Example #17
0
    public static Map InitializeMapOgr(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        Map map = new Map(size);

        //Set up the countries layer
        VectorLayer layCountries = new VectorLayer("Countries");
        //Set the datasource to a shapefile in the App_data folder
        try
        {
            layCountries.DataSource =
                new Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\countriesMapInfo.tab"));
        }
        catch (TypeInitializationException ex)
        {
            if (ex.GetType() == typeof (TypeInitializationException))
                throw new Exception(
                    "Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.");
        }
        catch (Exception ex)
        {
            throw;
        }

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

        //Set up a river layer
        VectorLayer layRivers = new VectorLayer("Rivers");
        //Set the datasource to a shapefile in the App_data folder
        layRivers.DataSource = new Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\riversMapInfo.tab"));
        //Define a blue 1px wide pen
        layRivers.Style.Line = new Pen(Color.Blue, 1);
        layRivers.SRID = 4326;

        //Set up a river layer
        VectorLayer layCities = new VectorLayer("Cities");
        //Set the datasource to a shapefile in the App_data folder
        layCities.DataSource = new Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\citiesMapInfo.tab"));
        //Define a blue 1px wide pen
        //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        layCities.Style.SymbolScale = 0.8f;
        layCities.MaxVisible = 40;
        layCities.SRID = 4326;

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

        //Set up a city label layer
        LabelLayer layCityLabel = new LabelLayer("City labels");
        layCityLabel.DataSource = layCities.DataSource;
        layCityLabel.Enabled = true;
        layCityLabel.LabelColumn = "Name";
        layCityLabel.Style = new LabelStyle();
        layCityLabel.Style.ForeColor = Color.Black;
        layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
        layCityLabel.MaxVisible = layLabel.MinVisible;
        layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
        layCityLabel.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;
        layCityLabel.Style.Offset = new PointF(3, 3);
        layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
        layCityLabel.TextRenderingHint = TextRenderingHint.AntiAlias;
        layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
        layCityLabel.SRID = 4326;
        layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
        layCityLabel.Style.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 = Color.LightBlue;

        map.ZoomToExtents(); // = 360;
        map.Center = new Point(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return map;
    }
Example #18
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;
        }
Example #19
0
        public static SharpMap.Map GetMapForProviders(IEnumerable<SharpMap.Data.Providers.IProvider> providers)
        {
            var m = new SharpMap.Map();
            foreach (var provider in providers)
            {
                var l = new VectorLayer(provider.ConnectionID, provider)
                            {
                                Style = GetRandomVectorStyle(),
                                IsQueryEnabled = true
                                
                            };
                if (provider.GetFeatureCount() > 50000)
                    m.BackgroundLayer.Add(AsyncLayerProxyLayer.Create(l, new Size(256, 128)));
                else    
                m.Layers.Add(l);

                if (provider.GetFeatureCount() < 50000)
                {
                var ll = new LabelLayer("Label " + provider.ConnectionID);
                ll.DataSource = provider;
                
                provider.Open();
                var f = provider.GetFeature(1);
                provider.Close();

                    ll.LabelColumn = f.Table.Columns[0].ColumnName;
                ll.Style.CollisionDetection = false;
                ll.Style.IgnoreLength = true;
                
                m.Layers.Add(ll);
            }
            }
            m.ZoomToExtents();
            return m;
        }
Example #20
0
        public static Map InitializeMap(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

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

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

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

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

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

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

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

            LabelLayer layRiverLabels = new LabelLayer("RiverLabels");
            layRiverLabels.DataSource = layRivers.DataSource;
            layRiverLabels.LabelColumn = "Name";
            layRiverLabels.PriorityDelegate = GetRiverLength;
            layRiverLabels.Style = new LabelStyle
                                       {
                                           Font = new Font("Arial", 10, FontStyle.Bold),
                                           Halo = new Pen(Color.Azure, 2),
                                           ForeColor = Color.DarkCyan,
                                           IgnoreLength = true,
                                           Enabled = true,
                                           CollisionDetection = true,
                                          
                                       };
            layRiverLabels.LabelFilter = 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 = Color.LightBlue;

            map.ZoomToExtents(); // = 360;

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

        }
Example #21
0
        public static Map GetMapForProviders(IEnumerable<IProvider> providers)
        {
            Map m = new Map();
            foreach (IProvider provider in providers)
            {
                VectorLayer l = new VectorLayer(provider.ConnectionID, provider)
                            {
                                Style = GetRandomVectorStyle()
                            };
                m.Layers.Add(l);
                LabelLayer ll = new LabelLayer("Label " + provider.ConnectionID);
                ll.DataSource = provider;

                provider.Open();
                IFeature f = provider.GetFeatureByOid(1);
                provider.Close();

                ll.LabelColumn = f.Factory.AttributesDefinition[1].AttributeName;
                ll.Style.CollisionDetection = false;
                ll.Style.IgnoreLength = true;

                m.Layers.Add(ll);
            }
            m.ZoomToExtents();
            return m;
        }
        public static Map InitializeMap(float angle)
        {
            //Initialize a new map based on the simple map
            Map map = new Map();

            //Set up countries layer
            VectorLayer layCountries = new VectorLayer("Countries");
            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new 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 = Pens.Black;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4326;
            map.Layers.Add(layCountries);

            //set up cities layer
            VectorLayer layCities = new VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource = new 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
            LabelLayer layLabel = new LabelLayer("Country labels");
            layLabel.DataSource = layCountries.DataSource;
            layLabel.Enabled = true;
            layLabel.LabelColumn = "Name";
            layLabel.Style = new LabelStyle();
            layLabel.Style.ForeColor = Color.White;
            layLabel.Style.Font = new Font(FontFamily.GenericSerif, 12);
            layLabel.Style.BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0));
            layLabel.MaxVisible = 90;
            layLabel.MinVisible = 30;
            layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
            layLabel.SRID = 4326;
            layLabel.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;
            map.Layers.Add(layLabel);

            //Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels");
            layCityLabel.DataSource = layCities.DataSource;
            layCityLabel.Enabled = true;
            layCityLabel.LabelColumn = "Name";
            layCityLabel.Style = new LabelStyle();
            layCityLabel.Style.ForeColor = Color.Black;
            layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
            layCityLabel.MaxVisible = layLabel.MinVisible;
            layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
            layCityLabel.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;
            layCityLabel.Style.Offset = new PointF(3, 3);
            layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
            layCityLabel.TextRenderingHint = TextRenderingHint.AntiAlias;
            layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
            layCityLabel.SRID = 4326;
            layCityLabel.LabelFilter = 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 = 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.MaximumExtents = new Envelope(-20, 70, -65, 80);
            map.MaximumZoom = 30;

            map.Zoom = 20;
            map.Center = new Point(0, 0);

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

            return map;
        }
Example #23
0
        private static Map InitializeMapinfo(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            VectorLayer layCountries = new VectorLayer("Countries");
            //Set the datasource to a shapefile in the App_data folder
            try
            {
                layCountries.DataSource = new Ogr("GeoData/MapInfo/countriesMapInfo.tab");
            }
            catch (TypeInitializationException ex)
            {
                if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' 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/",
                            GdalRasterLayer.FWToolsVersion));
                }
                throw;
            }

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

            //Set up a river layer
            VectorLayer layRivers = new VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new Ogr("GeoData/MapInfo/riversMapInfo.tab");
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 1);
            layRivers.SRID = 4326;

            //Set up a river layer
            VectorLayer layCities = new VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource = new Ogr("GeoData/MapInfo/citiesMapInfo.tab");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible = 40;
            layCities.SRID = 4326;

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

            //Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels");
            layCityLabel.DataSource = layCities.DataSource;
            layCityLabel.Enabled = true;
            layCityLabel.LabelColumn = "Name";
            layCityLabel.Style = new LabelStyle();
            layCityLabel.Style.ForeColor = Color.Black;
            layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
            layCityLabel.MaxVisible = layLabel.MinVisible;
            layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
            layCityLabel.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;
            layCityLabel.Style.Offset = new PointF(3, 3);
            layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
            layCityLabel.TextRenderingHint = TextRendering.AntiAlias;
            layCityLabel.SmoothingMode = Smoothing.AntiAlias;
            layCityLabel.SRID = 4326;
            layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
            layCityLabel.Style.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 = Color.LightBlue;

            map.ZoomToExtents(); // = 360;
            map.Center = new Point(0, 0);

            _ogrSampleDataset = "MapInfo";

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

            return map;
        }
Example #24
0
    public static Map InitializeWmsMap(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing Wms map...");

            //Initialize a new map of size 'imagesize'
        Map map = new Map(size);
        WmsLayer layWms = GetWmsLayer();

        //Set up the countries layer
        VectorLayer layCountries = new VectorLayer("Countries");
            //Set the datasource to a shapefile in the App_data folder
        layCountries.DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\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 = Pens.Yellow;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4326;

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

            //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(layWms);
            map.Layers.Add(layCountries);
            map.Layers.Add(layLabel);

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

            map.Zoom = 360;
        map.Center = new Point(0, 0);

            HttpContext.Current.Trace.Write("Map initialized");
            return map;
    }
Example #25
0
        private static Map InitializeMapSharpDX(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            VectorLayer layCountries = new SharpDXVectorLayer("Countries");
            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new ShapeFile("GeoData/World/countries.shp", true);
            //Set fill-style to green
            layCountries.Style.Fill = new SolidBrush(Color.FromArgb(64, Color.LimeGreen));
            //Set the polygons to have a black outline
            layCountries.Style.Outline = Pens.Black;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4326;

            //Set up a river layer
            VectorLayer layRivers = new SharpDXVectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new ShapeFile("GeoData/World/rivers.shp", true);
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 1);
            layRivers.SRID = 4326;

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

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

            //Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels");
            layCityLabel.DataSource = layCities.DataSource;
            layCityLabel.Enabled = true;
            layCityLabel.LabelColumn = "Name";
            layCityLabel.Style = new LabelStyle();
            layCityLabel.Style.ForeColor = Color.Black;
            layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
            layCityLabel.MaxVisible = layLabel.MinVisible;
            layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
            layCityLabel.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;
            layCityLabel.Style.Offset = new PointF(3, 3);
            layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
            layCityLabel.TextRenderingHint = TextRenderingHint.AntiAlias;
            layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
            layCityLabel.SRID = 4326;
            layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
            layCityLabel.Style.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.BackgroundLayer.Add(AsyncLayerProxyLayer.Create(layCountries));
            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 = Color.LightBlue;

            map.Zoom = 360;
            map.Center = new Point(0, 0);

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

            return map;
        }
Example #26
0
 public static LabelLayer CreateLabelLayer(VectorLayer originalLayer, string labelColumnName)
 {
     SharpMap.Layers.LabelLayer labelLayer = new SharpMap.Layers.LabelLayer(originalLayer.LayerName + ":Labels");
     labelLayer.DataSource = originalLayer.DataSource;
     labelLayer.LabelColumn = labelColumnName;
     labelLayer.Style.CollisionDetection = true;
     labelLayer.Style.CollisionBuffer = new SizeF(10F, 10F);
     labelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
     labelLayer.Style.Offset = new PointF(0, -5F);
     labelLayer.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.CommonCenter;
     labelLayer.Style.Font = new Font(FontFamily.GenericSansSerif, 12);
     labelLayer.MaxVisible = originalLayer.MaxVisible;
     labelLayer.MinVisible = originalLayer.MinVisible;
     labelLayer.Style.Halo = new Pen(Color.White, 2);
     labelLayer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     labelLayer.CoordinateTransformation = originalLayer.CoordinateTransformation;
     return labelLayer;
 }
Example #27
0
    public static SharpMap.Map InitializeMapOgr(System.Drawing.Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        //Initialize a new map of size 'imagesize'
        SharpMap.Map map = new SharpMap.Map(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
        try
        {
            layCountries.DataSource = new SharpMap.Data.Providers.Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\countriesMapInfo.tab"));
        }
        catch (Exception ex)
        {
            if (ex.GetType() == typeof(TypeInitializationException))
            {
                throw new Exception("Please copy the umanaged dll's into your bin folder from javascript:window.location.href='http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Extensions';.");
            }
        }

        //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;

        //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.Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\riversMapInfo.tab"));
        //Define a blue 1px wide pen
        layRivers.Style.Line = new Pen(Color.Blue, 1);
        layRivers.SRID       = 4326;

        //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.Ogr(HttpContext.Current.Server.MapPath(@"~\App_data\MapInfo\citiesMapInfo.tab"));
        //Define a blue 1px wide pen
        //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        layCities.Style.SymbolScale = 0.8f;
        layCities.MaxVisible        = 40;
        layCities.SRID = 4326;

        //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;

        //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;

        //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   = Color.LightBlue;

        map.ZoomToExtents(); // = 360;
        map.Center = new SharpMap.Geometries.Point(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return(map);
    }
Example #28
0
        public static Map InitializeMap(float angle)
        {
            try
            {
                // WARNING
                // This sample needs the GeoServer WFS running on your local machine. 
                // It uses the GeoServer default sample data. Installing and starting it is all you need to do
                // http://docs.codehaus.org/display/GEOS/Download

                // Sample by Peter Robineau

                const string getCapabilitiesURI = "http://localhost:8080/geoserver/wfs";
                const string serviceURI = "http://localhost:8080/geoserver/wfs";

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

                VectorLayer layer1 = new VectorLayer("States");
                VectorLayer layer2 = new VectorLayer("SelectedStatesAndHousholds");
                VectorLayer layer3 = new VectorLayer("New Jersey");
                VectorLayer layer4 = new VectorLayer("Roads");
                VectorLayer layer5 = new VectorLayer("Landmarks");
                VectorLayer layer6 = new VectorLayer("Poi");

                // Demo data from Geoserver 1.5.3 and Geoserver 1.6.0 

                WFS prov1 = new WFS(getCapabilitiesURI, "topp", "states", WFS.WFSVersionEnum.WFS1_0_0);

                // Bypass 'GetCapabilities' and 'DescribeFeatureType', if you know all necessary metadata.
                WfsFeatureTypeInfo featureTypeInfo = new WfsFeatureTypeInfo(serviceURI, "topp", null, "states",
                                                                            "the_geom");
                // 'WFS.WFSVersionEnum.WFS1_1_0' supported by Geoserver 1.6.x
                WFS prov2 = new WFS(featureTypeInfo, WFS.WFSVersionEnum.WFS1_1_0);
                // Bypass 'GetCapabilities' and 'DescribeFeatureType' again...
                // It's possible to specify the geometry type, if 'DescribeFeatureType' does not...(.e.g 'GeometryAssociationType')
                // This helps to accelerate the initialization process in case of unprecise geometry information.
                WFS prov3 = new WFS(serviceURI, "topp", "http://www.openplans.org/topp", "states", "the_geom",
                                    GeometryTypeEnum.MultiSurfacePropertyType, WFS.WFSVersionEnum.WFS1_1_0);

                // Get data-filled FeatureTypeInfo after initialization of dataprovider (useful in Web Applications for caching metadata.
                WfsFeatureTypeInfo info = prov1.FeatureTypeInfo;

                // Use cached 'GetCapabilities' response of prov1 (featuretype hosted by same service).
                // Compiled XPath expressions are re-used automatically!
                // If you use a cached 'GetCapabilities' response make sure the data provider uses the same version of WFS as the one providing the cache!!!
                WFS prov4 = new WFS(prov1.GetCapabilitiesCache, "tiger", "tiger_roads", WFS.WFSVersionEnum.WFS1_0_0);
                WFS prov5 = new WFS(prov1.GetCapabilitiesCache, "tiger", "poly_landmarks", WFS.WFSVersionEnum.WFS1_0_0);
                WFS prov6 = new WFS(prov1.GetCapabilitiesCache, "tiger", "poi", WFS.WFSVersionEnum.WFS1_0_0);
                // Clear cache of prov1 - data providers do not have any cache, if they use the one of another data provider  
                prov1.GetCapabilitiesCache = null;

                //Filters
                IFilter filter1 = new PropertyIsEqualToFilter_FE1_1_0("STATE_NAME", "California");
                IFilter filter2 = new PropertyIsEqualToFilter_FE1_1_0("STATE_NAME", "Vermont");
                IFilter filter3 = new PropertyIsBetweenFilter_FE1_1_0("HOUSHOLD", "600000", "4000000");
                IFilter filter4 = new PropertyIsLikeFilter_FE1_1_0("STATE_NAME", "New*");

                // SelectedStatesAndHousholds: Green
                OGCFilterCollection filterCollection1 = new OGCFilterCollection();
                filterCollection1.AddFilter(filter1);
                filterCollection1.AddFilter(filter2);
                OGCFilterCollection filterCollection2 = new OGCFilterCollection();
                filterCollection2.AddFilter(filter3);
                filterCollection1.AddFilterCollection(filterCollection2);
                filterCollection1.Junctor = OGCFilterCollection.JunctorEnum.Or;
                prov2.OGCFilter = filterCollection1;

                // Like-Filter('New*'): Bisque
                prov3.OGCFilter = filter4;

                // Layer Style
                layer1.Style.Fill = new SolidBrush(Color.IndianRed); // States
                layer2.Style.Fill = new SolidBrush(Color.Green); // SelectedStatesAndHousholds
                layer3.Style.Fill = new SolidBrush(Color.Bisque); // e.g. New York, New Jersey,...
                layer5.Style.Fill = new SolidBrush(Color.LightBlue);

                // Labels
                // Labels are collected when parsing the geometry. So there's just one 'GetFeatureByOid' call necessary.
                // Otherwise (when calling twice for retrieving labels) there may be an inconsistent read...
                // If a label property is set, the quick geometry option is automatically set to 'false'.
                prov3.Label = "STATE_NAME";
                LabelLayer layLabel = new LabelLayer("labels");
                layLabel.DataSource = prov3;
                layLabel.Enabled = true;
                layLabel.LabelColumn = prov3.Label;
                layLabel.Style = new LabelStyle();
                layLabel.Style.CollisionDetection = false;
                layLabel.Style.CollisionBuffer = new SizeF(5, 5);
                layLabel.Style.ForeColor = Color.Black;
                layLabel.Style.Font = new Font(FontFamily.GenericSerif, 10);
                layLabel.MaxVisible = 90;
                layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
                // 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;

                // Quick geometries
                // We need this option for prov2 since we have not passed a featuretype namespace
                prov2.QuickGeometries = true;
                prov4.QuickGeometries = true;
                prov5.QuickGeometries = true;
                prov6.QuickGeometries = true;

                layer1.DataSource = prov1;
                layer2.DataSource = prov2;
                layer3.DataSource = prov3;
                layer4.DataSource = prov4;
                layer5.DataSource = prov5;
                layer6.DataSource = prov6;

                map.Layers.Add(layer1);
                map.Layers.Add(layer2);
                map.Layers.Add(layer3);
                map.Layers.Add(layer4);
                map.Layers.Add(layer5);
                map.Layers.Add(layer6);
                map.Layers.Add(layLabel);

                map.Center = new Point(-74.0, 40.7);
                map.Zoom = 10;
                // Alternatively zoom closer
                // demoMap.Zoom = 0.2;

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

                return map;
            }
            catch (WebException ex)
            {
                if ((ex.Message.Contains("(502) Bad Gateway")) ||
                    (ex.Message.Contains("Unable to connect to the remote server")))
                {
                    throw new Exception(
                        "The Wfs sample threw an exception. You probably need to install the GeoServer WFS to your local machine. You can get it from here: http://docs.codehaus.org/display/GEOS/Download. The exception message was: " +
                        ex.Message);
                }
                else throw;
            }
        }
Example #29
0
        public static Map InitializeMap(float angle)
        {
            //Initialize a new map of size 'imagesize'
            Map map = new Map();

            //Set up the countries layer
            VectorLayer layCountries = new VectorLayer("OracleSample");

            //Set the datasource to a shapefile in the App_data folder
            layCountries.DataSource = new SharpMap.Data.Providers.OracleProvider("system", "metsys", "127.0.0.1",
                                                                         "COUNTRIES", "GEOM", "ID");
            //System.Diagnostics.Debug.WriteLine(layCountries.DataSource.GetGeometryByOid(101).ToString());

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

            //Set up a river layer
            VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
            layRivers.DataSource = new SharpMap.Data.Providers.OracleProvider("system", "metsys", "127.0.0.1", "RIVERS", "GEOM", "ID");
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 1);

            //Set up a river layer
            VectorLayer layCities = new VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
            layCities.DataSource = new SharpMap.Data.Providers.OracleProvider("system", "metsys", "127.0.0.1", "CITIES", "GEOM", "ID");
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible = 40;

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

            ////Set up a city label layer
            LabelLayer layCityLabel = new LabelLayer("City labels")
            {
                DataSource = layCities.DataSource,
                Enabled = true,
                LabelColumn = "NAME",
                PriorityColumn = "POPULATION",
                PriorityDelegate = delegate(GeoAPI.Features.IFeature fdr)
                {
                    Int32 retVal = 10000000 * ((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 LabelStyle()
                {
                    ForeColor = Color.Black,
                    Font = new Font(FontFamily.GenericSerif, 11),
                    MaxVisible = layLabel.MinVisible,
                    HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left,
                    VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom,
                    Offset = new PointF(3, 3),
                    Halo = new Pen(Color.Yellow, 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 = Color.LightBlue;

            map.ZoomToExtents(); // = 360;

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

            return map;

        }
        private static Map InitializeMapOsm(float angle)
        {
            //Transparent style
            VectorStyle transparentStyle = new VectorStyle();
            transparentStyle.Fill = Brushes.Transparent;
            transparentStyle.EnableOutline = true; //otherwise all the fancy theming stuff won't work!
            transparentStyle.Line.Brush = Brushes.Transparent;
            transparentStyle.Outline.Brush = Brushes.Transparent;
            transparentStyle.Symbol = null;

            VectorStyle transparentStyle2 = new VectorStyle();
            transparentStyle2.Fill = Brushes.Transparent;
            transparentStyle2.EnableOutline = true; //otherwise all the fancy theming stuff won't work!
            transparentStyle2.Line.Brush = Brushes.Transparent;
            transparentStyle2.Outline.Brush = Brushes.Transparent;
            transparentStyle2.Symbol = null;

            //Initialize a new map
            Map map = new Map();
            map.BackColor = Color.Cornsilk;

            var encoding = System.Text.Encoding.UTF8;

            //Set up the countries layer
            VectorLayer layNatural = new VectorLayer("Natural");
            //Set the datasource to a shapefile in the App_data folder
            layNatural.DataSource = new ShapeFile(string.Format("{0}/natural.shp", PathOsm), true) { Encoding = encoding };
            //Set default style to draw nothing
            layNatural.Style = transparentStyle;
            //Set theme
            ThemeViaDelegate theme = new ThemeViaDelegate(layNatural.Style, "type");
            theme.GetStyleFunction = delegate(FeatureDataRow row)
                                         {
                                             string caseVal = (String) row["type"];
                                             caseVal = caseVal.ToLowerInvariant();
                                             VectorStyle returnStyle = new VectorStyle();

                                             switch (caseVal)
                                             {
                                                 case "forest":
                                                     returnStyle.Fill = Brushes.ForestGreen;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.DarkGreen;
                                                     break;
                                                 case "water":
                                                     returnStyle.Fill = Brushes.Aqua;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.DarkBlue;
                                                     break;
                                                 case "riverbank":
                                                     returnStyle.Fill = Brushes.Peru;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.OrangeRed;
                                                     break;
                                                 case "park":
                                                     returnStyle.Fill = Brushes.PaleGreen;
                                                     returnStyle.EnableOutline = true;
                                                     returnStyle.Outline.Brush = Brushes.DarkGreen;
                                                     break;
                                                 default:
                                                     returnStyle = null;
                                                     break;
                                             }
                                             return returnStyle;
                                         };
            layNatural.Theme = theme;
            layNatural.SRID = 31466;

            VectorLayer layRoads = new VectorLayer("Roads");
            layRoads.DataSource = new ShapeFile(string.Format("{0}/roads.shp", PathOsm)) { Encoding = encoding };
            layRoads.DataSource.Open();
            _roadsExtents = layRoads.DataSource.GetExtents();
            //layRoads.DataSource.Close();
            layRoads.Style = transparentStyle;
            ThemeViaDelegate themeRoads = new ThemeViaDelegate(transparentStyle, "type");
            themeRoads.GetStyleFunction = delegate(FeatureDataRow row)
                                              {
                                                  VectorStyle returnStyle = new VectorStyle();

                                                  switch ((String)row["type"])
                                                  {
                                                      case "rail":
                                                          returnStyle.Fill = Brushes.White;
                                                          returnStyle.Line.DashPattern = new float[] { 4f, 4f };//;System.Drawing.Drawing2D.DashStyle.Dash;
                                                          returnStyle.Line.Width = 4;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.Outline.Width = 6;
                                                          break;
                                                      case "canal":
                                                          returnStyle.Fill = Brushes.Aqua;
                                                          returnStyle.Outline.Brush = Brushes.DarkBlue;
                                                          returnStyle.Outline.Width = 5;
                                                          break;
                                                      case "cycleway":
                                                      case "footway":
                                                      case "pedestrian":
                                                          returnStyle.Line.Brush = Brushes.DarkGray;
                                                          returnStyle.Line.DashStyle =
                                                              DashStyle.Dot;
                                                          returnStyle.Line.Width = 1;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.05d;
                                                          break;
                                                      case "living_street":
                                                      case "residential":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 2;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.DarkGray;
                                                          returnStyle.Outline.Width = 4;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.15d;
                                                          break;
                                                      case "primary":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 7;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.Outline.Width = 11;
                                                          break;
                                                      case "secondary":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 6;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.3d;
                                                          returnStyle.Outline.Width = 10;
                                                          break;
                                                      case "tertiary":
                                                          returnStyle.Line.Brush = Brushes.LightGoldenrodYellow;
                                                          returnStyle.Line.Width = 5;
                                                          returnStyle.EnableOutline = true;
                                                          returnStyle.Outline.Brush = Brushes.Black;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.6d;
                                                          returnStyle.Outline.Width = 9;
                                                          break;
                                                      case "path":
                                                      case "track":
                                                      case "unclassified":
                                                          returnStyle.Line.Brush = Brushes.DarkGray;
                                                          returnStyle.Line.DashStyle =
                                                              DashStyle.DashDotDot;
                                                          returnStyle.Line.Width = 1;
                                                          returnStyle.MaxVisible = _roadsExtents.Width * 0.025d;
                                                          break;
                                                      default:
                                                          returnStyle = null;
                                                          break;
                                                  }
                                                  return returnStyle;
                                              };
            layRoads.Theme = themeRoads;
            layRoads.SRID = 31466;

            VectorLayer layRail = new VectorLayer("Railways");
            layRail.DataSource = new ShapeFile(string.Format("{0}/railways.shp", PathOsm)) { Encoding = encoding };
            layRail.Style.Line.Brush = Brushes.White;
            layRail.Style.Line.DashPattern = new float[] {4f, 4f};//;System.Drawing.Drawing2D.DashStyle.Dash;
            layRail.Style.Line.Width = 4;
            layRail.Style.EnableOutline = true;
            layRail.Style.Outline.Brush = Brushes.Black;
            layRail.Style.Outline.Width = 6;

            VectorLayer layWaterways = new VectorLayer("Waterways");
            layWaterways.Style = transparentStyle;
            layWaterways.DataSource = new ShapeFile(string.Format("{0}/waterways.shp", PathOsm)) { Encoding = encoding };
            layRoads.Style = transparentStyle;
            ThemeViaDelegate themeWater = new ThemeViaDelegate(transparentStyle, "type");
            themeWater.GetStyleFunction = delegate(FeatureDataRow row)
            {
                VectorStyle returnStyle = new VectorStyle();
                returnStyle.Line.Brush = Brushes.Aqua;
                returnStyle.EnableOutline = true;
                Int32 lineWidth = 1;
                switch ((String)row["type"])
                {
                    case "canal":
                    case "derelict_canal":
                        lineWidth = 2;
                        break;
                    case "drain":
                        returnStyle.EnableOutline = false;
                        break;
                    case "stream":
                        lineWidth = 2;
                        break;
                    default:
                        //returnStyle = null;
                        break;
                }
                returnStyle.Line.Width = lineWidth;
                returnStyle.Outline.Brush = Brushes.DarkBlue;
                returnStyle.Outline.Width = lineWidth + 1;
                return returnStyle;
            };
            layWaterways.Theme = themeWater;
            layWaterways.SRID = 31466;

            VectorLayer layPoints = new VectorLayer("Points");
            layPoints.DataSource = new ShapeFile(string.Format("{0}/points.shp", PathOsm)) { Encoding = encoding };
            layPoints.Style = transparentStyle2;
            ThemeViaDelegate themePoints = new ThemeViaDelegate(transparentStyle2, "type");
            themePoints.GetStyleFunction = delegate(FeatureDataRow row)
            {
                VectorStyle returnStyle = new VectorStyle();
                switch ((String)row["type"])
                {
                    case "bank":
                        returnStyle.Symbol = new Bitmap("Images/Bank.gif");
                        break;
                    case "hospital":
                        returnStyle.Symbol = new Bitmap("Images/medical-facility.gif");
                        break;
                    case "hotel":
                        returnStyle.Symbol = new Bitmap("Images/hotel.gif");
                        break;
                    case "restaurant":
                    case "fast-food":
                        returnStyle.Symbol = new Bitmap("Images/restaurant.gif");
                        break;
                    case "parking":
                        returnStyle.Symbol = new Bitmap("Images/car.gif");
                        break;
                    default:
                        Bitmap tmp = new Bitmap(1,1);
                        tmp.SetPixel(0,0, Color.Transparent);
                        returnStyle.Symbol = tmp;
                        break;
                }
                return returnStyle;
            };
            layPoints.Theme = themePoints;
            layWaterways.SRID = 31466;

            var layLabel = new LabelLayer("Road Labels");
            layLabel.DataSource = layRoads.DataSource;
            layLabel.LabelColumn = "Name";

            //Add layers to Map
            map.Layers.Add(layNatural);
            map.Layers.Add(layWaterways);
            map.Layers.Add(layRail);
            map.Layers.Add(layRoads);
            map.Layers.Add(layPoints);
            map.Layers.Add(layLabel);

            ShapeProvider sp = new ShapeProvider(string.Format("{0}/obepath.shp", PathOsm)) { Encoding = encoding };
            VectorLayer vl = new VectorLayer("obepath", sp);
            vl.SRID = 31466;
            vl.Style.Symbol = new Bitmap("Images/car.gif");

            VariableLayerCollection.Interval = 500;
            map.VariableLayers.Add(vl);

            //Restrict zoom
            map.MaximumZoom = layRoads.Envelope.Width * 0.75d;
            map.Zoom = layRoads.Envelope.Width * 0.2d; ;
            map.Center = layRoads.Envelope.Centre;

            var disclaimer = new Disclaimer
                {
                    Font = new Font("Arial", 7f, FontStyle.Italic),
                    Text = "Geodata from OpenStreetMap (CC-by-SA)\nTransformed to Shapefile by geofabrik.de",
                    Anchor = MapDecorationAnchor.CenterBottom
                };
            map.Decorations.Add(disclaimer);
            transparentStyle2.MaxVisible = map.MaximumZoom*0.3;

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

            return map;
        }
Example #31
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);
        }
Example #32
0
    public static Map InitializeMapPostGis(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

        string connectionString = ConfigurationManager.ConnectionStrings["postgis"].ConnectionString;

        //Initialize a new map of size 'imagesize'
        SharpMap.Map map = new SharpMap.Map(size);

        //Set up the countries layer
        SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
        //Set the datasource to a new MsSqlSpatialProvider
        layCountries.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "countries", "wkb_geometry", "ogc_fid");

        //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;

        //Set up a river layer
        SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
        //Set the datasource to a new MsSqlSpatialProvider
        layRivers.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "rivers", "wkb_geometry", "ogc_fid");
        //Define a blue 1px wide pen
        layRivers.Style.Line = new Pen(Color.Blue, 1);

        //Set up a river layer
        SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
        //Set the datasource to a new MsSqlSpatialProvider
        layCities.DataSource = new SharpMap.Data.Providers.PostGIS(connectionString, "cities", "wkb_geometry", "ogc_fid"); ;
        //Define a blue 1px wide pen
        //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
        layCities.Style.SymbolScale = 0.8f;
        layCities.MaxVisible = 40;

        //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.MaxVisible = 90;
        layLabel.MinVisible = 30;
        layLabel.MultipartGeometryBehaviour = SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
        layLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
        layLabel.PriorityColumn = "popdens";
        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.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
        layLabel.Style.CollisionDetection = true;

        //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.PriorityColumn = "population";
        layCityLabel.PriorityDelegate = delegate(SharpMap.Data.FeatureDataRow fdr)
        {
            Int32 retVal = 10000000 * (Int32)((String)fdr["capital"] == "Y" ? 1 : 0);
            return retVal + Convert.ToInt32(fdr["population"]);
        };
        layCityLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
        layCityLabel.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        layCityLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
        layCityLabel.Style = new SharpMap.Styles.LabelStyle();
        layCityLabel.Style.ForeColor = Color.Black;
        layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
        layCityLabel.Style.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.Style.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 = Color.LightBlue;

        map.Zoom = 360;
        map.Center = new Point(0, 0);

        HttpContext.Current.Trace.Write("Map initialized");
        return map;
    }
Example #33
0
        public static SharpMap.Map GetMapForProviders(IEnumerable<SharpMap.Data.Providers.IProvider> providers)
        {
            var m = new SharpMap.Map();
            foreach (var provider in providers)
            {
                var l = new VectorLayer(provider.ConnectionID, provider)
                            {
                                Style = GetRandomVectorStyle()
                            };
                m.Layers.Add(l);
                var ll = new LabelLayer("Label " + provider.ConnectionID);
                ll.DataSource = provider;

                provider.Open();
                var f = provider.GetFeature(1);
                provider.Close();

                ll.LabelColumn = f.Table.Columns[1].ColumnName;
                ll.Style.CollisionDetection = false;
                ll.Style.IgnoreLength = true;

                m.Layers.Add(ll);
            }
            m.ZoomToExtents();
            return m;
        }
Example #34
0
    public static Map InitializeMap(Size size)
    {
        HttpContext.Current.Trace.Write("Initializing map...");

            //Initialize a new map of size 'imagesize'
        Map map = new Map(size);

            //Set up the countries layer
        VectorLayer layCountries = new VectorLayer("Countries");
            //Set the datasource to a shapefile in the App_data folder
        layCountries.DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\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 = Pens.Black;
            layCountries.Style.EnableOutline = true;
            layCountries.SRID = 4326;

            //Set up a river layer
        VectorLayer layRivers = new VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder
        layRivers.DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\rivers.shp"), true);
            //Define a blue 1px wide pen
        layRivers.Style.Line = new Pen(Color.Blue, 1);
            layRivers.SRID = 4326;

            //Set up a river layer
        VectorLayer layCities = new VectorLayer("Cities");
            //Set the datasource to a shapefile in the App_data folder
        layCities.DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~\App_data\cities.shp"), true);
            //Define a blue 1px wide pen
            //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~\App_data\icon.png"));
            layCities.Style.SymbolScale = 0.8f;
            layCities.MaxVisible = 40;
            layCities.SRID = 4326;

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

            //Set up a city label layer
        LabelLayer layCityLabel = new LabelLayer("City labels");
            layCityLabel.DataSource = layCities.DataSource;
            layCityLabel.Enabled = true;
            layCityLabel.LabelColumn = "Name";
        layCityLabel.Style = new LabelStyle();
            layCityLabel.Style.ForeColor = Color.Black;
            layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
            layCityLabel.MaxVisible = layLabel.MinVisible;
        layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
        layCityLabel.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;
            layCityLabel.Style.Offset = new PointF(3, 3);
            layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
        layCityLabel.TextRenderingHint = TextRenderingHint.AntiAlias;
            layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
            layCityLabel.SRID = 4326;
        layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
            layCityLabel.Style.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 = Color.LightBlue;

            map.Zoom = 360;
        map.Center = new Point(0, 0);

            HttpContext.Current.Trace.Write("Map initialized");
            return map;
    }
Example #35
0
        /// <summary>        
        /// /// Add a list of vector layers to the map.
        /// </summary>
        /// <param name="vectorLayers"></param>
        public void AddVectorLayers(List<FeatureInfo> vectorLayers)
        {
            int counter = 0;
            if (vectorLayers == null) return;
            vectorLayers.ForEach(layer => {

                VectorLayer vectorLayer = new VectorLayer("VectorLayer-" + counter);
                GeometryFactory factory = new GeometryFactory();
                List<IGeometry> geometries = new List<IGeometry>();

                FeatureDataTable featureData = new FeatureDataTable();
                featureData.Columns.Add("text", typeof(String));
                featureData.Columns.Add("style", typeof(MapExport.Style));

                layer.features.ForEach(feature =>
                {
                    FeatureDataRow dataRow = featureData.NewRow();
                    dataRow["text"] = feature.attributes.text;
                    dataRow["style"] = feature.attributes.style;

                    List<GeoAPI.Geometries.Coordinate> vertices = new List<GeoAPI.Geometries.Coordinate>();

                    feature.coordinates.ForEach(coordinate =>
                    {
                        double x = coordinate[0];
                        double y = coordinate[1];
                        vertices.Add((new GeoAPI.Geometries.Coordinate(x, y)));
                    });

                    switch (feature.type)
                    {
                        case "Text":
                        case "Point":
                            if (vertices.Count > 0)
                            {
                                var point = factory.CreatePoint(new GeoAPI.Geometries.Coordinate(vertices[0]));
                                dataRow.Geometry = point;
                            }
                            break;
                        case "LineString":
                            var lineString = factory.CreateLineString(vertices.ToArray());
                            dataRow.Geometry = lineString;
                            break;
                        case "Polygon":
                            var polygon = factory.CreatePolygon(vertices.ToArray());
                            dataRow.Geometry = polygon;
                            break;
                    }

                    featureData.AddRow(dataRow);
                });

                vectorLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(featureData);
                //vectorLayer.DataSource = new SharpMap.Data.Providers.FeatureProvider(featureData);

                //vectorLayer.Theme = new CustomTheme(GetFeatureStyle);
                vectorLayer.Theme = new CustomTheme(GetFeatureStyle);
                map.Layers.Add(vectorLayer);

                LabelLayer labels = new LabelLayer("Labels");

                labels.DataSource = vectorLayer.DataSource;
                labels.Enabled = true;
                labels.LabelColumn = "text";
                labels.Theme = new CustomTheme(GetLabelStyle);
                labels.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                labels.SmoothingMode = SmoothingMode.HighQuality;
                labels.SRID = vectorLayer.SRID;

                map.Layers.Add(labels);
                counter++;
            });
        }