Example #1
0
      public System.Collections.Generic.List<uint> GetObjectIDsInView(SharpMap.Geometries.BoundingBox bbox)
      {
            Collection<uint> objectlist = new Collection<uint>();
            using (SQLiteConnection conn = new SQLiteConnection(_ConnectionString))
            {
                string strSQL = "SELECT " + this.ObjectIdColumn + " ";
                strSQL += "FROM " + this.Table + " WHERE ";

                strSQL += GetBoxClause(bbox);

                if (!String.IsNullOrEmpty(_defintionQuery))
                    strSQL += " AND " + this.DefinitionQuery + " AND ";

                using (SQLiteCommand command = new SQLiteCommand(strSQL, conn))
                {
                    conn.Open();
                    using (SQLiteDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                uint ID = (uint)(int)dr[0];
                                objectlist.Add(ID);
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return objectlist;
        }
Example #2
0
        public System.Collections.Generic.List<SharpMap.Geometries.Geometry> GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox)
        {
            Collection<SharpMap.Geometries.Geometry> features = new Collection<IGeometry>();
            using (SQLiteConnection conn = new SQLiteConnection(_ConnectionString))
            {
                string BoxIntersect = GetBoxClause(bbox);

                string strSQL = "SELECT " + this.GeometryColumn + " AS Geom ";
                strSQL += "FROM " + this.Table + " WHERE ";
                strSQL += BoxIntersect;
                if (!String.IsNullOrEmpty(_defintionQuery))
                    strSQL += " AND " + this.DefinitionQuery;

                using (SQLiteCommand command = new SQLiteCommand(strSQL, conn))
                {
                    conn.Open();
                    using (SQLiteDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                IGeometry geom = SharpMap.Converters.WellKnownText.GeometryFromWKT.Parse((string)dr[0]);
                                if (geom != null)
                                    features.Add(geom);
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return features;
        }
Example #3
0
    protected override SharpMap.Rendering.Label CreateLabel(SharpMap.Geometries.Geometry feature, string text, float rotation, SharpMap.Styles.LabelStyle style, Map map, System.Drawing.Graphics g)
    {
      //System.Drawing.SizeF size = g.MeasureString(text, style.Font);

      System.Drawing.PointF position = map.WorldToImage(feature.GetBoundingBox().GetCentroid());
      //position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
      //position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
      if (position.X /*- size.Width*/ > map.Size.Width || position.X /*+ size.Width */< 0 ||
        position.Y /*- size.Height*/ > map.Size.Height || position.Y /*+ size.Height*/ < 0)
        return null;
      else
      {
        SharpMap.Rendering.Label lbl;

        if (!style.CollisionDetection)
          lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority, null, style);
        else
        {
          //Collision detection is enabled so we need to measure the size of the string
          lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority,
            new SharpMap.Rendering.LabelBox(position.X /*- size.Width * 0.5f*/ - style.CollisionBuffer.Width, position.Y + /*size.Height * 0.5f*/ + style.CollisionBuffer.Height,
            /*size.Width +*/ 2f * style.CollisionBuffer.Width, /*size.Height +*/ style.CollisionBuffer.Height * 2f), style);
        }
        if (feature.GetType() == typeof(SharpMap.Geometries.LineString))
        {
          SharpMap.Geometries.LineString line = feature as SharpMap.Geometries.LineString;
          if (line.Length / map.PixelSize > 40/*size.Width*/) //Only label feature if it is long enough
            CalculateLabelOnLinestring(line, ref lbl, map);
          else
            return null;
        }

        return lbl;
      }
    }
        public static SharpMap.Data.FeatureDataRow FindGeoNearPoint(
            GeoAPI.Geometries.IPoint point, SharpMap.Layers.VectorLayer layer, double amountGrow)
        {
            var box = new GeoAPI.Geometries.Envelope(point.Coordinate);
            box.ExpandBy(amountGrow);

            var fds = new SharpMap.Data.FeatureDataSet();
            layer.DataSource.ExecuteIntersectionQuery(box, fds);

            SharpMap.Data.FeatureDataRow result = null;
            var minDistance = double.MaxValue;

            foreach (SharpMap.Data.FeatureDataTable fdt in fds.Tables)
            {
            foreach (SharpMap.Data.FeatureDataRow fdr in fdt.Rows)
            {
            if (fdr.Geometry != null)
            {
                var distance = point.Distance(fdr.Geometry);
                if (distance < minDistance)
                {
                    result = fdr;
                    minDistance = distance;
                }
            }
            }
            }
            return result;
        }
Example #5
0
    /// <summary>
    /// Method for creating pie chart symbols
    /// </summary>
    /// <remarks>
    /// <para>In this example we just create some random pie charts, 
    /// but it probably should be based on attributes read from the row.</para>
    ///	<para>Credits goes to gonzalo_ar for posting this in the forum</para></remarks>
    /// <param name="row"></param>
    /// <returns></returns>
    private static Bitmap GetPieChart(SharpMap.Data.FeatureDataRow row)
    {

        // Replace polygon with a center point (this is where we place the symbol
        row.Geometry = row.Geometry.GetBoundingBox().GetCentroid();

        // Just for the example I use random values 
        int size = rand.Next(20, 35);
        int angle1 = rand.Next(60, 180);
        int angle2 = rand.Next(angle1 + 60, 300);
        Rectangle rect = new Rectangle(0, 0, size, size);
        System.Drawing.Bitmap b = new Bitmap(size, size);
        Graphics g = Graphics.FromImage(b);

        // Draw Pie 
        g.FillPie(Brushes.LightGreen, rect, 0, angle1);
        g.FillPie(Brushes.Pink, rect, angle1, angle2 - angle1);
        g.FillPie(Brushes.PeachPuff, rect, angle2, 360 - angle2);

        // Draw Borders 
        g.DrawPie(Pens.Green, rect, 0, angle1);
        g.DrawPie(Pens.Red, rect, angle1, angle2 - angle1);
        g.DrawPie(Pens.Orange, rect, angle2, 360 - angle2);
        g.Dispose();
        return b;
    }
Example #6
0
 public IEnumerable<SharpMap.Geometries.Geometry> getGeom(SharpMap.Geometries.GeometryCollection g)
 {
     foreach (SharpMap.Geometries.Geometry geo in g.Collection)
     {
         yield return geo;
     }
 }
Example #7
0
    /// <summary>
    /// Method to place the street direction symbols
    /// </summary>
    /// <param name="map"></param>
    /// <param name="lineString"></param>
    /// <param name="graphics"></param>
    private void OnRenderInternal(SharpMap.Map map, GeoAPI.Geometries.ILineString lineString,
        System.Drawing.Graphics graphics)
    {

        var length = lineString.Length;
        var lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(lineString);
        if (length < RepeatInterval + ArrowLength)
        {
            var start = System.Math.Max(0, (length - ArrowLength)/2);
            var end = System.Math.Min(length, (length + ArrowLength)/2);
            var arrow = (GeoAPI.Geometries.ILineString) lil.ExtractLine(start, end);

            RenderArrow(map, graphics, arrow);

            return;
        }

        var numArrows = (int) ((lineString.Length - ArrowLength)/RepeatInterval);
        var offset = (lineString.Length - numArrows*RepeatInterval - ArrowLength)*0.5;

        while (offset + ArrowLength < lineString.Length)
        {
            var arrow = (GeoAPI.Geometries.ILineString) lil.ExtractLine(offset, offset + ArrowLength);
            RenderArrow(map, graphics, arrow);
            offset += RepeatInterval;
        }

    }
Example #8
0
 /// <summary>
 /// Method to render the arrow
 /// </summary>
 /// <param name="map">The map</param>
 /// <param name="graphics">The graphics object</param>
 /// <param name="arrow">The arrow</param>
 private void RenderArrow(SharpMap.Map map, System.Drawing.Graphics graphics, GeoAPI.Geometries.ILineString arrow)
 {
     var pts = new System.Drawing.PointF[arrow.Coordinates.Length];
     for (var i = 0; i < pts.Length; i++)
         pts[i] = map.WorldToImage(arrow.GetCoordinateN(i));
     graphics.DrawLines(ArrowPen, pts);
 }
        private void ChangeTool(SharpMap.Forms.MapImage.Tools tool)
        {
            _mapImage.ActiveTool = tool;

            _view.SelectChecked = false;
            _view.ZoomInChecked = false;
            _view.ZoomOutChecked = false;
            _view.PanChecked = false;

            switch (tool)
            {
                case SharpMap.Forms.MapImage.Tools.Pan:
                    _view.PanChecked = true;
                    break;
                case SharpMap.Forms.MapImage.Tools.ZoomIn:
                    _view.ZoomInChecked = true;
                    break;
                case SharpMap.Forms.MapImage.Tools.ZoomOut:
                    _view.ZoomOutChecked = true;
                    break;
                case SharpMap.Forms.MapImage.Tools.Query:
                    _view.SelectChecked = true;
                    break;
            }
        }
public SharpMap.Geometries.MultiLineString SplitLineString(
    SharpMap.Geometries.LineString lineString, 
    System.Double length)
{
    if (lineString == null || lineString.IsEmpty())
        throw new System.ArgumentException("Linestring is null or Empty", "lineString");

    var gf = new NetTopologySuite.Geometries.GeometryFactory();
    var ntsLine = (NetTopologySuite.Geometries.LineString)
                    SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(lineString, gf);

    var ret = new SharpMap.Geometries.MultiLineString();
    var lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(ntsLine);

    double currentLength = 0d;
    while (currentLength  < ntsLine.Length)
    {
        var tmpLine = (NetTopologySuite.Geometries.LineString)
            lil.ExtractLine(currentLength, currentLength + length);
        ret.LineStrings.Add((SharpMap.Geometries.LineString)
            SharpMap.Converters.NTS.GeometryConverter.ToSharpMapGeometry(tmpLine));
        currentLength += length;
    }
    return ret;
}
 private void CreateTab(SharpMap.Data.FeatureDataTable featureDataTable)
 {
   this.tabControl1.TabPages.Add(featureDataTable.TableName, featureDataTable.TableName);
   System.Windows.Forms.DataGridView dv = new DataGridView();
   dv.AllowUserToAddRows = false;
   dv.AllowUserToDeleteRows = false;
   dv.AllowUserToOrderColumns = true;
   dv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
   dv.Font = this.Font;
   dv.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dv_DataBindingComplete);
   dv.Dock = System.Windows.Forms.DockStyle.Fill;
   dv.Location = new System.Drawing.Point(3, 3);
   dv.Name = "dvSelection";
   dv.ReadOnly = true;
   dv.Size = new System.Drawing.Size(278, 234);
   dv.TabIndex = 1;
   dv.VirtualMode = true;
   dv.CellValueNeeded += new DataGridViewCellValueEventHandler(dv_CellValueNeeded);
   dv.CellDoubleClick += new DataGridViewCellEventHandler(dv_CellDoubleClick);
   dv.CellClick += new DataGridViewCellEventHandler(dv_CellClick);
   dv.AllowUserToAddRows = false;
   dv.AllowUserToDeleteRows = false;
   dv.AllowUserToOrderColumns = true;
   dv.AllowUserToResizeColumns = true;
   dv.AllowUserToResizeRows = true;
   dv.MultiSelect = false;
   this.tabControl1.TabPages[featureDataTable.TableName].Controls.Add(dv);
   //dv.DataSource = featureDataTable;
   DataSources[featureDataTable.TableName] = featureDataTable;
   SetupRowsAndColumns(dv, featureDataTable);
   dv.Refresh();
 }
Example #12
0
        /// <summary>
        /// Renders a polygon to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="pol">Polygon to render</param>
        /// <param name="brush">Brush used for filling (null or transparent for no filling)</param>
        /// <param name="pen">Outline pen style (null if no outline)</param>
        /// <param name="clip">Specifies whether polygon clipping should be applied</param>
        /// <param name="map">Map reference</param>
        public static void DrawPolygon(System.Drawing.Graphics g, SharpMap.Geometries.Polygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, SharpMap.Map map)
        {
            if (pol.ExteriorRing == null)
                return;
            if (pol.ExteriorRing.Vertices.Count > 2)
            {
                //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

                //Add the exterior polygon
                if (!clip)
                    gp.AddPolygon(pol.ExteriorRing.TransformToImage(map));
                else
                    gp.AddPolygon(clipPolygon(pol.ExteriorRing.TransformToImage(map), map.Size.Width, map.Size.Height));

                //Add the interior polygons (holes)
                for (int i = 0; i < pol.InteriorRings.Count; i++)
                    if (!clip)
                        gp.AddPolygon(pol.InteriorRings[i].TransformToImage(map));
                    else
                        gp.AddPolygon(clipPolygon(pol.InteriorRings[i].TransformToImage(map), map.Size.Width, map.Size.Height));

                // Only render inside of polygon if the brush isn't null or isn't transparent
                if (brush != null && brush != System.Drawing.Brushes.Transparent)
                    g.FillPath(brush, gp);
                // Create an outline if a pen style is available
                if (pen != null)
                    g.DrawPath(pen, gp);
            }
        }
 protected override void OnRenderInternal(SharpMap.Map map, GeoAPI.Geometries.IPolygon polygon, System.Drawing.Graphics g)
 {
     var pt = polygon.Centroid;
     g.RenderingOrigin =
         System.Drawing.Point.Truncate(SharpMap.Utilities.Transform.WorldtoMap(pt.Coordinate, map));
     base.OnRenderInternal(map, polygon, g);
 }
Example #14
0
        /// <summary>
        /// Converts any <see cref=GisSharpBlog.NetTopologySuite.Geometries.Geometry"/> to the correspondant 
        /// <see cref="SharpMap.Geometries.Geometry"/>.
        /// </summary>
        /// <param name="geometry"></param>
        /// <returns></returns>
        public static GisSharpBlog.NetTopologySuite.Geometries.Geometry ToNTSGeometry(SharpMap.Geometries.Geometry geometry,
            GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
        {
            if (geometry == null)
                throw new NullReferenceException("geometry");

            if (geometry.GetType() == typeof(SharpMap.Geometries.Point))
                return ToNTSPoint(geometry as SharpMap.Geometries.Point, factory);

            else if (geometry.GetType() == typeof(SharpMap.Geometries.LineString))
                return ToNTSLineString(geometry as SharpMap.Geometries.LineString, factory);

            else if (geometry.GetType() == typeof(SharpMap.Geometries.Polygon))
                return ToNTSPolygon(geometry as SharpMap.Geometries.Polygon, factory);

            else if (geometry.GetType() == typeof(SharpMap.Geometries.MultiPoint))
                return ToNTSMultiPoint(geometry as SharpMap.Geometries.MultiPoint, factory);

            else if (geometry.GetType() == typeof(SharpMap.Geometries.MultiLineString))
                return ToNTSMultiLineString(geometry as SharpMap.Geometries.MultiLineString, factory);

            else if (geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon))
                return ToNTSMultiPolygon(geometry as SharpMap.Geometries.MultiPolygon, factory);

            else if (geometry.GetType() == typeof(SharpMap.Geometries.GeometryCollection))
                return ToNTSGeometryCollection(geometry as SharpMap.Geometries.GeometryCollection, factory);

            else throw new NotSupportedException("Type " + geometry.GetType().FullName + " not supported");
        }
Example #15
0
	/// <summary>
	/// This method is used for determining the color of country based on attributes.
	/// It is used as a delegate for the CustomTheme class.
	/// </summary>
	/// <param name="row"></param>
	/// <returns></returns>
	private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
	{
		SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
		switch (row["NAME"].ToString().ToLower())
		{
			case "denmark": //If country name is Danmark, fill it with green
				style.Fill = Brushes.Green;
				return style;
			case "united states": //If country name is USA, fill it with Blue and add a red outline
				style.Fill = Brushes.Blue;
				style.Outline = Pens.Red;
				return style;
			case "china": //If country name is China, fill it with red
				style.Fill = Brushes.Red;
				return style;
			default:
				break;
		}
		//If country name starts with S make it yellow
		if (row["NAME"].ToString().StartsWith("S"))
		{
			style.Fill = Brushes.Yellow;
			return style;
		}
		// If geometry is a (multi)polygon and the area of the polygon is less than 30, make it cyan
		else if (row.Geometry.GetType() == typeof(IMultiPolygon) && (row.Geometry as IMultiPolygon).Area < 30 ||
			row.Geometry.GetType() == typeof(IPolygon) && (row.Geometry as IPolygon).Area < 30 )
		{
			style.Fill = Brushes.Cyan;
			return style;
		}
		else //None of the above -> Use the default style
			return null;
	}
Example #16
0
 private string GetFileName(SharpMap.Geometries.BoundingBox boundingBox)
 {
   return String.Format("{0}/{1}_{2}_{3}_{4}.{5}", directory,
     boundingBox.Left.ToString("r", cultureInfo), boundingBox.Top.ToString("r", cultureInfo),
     boundingBox.Right.ToString("r", cultureInfo), boundingBox.Bottom.ToString("r", cultureInfo),
     "png");
 }
Example #17
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="LabelPoint">Label placement</param>
        /// <param name="Offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="map">Map reference</param>
        public static void DrawLabel(System.Drawing.Graphics g, System.Drawing.PointF LabelPoint, System.Drawing.PointF Offset, System.Drawing.Font font, System.Drawing.Color forecolor, System.Drawing.Brush backcolor, System.Drawing.Pen halo, float rotation, string text, SharpMap.Map map)
        {
            System.Drawing.SizeF fontSize = g.MeasureString(text, font); //Calculate the size of the text
            LabelPoint.X += Offset.X; LabelPoint.Y += Offset.Y; //add label offset
            if (rotation != 0 && rotation != float.NaN)
            {
                g.TranslateTransform(LabelPoint.X, LabelPoint.Y);
                g.RotateTransform(rotation);
                g.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                    g.FillRectangle(backcolor, 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    g.DrawPath(halo, path);
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
                g.Transform = map.MapTransform;
            }
            else
            {
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                    g.FillRectangle(backcolor, LabelPoint.X, LabelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, LabelPoint, null);
                if (halo != null)
                    g.DrawPath(halo, path);
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Example #18
0
        /// <summary>
        /// Get FeatureDataSet
        /// </summary>
        /// <param name="ShapeLayer"></param>
        /// <returns></returns>
        public static SharpMap.Data.FeatureDataSet GetFeatureDataSet(SharpMap.Geometries.BoundingBox envelope, 
            SharpMap.Layers.VectorLayer shapeLayer)
        {
            shapeLayer.DataSource.Open();
              shapeLayer.DataSource.ExecuteIntersectionQuery(envelope, _featureData);

              return _featureData;
        }
Example #19
0
 /// <summary>
 /// Construcor, initializes the Connector object.
 /// </summary>
 internal Connector(SharpMap.Data.Providers.IProvider provider, bool Shared)
 {
     this.Provider = provider;
     this._Shared = Shared;
     this.Pooled = true;
     Connector.InstanceCounter++;
     this.InstanceNumber = Connector.InstanceCounter;
 }
Example #20
0
 public static void Locate(SharpMap.Map map, string rootPath, string bitmapPath)
 {
     string[] poiFiles = System.IO.Directory.GetFiles(rootPath, "*.poi");
     foreach (string poiFile in poiFiles)
     {
         map.Layers.Add(AMLayerFactory.CreateLayer(poiFile, bitmapPath));
     }
 }
Example #21
0
		/// <summary>
		/// Initializes a new instance of the GradientTheme class
		/// </summary>
		/// <remarks>
		/// <para>The gradient theme interpolates linearly between two styles based on a numerical attribute in the datasource.
		/// This is useful for scaling symbols, line widths, line and fill colors from numerical attributes.</para>
		/// <para>Colors are interpolated between two colors, but if you want to interpolate through more colors (fx. a rainbow),
		/// set the <see cref="TextColorBlend"/>, <see cref="LineColorBlend"/> and <see cref="FillColorBlend"/> properties
		/// to a custom <see cref="ColorBlend"/>.
		/// </para>
		/// <para>The following properties are scaled (properties not mentioned here are not interpolated):
		/// <list type="table">
		///		<listheader><term>Property</term><description>Remarks</description></listheader>
		///		<item><term><see cref="System.Drawing.Color"/></term><description>Red, Green, Blue and Alpha values are linearly interpolated.</description></item>
		///		<item><term><see cref="System.Drawing.Pen"/></term><description>The color, width, color of pens are interpolated. MiterLimit,StartCap,EndCap,LineJoin,DashStyle,DashPattern,DashOffset,DashCap,CompoundArray, and Alignment are switched in the middle of the min/max values.</description></item>
		///		<item><term><see cref="System.Drawing.SolidBrush"/></term><description>SolidBrush color are interpolated. Other brushes are not supported.</description></item>
		///		<item><term><see cref="SharpMap.Styles.VectorStyle"/></term><description>MaxVisible, MinVisible, Line, Outline, Fill and SymbolScale are scaled linearly. Symbol, EnableOutline and Enabled switch in the middle of the min/max values.</description></item>
		///		<item><term><see cref="SharpMap.Styles.LabelStyle"/></term><description>FontSize, BackColor, ForeColor, MaxVisible, MinVisible, Offset are scaled linearly. All other properties use min-style.</description></item>
		/// </list>
		/// </para>
		/// <example>
		/// Creating a rainbow colorblend showing colors from red, through yellow, green and blue depicting 
		/// the population density of a country.
		/// <code lang="C#">
		/// //Create two vector styles to interpolate between
		/// SharpMap.Styles.VectorStyle min = new SharpMap.Styles.VectorStyle();
		/// SharpMap.Styles.VectorStyle max = new SharpMap.Styles.VectorStyle();
		/// min.Outline.Width = 1f; //Outline width of the minimum value
		/// max.Outline.Width = 3f; //Outline width of the maximum value
		/// //Create a theme interpolating population density between 0 and 400
		/// SharpMap.Rendering.Thematics.GradientTheme popdens = new SharpMap.Rendering.Thematics.GradientTheme("PopDens", 0, 400, min, max);
		/// //Set the fill-style colors to be a rainbow blend from red to blue.
		/// popdens.FillColorBlend = SharpMap.Rendering.Thematics.ColorBlend.Rainbow5;
		/// myVectorLayer.Theme = popdens;
		/// </code>
		/// </example>
		/// </remarks>
		/// <param name="columnName">Name of column to extract the attribute</param>
		/// <param name="minValue">Minimum value</param>
		/// <param name="maxValue">Maximum value</param>
		/// <param name="minStyle">Color for minimum value</param>
		/// <param name="maxStyle">Color for maximum value</param>
		public GradientTheme(string columnName, double minValue, double maxValue, SharpMap.Styles.IStyle minStyle, SharpMap.Styles.IStyle maxStyle)
		{
			_ColumnName = columnName;
			_min = minValue;
			_max = maxValue;
			_maxStyle = maxStyle;
			_minStyle = minStyle;
		}
 public static bool JustTracks(SharpMap.Data.FeatureDataRow fdr)
 {
     //System.Console.WriteLine(fdr [0] + ";"+ fdr[4]);
     var s = fdr[4] as string;
     if (s != null)
         return s == "track";
     return true;
 }
Example #23
0
    /// <summary>
    /// This method is used for determining the style
    /// It is used as a delegate for the CustomTheme class.
    /// </summary>
    /// <param name="row"></param>
    /// <returns></returns>
    private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
    {

        SharpMap.Styles.VectorStyle s = new SharpMap.Styles.VectorStyle();
        s.Fill = new SolidBrush(Color.Green);
        s.Symbol = GetPieChart(row);
        return s;
    }
Example #24
0
 /// <summary>
 /// Renders a LineString to the map.
 /// </summary>
 /// <param name="g">Graphics reference</param>
 /// <param name="line">LineString to render</param>
 /// <param name="pen">Pen style used for rendering</param>
 /// <param name="map">Map reference</param>
 public static void DrawLineString(System.Drawing.Graphics g, Geometries.LineString line, System.Drawing.Pen pen, SharpMap.Map map)
 {
     if (line.Vertices.Count > 1)
     {
         System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
         gp.AddLines(line.TransformToImage(map));
         g.DrawPath(pen, gp);
     }
 }
Example #25
0
		public override SharpMap.Geometries.Point Transform(SharpMap.Geometries.Point point)
		{
			if (!(point is SharpMap.Geometries.Point3D))
				throw new ArgumentException("Datum transformation requires a 3D point");
			if (!_isInverse)
				return Apply(point as SharpMap.Geometries.Point3D);
			else
				return ApplyInverted(point as SharpMap.Geometries.Point3D);
		}
Example #26
0
		/// <summary>
		/// Renders a LineString to the map.
		/// </summary>
		/// <param name="g">Graphics reference</param>
		/// <param name="line">LineString to render</param>
		/// <param name="pen">Pen style used for rendering</param>
		/// <param name="map">Map reference</param>
		public static void DrawLineString(System.Drawing.Graphics g, ILineString line, System.Drawing.Pen pen, SharpMap.Map map)
		{
			if (line.Coordinates.Length > 1)
			{
				System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
				gp.AddLines(Transform.TransformToImage(line, map));
				g.DrawPath(pen, gp);
			}
		}
Example #27
0
		/// <summary>
		/// Transforms from world coordinate system (WCS) to image coordinates
		/// NOTE: This method DOES NOT take the MapTransform property into account (use SharpMap.Map.MapToWorld instead)
		/// </summary>
		/// <param name="p">Point in WCS</param>
		/// <param name="map">Map reference</param>
		/// <returns>Point in image coordinates</returns>
		public static System.Drawing.PointF WorldtoMap(ICoordinate p, SharpMap.Map map)
		{
			//if (map.MapTransform != null && !map.MapTransform.IsIdentity)
			//	map.MapTransform.TransformPoints(new System.Drawing.PointF[] { p });
			
            System.Drawing.PointF result = new System.Drawing.Point();
			result.X = (float)((p.X - map.WorldLeft) / map.PixelWidth);
            result.Y = (float)((map.WorldTop - p.Y) / map.PixelHeight);
			return result;
		}
Example #28
0
		/// <summary>
		/// Searches the shared and pooled connector lists for a
		/// matching connector object or creates a new one.
		/// </summary>
		/// <param name="provider">Provider requested to connect to the database server</param>
		/// <param name="Shared">Allows multiple connections on a single connector. </param>
		/// <returns>A pooled connector object.</returns>
		internal Connector RequestConnector(SharpMap.Data.Providers.IProvider provider, bool Shared)
		{
			// if a shared connector is requested then the Shared
			// Connector List is searched first:
			if (Shared)
			{
				foreach (Connector Connector in this.SharedConnectors)
				{
					if (Connector.Provider.ConnectionID == provider.ConnectionID)
					{	// Bingo!
						// Return the shared connector to caller.
						// The connector is already in use.
						Connector._ShareCount++;
						return Connector;
					}
				}
			}

			// if a shared connector could not be found or a
			// nonshared connector is requested, then the pooled
			// (unused) connectors are beeing searched.
			foreach (Connector Connector in this.PooledConnectors)
			{
				if (Connector.Provider.ConnectionID == provider.ConnectionID)
				{	// Bingo!
					// Remove the Connector from the pooled connectors list.
					this.PooledConnectors.Remove(Connector);
					// Make the connector shared if requested					
					if (Connector.Shared = Shared)
					{
						this.SharedConnectors.Add(Connector);
						Connector._ShareCount = 1;
					}
					// done...
					Connector.InUse = true;
					return Connector;
				}
			}

			// No suitable connector found, so create new one
			Connector NewConnector = new Connector(provider, Shared);

			// Shared connections must be added to the shared 
			// connectors list
			if (Shared)
			{
				this.SharedConnectors.Add(NewConnector);
				NewConnector._ShareCount = 1;
			}

			// and then returned to the caller
			NewConnector.InUse = true;
			NewConnector.Open();
			return NewConnector;
		}
Example #29
0
        public ImageMapPoint(SharpMap.Geometries.Geometry geom, SharpMap.Map map, ImageMapStyle mapStyle)
            : base(geom, map)
        {
            this.Radius = mapStyle.Point.Radius;

            SharpMap.Geometries.Point P = geom as SharpMap.Geometries.Point;
            PointF pf = map.WorldToImage(P);
            map.MapTransform.TransformPoints(new PointF[] { pf });
            center = new System.Drawing.Point((int)pf.X, (int)pf.Y);

        }
Example #30
0
 /// <summary>
 /// Converts any <see cref="SharpMap.Geometries.Geometry"/> array to the correspondant 
 /// <see cref=GisSharpBlog.NetTopologySuite.Geometries.Geometry"/> array.
 /// </summary>
 /// <param name="geometries"></param>
 /// <param name="factory"></param>
 /// <returns></returns>
 public static GisSharpBlog.NetTopologySuite.Geometries.Geometry[] ToNTSGeometry(SharpMap.Geometries.Geometry[] geometries,
     GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory factory)
 {            
     GisSharpBlog.NetTopologySuite.Geometries.Geometry[] converted = new GisSharpBlog.NetTopologySuite.Geometries.Geometry[geometries.Length];
     int index = 0;
     foreach (SharpMap.Geometries.Geometry geometry in geometries)
         converted[index++] = GeometryConverter.ToNTSGeometry(geometry, factory);
     if((geometries.Length != converted.Length))
         throw new ApplicationException("Conversion error");
     return converted;
 }