Example #1
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 #2
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);
 }
 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 #4
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(GeoAPI.Features.IFeature row)
    {
        // Replace polygon with a center point (this is where we place the symbol
        row.Geometry = row.Geometry.Centroid;

        // 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);
        RectangleF rect = new RectangleF(0, 0, size, size);
        Bitmap b = new Bitmap(size, size);
        using (IGraphics g = Graphics.FromImage(b).G())
        {
            // 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);
        }
        return b;
    }
Example #5
0
 /// <summary>
 /// Creates an enumeration of <see cref="GeoAPI.Geometries.Coordinate"/>s from an xml string
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="xml">the xml string</param>
 /// <returns>Coordinates</returns>
 public static System.Collections.Generic.IEnumerable<GeoAPI.Geometries.IGeometry> PointsFromXml(
     GeoAPI.Geometries.IGeometryFactory factory,
     System.IO.Stream xml)
 {
     foreach (var coordinate in CoordinatesFromXml(xml))
         yield return factory.CreatePoint(coordinate);
 }
Example #6
0
 public void OnMouseUp(GeoAPI.Geometries.ICoordinate worldPosition, System.Windows.Forms.MouseEventArgs e)
 {
     if (enabled)
     {
         MessageBox.Show("Hallo Rob", "Demo MapTool");
     }
 }
