I am trying to draw a line between two lines.
I could create points by using the createPoint Method
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries;
using SharpMap.Layers;
using SharpMap.Data;
using SharpMap.Styles;
using SharpMap.Rendering.Thematics;
using BruTile.Web;
using WindowsFormsApplication1.Properties;
#if DotSpatialProjections
using GeometryTransform = DotSpatial.Projections.GeometryTransform;
#else
using GeometryTransform = GeoAPI.CoordinateSystems.Transformations.GeometryTransform;
#endif
namespace WindowsFormsApplication1
{
public partial class FormMovingObjectOverTileLayer : Form
{
private List<IGeometry> geos = new List<IGeometry>();
GeoAPI.Geometries.Coordinate position, position1,position2;
public FormMovingObjectOverTileLayer()
{
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
private void FormMovingObjectOverTileLayer_Load(object sender, EventArgs e)
{
//Lisbon...
#if DotSpatialProjections
var mathTransform = LayerTools.Wgs84toGoogleMercator;
var geom = GeometryTransform.TransformBox(
new Envelope(-9.205626, -9.123736, 38.690993, 38.740837),
mathTransform.Source, mathTransform.Target);
#else
var mathTransform = LayerTools.Wgs84toGoogleMercator.MathTransform;
GeoAPI.Geometries.Envelope geom = GeometryTransform.TransformBox(
new Envelope(139.921875, -32.34375 , 5576031.87584, -3808518.221266), mathTransform);
#endif
//Google Background
TileAsyncLayer layer2 = new TileAsyncLayer(new OsmTileSource(), "TileLayer - OSM");
this.mapBox1.Map.BackgroundLayer.Add(layer2);
var gf = new GeometryFactory(new PrecisionModel(), 3857);
//Adds a static layer
var staticLayer = new VectorLayer("Fixed Marker");
//position = geom.GetCentroid();
var aux = new List<IGeometry>();
// position2 = new Coordinate(-10, -10);
aux.Add(gf.CreatePoint(geom.Centre));
staticLayer.Style.Symbol = Resources.PumpSmall;
var geoProviderFixed = new SharpMap.Data.Providers.GeometryProvider(aux);
staticLayer.DataSource = geoProviderFixed;
this.mapBox1.Map.Layers.Add(staticLayer);
position = geom.Centre;
//Adds a moving variable layer
VectorLayer pushPinLayer = new VectorLayer("PushPins");
position1 = new Coordinate(10, 10);
geos.Add(gf.CreatePoint(position1));
// Line Between Two Points
aux.Add(gf.CreateLineString(10,10,20,20));
//
pushPinLayer.Style.Symbol = Resources.ZoomToExtents1;
var geoProvider = new SharpMap.Data.Providers.GeometryProvider(geos);
pushPinLayer.DataSource = geoProvider;
this.mapBox1.Map.VariableLayers.Add(pushPinLayer);
this.mapBox1.Map.ZoomToBox(geom);
this.mapBox1.Refresh();
}
private void timer1_Tick(object sender, EventArgs e)
{
position1.X = position1.X + (position.X - position1.X)*0.002f;
position1.Y = position1.Y + (position.Y - position1.Y) * 0.002f;
VariableLayerCollection.TouchTimer();
}
private void button4_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
}
private void Form2_SizeChanged(object sender, EventArgs e)
{
this.mapBox1.Refresh();
}
private void FormMovingObjectOverTileLayer_FormClosing(object sender, FormClosingEventArgs e)
{
this.timer1.Stop();
}
}
}
But I am not sure how to make the line
I tried this line of code but it returns an error, I just don't know what the parameters are
aux.Add(gf.CreateLineString(10,10, 20,20);
Error 1 No overload for method 'CreateLineString' takes 4
arguments D:\Moving object
Best Answer
The
CreateLineString
method only takes one argument - an array ofCoordinate
(strictly speaking anIEnumerable<ICoordinate>
or anICoordinateSequence
). You can see this in the examples:Note that there are some API differences across versions, so next time, posting exact version information might be useful.