本文整理汇总了C#中SharpMap类的典型用法代码示例。如果您正苦于以下问题:C# SharpMap类的具体用法?C# SharpMap怎么用?C# SharpMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SharpMap类属于命名空间,在下文中一共展示了SharpMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetObjectIDsInView
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;
}
示例2: GetGeometriesInView
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;
}
示例3: CreateLabel
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;
}
}
示例4: FindGeoNearPoint
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;
}
示例5: GetPieChart
/// <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;
}
示例6: getGeom
public IEnumerable<SharpMap.Geometries.Geometry> getGeom(SharpMap.Geometries.GeometryCollection g)
{
foreach (SharpMap.Geometries.Geometry geo in g.Collection)
{
yield return geo;
}
}
示例7: OnRenderInternal
/// <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;
}
}
示例8: RenderArrow
/// <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);
}
示例9: ChangeTool
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;
}
}
示例10: SplitLineString
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;
}
示例11: CreateTab
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();
}
示例12: DrawPolygon
/// <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);
}
}
示例13: OnRenderInternal
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);
}
示例14: ToNTSGeometry
/// <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");
}
示例15: GetCountryStyle
/// <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;
}