Example #7
0
        public static FeatureDataRow FindGeoNearPoint(GeoAPI.Geometries.IPoint point, VectorLayer layer, double amountGrow)
        {
            var box = new Envelope(point.Coordinate);
            box.ExpandBy(amountGrow);

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

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

            foreach (FeatureDataTable fdt in fds.Tables)
            {
                foreach (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 #8
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 VectorStyle GetCountryStyle(GeoAPI.Features.IFeature row)
 {
     VectorStyle s = new VectorStyle();
     s.Fill = new SolidBrush(Color.Green);
     s.Symbol = GetPieChart(row);
     return s;
 }
 public static bool JustTracks(GeoAPI.Features.IFeature fdr)
 {
     //System.Console.WriteLine(fdr [0] + ";"+ fdr[4]);
     var s = fdr.Attributes[4] as string;
     if (s != null)
         return s == "track";
     return true;
 }
Example #10
0
 internal static GeoAPI.Geometries.IGeometry ToPolygon(GeoAPI.Geometries.Envelope queryWindow)
 {
     return new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(new[] { 
         new GeoAPI.Geometries.Coordinate(queryWindow.MinX, queryWindow.MinY),
         new GeoAPI.Geometries.Coordinate(queryWindow.MinX, queryWindow.MaxY),
         new GeoAPI.Geometries.Coordinate(queryWindow.MaxX, queryWindow.MaxY),
         new GeoAPI.Geometries.Coordinate(queryWindow.MaxX, queryWindow.MinY),
         new GeoAPI.Geometries.Coordinate(queryWindow.MinX, queryWindow.MinY)}));
 }
Example #11
0
 public Geometry(GeoAPI.Geometries.IGeometry shape)
 {
     this.coordinates = new decimal[shape.Coordinates.Length][];
     for(var i = 0; i < shape.Coordinates.Length; i++)
     {
         var coordinate = shape.Coordinates[i];
         this.coordinates[i] = new decimal[2] { System.Convert.ToDecimal(coordinate.X), System.Convert.ToDecimal(coordinate.Y) };
     }
 }
        void mapBox1_GeometryDefined(GeoAPI.Geometries.IGeometry geometry)
        {
            MessageBox.Show("Geometry defined!\r\n"+geometry);

            geoProvider.Geometries.Add(geometry);

            this.mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
            this.mapBox1.Refresh();

        }
Example #13
0
        public SharpMap.Styles.VectorStyle GetRotatedSymol(GeoAPI.Features.IFeature row)
        {
            if (!System.String.IsNullOrEmpty(StyleRotationColumn))
                try
                {
                    SharpMap.Styles.VectorStyle dataStyle = CloneStyle(DefaultStyle);
                    dataStyle.SymbolRotation = System.Convert.ToSingle(row.Attributes[StyleRotationColumn]);
                    return dataStyle;
                }
                catch { }

            return null;
        }
Example #14
0
 public static GeoAPI.Geometries.ILinearRing CreateRectangle(GeoAPI.Geometries.IGeometryFactory factory, 
     GeoAPI.Geometries.Coordinate leftTop, GeoAPI.Geometries.Coordinate rightBottom)
 {
     var pts = new[]
                     {
                         leftTop, 
                         new GeoAPI.Geometries.Coordinate(rightBottom.X, leftTop.Y), 
                         rightBottom,
                         new GeoAPI.Geometries.Coordinate(leftTop.X, rightBottom.Y), 
                         leftTop
                     };
     return factory.CreateLinearRing(pts);
 }
Example #15
0
		/// <summary>
		/// Transforms a <see cref="Envelope"/>.
		/// </summary>
		/// <param name="box">BoundingBox to transform</param>
		/// <param name="transform">Math Transform</param>
		/// <returns>Transformed object</returns>
		public static GeoAPI.Geometries.IEnvelope TransformBox(GeoAPI.Geometries.IEnvelope box, IMathTransform transform)
		{
			if (box == null)
				return null;
            double[][] corners = new double[4][];
            corners[0] = transform.Transform(ToLightStruct(box.MinX, box.MinY)); //LL
            corners[1] = transform.Transform(ToLightStruct(box.MaxX, box.MaxY)); //UR
            corners[2] = transform.Transform(ToLightStruct(box.MinX, box.MaxY)); //UL
            corners[3] = transform.Transform(ToLightStruct(box.MaxX, box.MinY)); //LR

			IEnvelope result = GeometryFactory.CreateEnvelope();
            foreach (double[] p in corners)
				result.ExpandToInclude(p[0], p[1]);
			return result;
		}
public static void EnsureVisible(SharpMap.Map map, GeoAPI.Geometries.Coordinate pt)
{
    const double ensureVisibleRatio = 0.1d;
            
    //Get current map envelope
    var bb = map.Envelope;
    System.Console.WriteLine(string.Format("Map envelope: {0}", bb));
            
    //Set valid envelope
    var evbb = bb.Grow(- ensureVisibleRatio * bb.Width, -ensureVisibleRatio * bb.Height );
    System.Console.WriteLine(string.Format("Valid envelope: {0}", evbb));
            
    //Test if Point is in valid envelope
    if (evbb.Contains(pt)) return;

    //It is not
    System.Console.WriteLine(string.Format("Valid envelope does not contain {0}", pt));

    //LineString from Map.Center -> to Point
    var ls = map.Factory.CreateLineString(new[] {evbb.Centre, pt});
    System.Console.WriteLine(string.Format("LineString Map.Center -> Point: {0}", ls));

    //Setup Linestring from BoundingBox
    var evbbpts = new [] {evbb.TopLeft(), evbb.TopRight(), evbb.BottomRight(), evbb.BottomLeft(), evbb.TopLeft() };
    var evbblinearring = map.Factory.CreateLineString(evbbpts);
    System.Console.WriteLine(string.Format("Linestring of valid envelope: {0}", evbblinearring));

    //// convert geometries to NTS
    //var ntsevbb = (NetTopologySuite.Geometries.LineString)
    //    SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(evbblinearring, gf);
    //var ntsls = (NetTopologySuite.Geometries.LineString)
    //    SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(ls, gf);

    // Get intersection point
    var intGeo = evbblinearring.Intersection(ls);
    var intPt = (NetTopologySuite.Geometries.Point)intGeo;
    System.Console.WriteLine(string.Format("Intersection point is: {0}", intPt));

    //Compute offset
    var dx = pt.X - intPt.X;
    var dy = pt.Y - intPt.Y;
    System.Console.WriteLine(string.Format("Map.Center needs to be shifted by: [{0}, {1}]", dx, dy));

    //Set new center Center
    map.Center = new GeoAPI.Geometries.Coordinate(map.Center.X + dx, map.Center.Y + dy);

}
Example #17
0
        public override void OnMouseDown(GeoAPI.Geometries.ICoordinate worldPosition, System.Windows.Forms.MouseEventArgs e)
        {
            // Starting a new measurement?
            if (pointGometries.Count >= 2)
            {
                Clear();
            }

            // Add the newly selected point
            pointGometries.Add(new GeoPoint(worldPosition));

            CalculateDistance();

            // Refresh the screen
            pointLayer.RenderRequired = true;
            MapControl.Refresh(); // HACK: Why is this needed? (Only RenderRequired = true isn't enough...)
            
            base.OnMouseDown(worldPosition, e);
        }
public GeoAPI.Geometries.IMultiLineString SplitLineString(
    GeoAPI.Geometries.ILineString 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 System.Collections.Generic.List<GeoAPI.Geometries.ILineString>();
    var lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(lineString);

    double currentLength = 0d;
    while (currentLength  < lineString.Length)
    {
        var tmpLine = (GeoAPI.Geometries.ILineString)
            lil.ExtractLine(currentLength, currentLength + length);
        ret.Add(tmpLine);
        currentLength += length;
    }
    return lineString.Factory.CreateMultiLineString(ret.ToArray());
}
Example #19
0
        internal static DotSpatial.Topology.LineString ToDotSpatialLineString(GeoAPI.Geometries.ILineString l)
        {
            DotSpatial.Topology.Coordinate[] c = new DotSpatial.Topology.Coordinate[l.Coordinates.Count()];

            for (int i = 0; i < l.Coordinates.Count(); i++)
            {
                c[i] = new DotSpatial.Topology.Coordinate(l.Coordinates[i].X, l.Coordinates[i].Y);
            }
            return new DotSpatial.Topology.LineString(c);
        }
Example #20
0
 internal static DotSpatial.Topology.Coordinate ToDotSpatialCoordinate(GeoAPI.Geometries.Coordinate coordinate)
 {
     return new DotSpatial.Topology.Coordinate(coordinate.X, coordinate.Y);
 }
Example #21
0
 internal static DotSpatial.Topology.Point ToDotSpatialPoint(GeoAPI.Geometries.Coordinate point)
 {
     return new DotSpatial.Topology.Point(point.X, point.Y);
 }
        //public NtsGeographySink() 
        //    :this(GeometryFactory.Default)
        //{}

	    public NtsGeographySink(GeoAPI.IGeometryServices geometryServices)
	    {
            _geometryServices = geometryServices;
	    }
 void mapBox1_MouseMove(GeoAPI.Geometries.Coordinate worldPos, MouseEventArgs imagePos)
 {
     this.label2.Text = worldPos.X.ToString("N4") + "/" + worldPos.Y.ToString("N4");
 }
Example #24
0
		/// <summary>
		/// Zooms the map to fit a bounding box
		/// </summary>
		/// <remarks>
		/// NOTE: If the aspect ratio of the box and the aspect ratio of the mapsize
		/// isn't the same, the resulting map-envelope will be adjusted so that it contains
		/// the bounding box, thus making the resulting envelope larger!
		/// </remarks>
		/// <param name="bbox"></param>
		public void ZoomToBox(GeoAPI.Geometries.IEnvelope bbox)
		{
			this._Zoom = bbox.Width; //Set the private center value so we only fire one MapOnViewChange event
			if (this.Envelope.Height < bbox.Height)
				this._Zoom *= bbox.Height / this.Envelope.Height;
			this.Center = bbox.Centre;			
		}
Example #25
0
		/// <summary>
		/// Returns all features with the view box
		/// </summary>
		/// <param name="bbox">view box</param>
		/// <param name="ds">FeatureDataSet to fill data into</param>
		public void ExecuteIntersectionQuery(GeoAPI.Geometries.IEnvelope bbox, SharpMap.Data.FeatureDataSet ds)
		{
			//List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>();
			using (SqlConnection conn = new SqlConnection(_ConnectionString))
			{
				string strSQL = "SELECT *, " + this.GeometryColumn + " AS sharpmap_tempgeometry ";
				strSQL += "FROM " + this.Table + " WHERE ";
				strSQL += GetBoxClause(bbox);

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

				using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
				{
					conn.Open();
					System.Data.DataSet ds2 = new System.Data.DataSet();
					adapter.Fill(ds2);
					conn.Close();
					if (ds2.Tables.Count > 0)
					{
						FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]);
						foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
							if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_"))
								fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
						foreach (System.Data.DataRow dr in ds2.Tables[0].Rows)
						{
							SharpMap.Data.FeatureDataRow fdr = fdt.NewRow();
							foreach (System.Data.DataColumn col in ds2.Tables[0].Columns)
								if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_"))
									fdr[col.ColumnName] = dr[col];
							if (dr["sharpmap_tempgeometry"] != DBNull.Value)
								fdr.Geometry = SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
							fdt.AddRow(fdr);
						}
						ds.Tables.Add(fdt);
					}
				}
			}
		}
Example #26
0
		private string GetBoxClause(GeoAPI.Geometries.IEnvelope bbox)
		{
			return String.Format(SharpMap.Map.numberFormat_EnUS,
				"(Envelope_MinX < {0} AND Envelope_MaxX > {1} AND Envelope_MinY < {2} AND Envelope_MaxY > {3})",
				bbox.MaxX, bbox.MinX, bbox.MaxY, bbox.MinY);
		}
Example #27
0
		/// <summary>
		/// Returns the features that intersects with 'geom' [NOT IMPLEMENTED]
		/// </summary>
		/// <param name="geom"></param>
		/// <param name="ds">FeatureDataSet to fill data into</param>
		public void ExecuteIntersectionQuery(GeoAPI.Geometries.IGeometry geom, FeatureDataSet ds)
		{
			throw new NotImplementedException();
		}
Example #28
0
        internal static DotSpatial.Topology.LinearRing ToDotSpatialLinearRing(GeoAPI.Geometries.ILinearRing geom)
        {
            Collection<DotSpatial.Topology.Point> vertices = new Collection<DotSpatial.Topology.Point>();

            foreach (Coordinate coordinate in geom.Coordinates)
            {
                DotSpatial.Topology.Point p = ToDotSpatialPoint(coordinate);

                vertices.Add(p);
            }
            return new DotSpatial.Topology.LinearRing(vertices);
        }
Example #29
0
        internal static DotSpatial.Topology.Polygon ToDotSpatialPolygon(GeoAPI.Geometries.IPolygon geom)
        {
            DotSpatial.Topology.LinearRing exteriorRing = ToDotSpatialLinearRing((GeoAPI.Geometries.ILinearRing)geom.ExteriorRing);

            DotSpatial.Topology.LinearRing[] interiorRings = new DotSpatial.Topology.LinearRing[geom.InteriorRings.Count()];

            //foreach (GeoAPI.Geometries.ILineString interiorRing in geom.InteriorRings)
            for (int i = 0; i < geom.InteriorRings.Count(); i++)
            {
                DotSpatial.Topology.LinearRing hole = ToDotSpatialLinearRing((GeoAPI.Geometries.ILinearRing)geom.InteriorRings[i]);
                interiorRings[i] = hole;
            }

            return new DotSpatial.Topology.Polygon(exteriorRing, interiorRings);
        }
Example #30
0
		/// <summary>
		/// Returns geometry Object IDs whose bounding box intersects 'bbox'
		/// </summary>
		/// <param name="bbox"></param>
		/// <returns></returns>
		public Collection<uint> GetObjectIDsInView(GeoAPI.Geometries.IEnvelope bbox)
		{
			Collection<uint> objectlist = new Collection<uint>();
			using (SqlConnection conn = new SqlConnection(_ConnectionString))
			{
				string strSQL = "SELECT " + this.ObjectIdColumn + " ";
				strSQL += "FROM " + this.Table + " WHERE ";

				strSQL += GetBoxClause(bbox);

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

				using (SqlCommand command = new SqlCommand(strSQL, conn))
				{
					conn.Open();
					using (SqlDataReader dr = command.ExecuteReader())
					{
						while (dr.Read())
						{
							if (dr[0] != DBNull.Value)
							{
								uint ID = (uint)(int)dr[0];
								objectlist.Add(ID);
							}
						}
					}
					conn.Close();
				}
			}
			return objectlist;
		}