本文整理汇总了C#中OsmSharp.Math.Geo.GeoCoordinate类的典型用法代码示例。如果您正苦于以下问题:C# GeoCoordinate类的具体用法?C# GeoCoordinate怎么用?C# GeoCoordinate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeoCoordinate类属于OsmSharp.Math.Geo命名空间,在下文中一共展示了GeoCoordinate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RoutingRegressionTest1
public void RoutingRegressionTest1()
{
var interpreter = new OsmRoutingInterpreter();
var tagsIndex = new TagsTableCollectionIndex();
// do the data processing.
var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
var dataProcessorSource = new XmlOsmStreamSource(
Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
var sorter = new OsmStreamFilterSort();
sorter.RegisterSource(dataProcessorSource);
targetData.RegisterSource(sorter);
targetData.Pull();
var basicRouter = new Dykstra();
var router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);
// resolve the three points in question.
var point35 = new GeoCoordinate(51.01257, 4.000753);
var point35resolved = router.Resolve(Vehicle.Car, point35);
var point45 = new GeoCoordinate(51.01315, 3.999588);
var point45resolved = router.Resolve(Vehicle.Car, point45);
// route between 35 and 45.
var routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
// route between 35 and 45.
var routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
}
示例2: RouterPoint
/// <summary>
/// Creates a new router point.
/// </summary>
/// <param name="id"></param>
/// <param name="vehicle"></param>
/// <param name="location"></param>
public RouterPoint(long id, Vehicle vehicle, GeoCoordinate location)
{
_id = id;
this.Location = location;
this.Vehicle = vehicle;
this.Tags = new List<KeyValuePair<string, string>>();
}
示例3: AddLine
/// <summary>
/// Adds a line.
/// </summary>
public void AddLine(GeoCoordinate point1, GeoCoordinate point2, float sizePixels, int color)
{
if (point1 == null) { throw new ArgumentNullException(); }
if (point2 == null) { throw new ArgumentNullException(); }
// update envelope.
if (_envelope == null)
{ // create initial envelope.
_envelope = new GeoCoordinateBox(point1, point2);
}
// also include the current point.
_envelope.ExpandWith(point1);
_envelope.ExpandWith(point2);
var projected1 = _projection.ToPixel(point1);
var projected2 = _projection.ToPixel(point2);
var x = new double[] { projected1[0], projected2[0] };
var y = new double[] { projected1[1], projected2[1] };
uint? pointsId = _scene.AddPoints(x, y);
if (pointsId.HasValue)
{
_scene.AddStyleLine(pointsId.Value, 0, float.MinValue, float.MaxValue, color, sizePixels, Renderer.Primitives.LineJoin.Round, null);
this.RaiseLayerChanged();
}
}
示例4: TestGeoCoordinateOffsetWithDirection
public void TestGeoCoordinateOffsetWithDirection()
{
var distance = 1000; // 1km
var start = new GeoCoordinate(53.32056, 1.72972);
var offset = start.OffsetWithDirection(distance, DirectionEnum.North);
Assert.AreEqual(53.32950, offset.Latitude, 0.0001);
Assert.AreEqual(1.72970, offset.Longitude, 0.0001);
offset = start.OffsetWithDirection(distance, DirectionEnum.NorthEast);
Assert.AreEqual(53.32690, offset.Latitude, 0.0001);
Assert.AreEqual(1.74040, offset.Longitude, 0.0001);
start = new GeoCoordinate(0, 0);
offset = start.OffsetWithDirection(distance, DirectionEnum.West);
Assert.AreEqual(0, offset.Latitude, 0.0001);
Assert.AreEqual(-0.008984, offset.Longitude, 0.0001);
offset = start.OffsetWithDirection(distance, DirectionEnum.East);
Assert.AreEqual(0, offset.Latitude, 0.0001);
Assert.AreEqual(0.008984, offset.Longitude, 0.0001);
offset = start.OffsetWithDirection(distance, DirectionEnum.North);
Assert.AreEqual(0.008896, offset.Latitude, 0.0001);
Assert.AreEqual(0, offset.Longitude, 0.0001);
offset = start.OffsetWithDirection(distance, DirectionEnum.South);
Assert.AreEqual(-0.008896, offset.Latitude, 0.0001);
Assert.AreEqual(0, offset.Longitude, 0.0001);
}
示例5: BuildDummyRoute
/// <summary>
/// Builds a dummy route (as the crow flies) for segments of a route not found.
/// </summary>
/// <returns></returns>
public virtual Route BuildDummyRoute(Vehicle vehicle, GeoCoordinate coordinate1, GeoCoordinate coordinate2)
{
var route = new Route();
route.Vehicle = vehicle.UniqueName;
var segments = new RouteSegment[2];
segments[0] = new RouteSegment();
segments[0].Distance = 0;
segments[0].Time = 0;
segments[0].Type = RouteSegmentType.Start;
segments[0].Vehicle = vehicle.UniqueName;
segments[0].Latitude = (float)coordinate1.Latitude;
segments[0].Longitude = (float)coordinate1.Longitude;
var distance = coordinate1.DistanceReal(coordinate2).Value;
var timeEstimage = distance / (vehicle.MaxSpeed().Value) * 3.6;
var tags = new TagsCollection();
tags.Add("route", "not_found");
segments[1] = new RouteSegment();
segments[1].Distance = distance;
segments[1].Time = timeEstimage;
segments[1].Type = RouteSegmentType.Stop;
segments[1].Vehicle = vehicle.UniqueName;
segments[1].Latitude = (float)coordinate2.Latitude;
segments[1].Longitude = (float)coordinate2.Longitude;
segments[1].Tags = RouteTagsExtensions.ConvertFrom(tags);
route.Segments = segments;
return route;
}
示例6: CompareRoutes
/// <summary>
/// Compares the two given routes.
/// </summary>
/// <param name="reference"></param>
/// <param name="route"></param>
protected void CompareRoutes(Route reference, Route route)
{
double delta = 0.0001;
if (reference.Segments == null)
{ // both routes are empty.
Assert.IsNull(route.Segments);
}
else
{ // compare the geometry of the routes.
for (int idx = 0; idx < reference.Segments.Length; idx++)
{
var referenceCoordinate = new GeoCoordinate(reference.Segments[idx].Latitude,
reference.Segments[idx].Longitude);
Meter referenceDistance, distance;
GeoCoordinate referenceProjected, projected;
Second referenceTime, time;
reference.ProjectOn(referenceCoordinate, out referenceProjected, out referenceDistance, out referenceTime);
route.ProjectOn(referenceCoordinate, out projected, out distance, out time);
Assert.AreEqual(0, referenceProjected.DistanceReal(projected).Value, delta); // projected points have to match.
Assert.AreEqual(referenceDistance.Value, distance.Value, 0.1); // compare calculated distance to 10cm accuracy.
Assert.AreEqual(referenceProjected.Latitude, projected.Latitude, delta);
Assert.AreEqual(referenceProjected.Longitude, projected.Longitude, delta);
}
}
}
示例7: GeoCoordinateLine
/// <summary>
/// Creates a geo coordinate line.
/// </summary>
/// <param name="point1"></param>
/// <param name="point2"></param>
/// <param name="is_segment1"></param>
/// <param name="is_segment2"></param>
public GeoCoordinateLine(
GeoCoordinate point1,
GeoCoordinate point2,
bool is_segment1,
bool is_segment2)
: base(point1, point2, is_segment1, is_segment2)
{
}
示例8: Contains
/// <summary>
/// Returns true if the given coordinate is contained in this ring.
///
/// See: http://geomalgorithms.com/a03-_inclusion.html
/// </summary>
/// <param name="coordinate"></param>
/// <returns></returns>
public bool Contains(GeoCoordinate coordinate)
{
int number = 0;
if (this.Coordinates[0] == coordinate)
{ // the given point is one of the corners.
return true;
}
// loop over all edges and calculate if they possibly intersect.
for (int idx = 0; idx < this.Coordinates.Count - 1; idx++)
{
if (this.Coordinates[idx + 1] == coordinate)
{ // the given point is one of the corners.
return true;
}
bool idxRight = this.Coordinates[idx].Longitude > coordinate.Longitude;
bool idx1Right = this.Coordinates[idx + 1].Longitude > coordinate.Longitude;
if (idxRight || idx1Right)
{ // at least on of the coordinates is to the right of the point to calculate for.
if ((this.Coordinates[idx].Latitude <= coordinate.Latitude &&
this.Coordinates[idx + 1].Latitude >= coordinate.Latitude) &&
!(this.Coordinates[idx].Latitude == coordinate.Latitude &&
this.Coordinates[idx + 1].Latitude == coordinate.Latitude))
{ // idx is lower than idx+1
if (idxRight && idx1Right)
{ // no need for the left/right algorithm the result is already known.
number++;
}
else
{ // one of the coordinates is not to the 'right' now we need the left/right algorithm.
LineF2D localLine = new LineF2D(this.Coordinates[idx], this.Coordinates[idx + 1]);
if (localLine.PositionOfPoint(coordinate) == LinePointPosition.Left)
{
number++;
}
}
}
else if ((this.Coordinates[idx].Latitude >= coordinate.Latitude &&
this.Coordinates[idx + 1].Latitude <= coordinate.Latitude) &&
!(this.Coordinates[idx].Latitude == coordinate.Latitude &&
this.Coordinates[idx + 1].Latitude == coordinate.Latitude))
{ // idx is higher than idx+1
if (idxRight && idx1Right)
{ // no need for the left/right algorithm the result is already known.
number--;
}
else
{ // one of the coordinates is not to the 'right' now we need the left/right algorithm.
LineF2D localLine = new LineF2D(this.Coordinates[idx], this.Coordinates[idx + 1]);
if (localLine.PositionOfPoint(coordinate) == LinePointPosition.Right)
{
number--;
}
}
}
}
}
return number != 0;
}
示例9: CalculateTSP
/// <summary>
/// Calculates a solution to the ATSP.
/// </summary>
/// <param name="weights">The weights between all the customers.</param>
/// <param name="locations">The locations of all customers.</param>
/// <param name="first">The first customer.</param>
/// <param name="is_round">Return to the first customer or not.</param>
/// <returns></returns>
public IRoute CalculateTSP(double[][] weights, GeoCoordinate[] locations, int first, bool is_round)
{
// create solver.
ISolver solver = this.DoCreateSolver(locations.Length);
solver.IntermidiateResult += new SolverDelegates.IntermidiateDelegate(solver_IntermidiateResult);
// calculate the TSP.
return solver.Solve(this.GenerateProblem(weights, first, null, is_round));
}
示例10: MapMarker
/// <summary>
/// Initializes a new instance of the <see cref="SomeTestProject.MapMarker"/> class.
/// </summary>
/// <param name="location">Coordinate.</param>
/// <param name="image">Bitmap.</param>
/// <param name="alignment">Alignment.</param>
public MapMarker(GeoCoordinate location, MapMarkerAlignmentType alignment, UIImage image)
: base(UIButtonType.Custom){
_image = image;
this.Location = location;
_alignment = alignment;
this.Frame = new System.Drawing.RectangleF (new System.Drawing.PointF (0, 0), image.Size);
this.SetImage (image, UIControlState.Normal);
this.SetImage (image, UIControlState.Highlighted);
this.SetImage (image, UIControlState.Disabled);
}
示例11: TestGeoCoordinateOffsetRandom
public void TestGeoCoordinateOffsetRandom()
{
var generator = new OsmSharp.Math.Random.RandomGenerator(10124613);
for(int idx = 0; idx < 1000; idx++)
{
GeoCoordinate start = new GeoCoordinate(51, 4.8);
GeoCoordinate offset = start.OffsetRandom(generator, 20);
double distance = offset.DistanceReal(start).Value;
Assert.IsTrue(distance <= 20.001);
}
}
示例12: AddLine
/// <summary>
/// Adds a line.
/// </summary>
/// <param name="point1"></param>
/// <param name="point2"></param>
/// <param name="sizePixels"></param>
/// <param name="color"></param>
/// <returns></returns>
public void AddLine(GeoCoordinate point1, GeoCoordinate point2, float sizePixels, int color)
{
double[] projected1 = _projection.ToPixel(point1);
double[] projected2 = _projection.ToPixel(point2);
double[] x = new double[] { projected1[0], projected2[0] };
double[] y = new double[] { projected1[1], projected2[1] };
uint? pointsId = _scene.AddPoints(x, y);
if (pointsId.HasValue)
{
_scene.AddStyleLine(pointsId.Value, 0, float.MinValue, float.MaxValue, color, sizePixels, Renderer.Primitives.LineJoin.Round, null);
this.RaiseLayerChanged();
}
}
示例13: GetMatrix
public override Tuple<string, double[][]>[] GetMatrix(Vehicle vehicle, GeoCoordinate[] source, GeoCoordinate[] target, string[] outputs,
out Tuple<string, int, string>[] errors)
{
var errorsList = new List<Tuple<string, int, string>>();
for (var i = 0; i < source.Length; i++)
{
if (source[i] == null || source[i].Latitude > 180)
{ // dummy incorrect coordinates had a lat bigger than 180.
errorsList.Add(new Tuple<string, int, string>("source", i, "Coordinate invalid."));
source[i] = null;
}
}
for (var i = 0; i < target.Length; i++)
{
if (target[i] == null || target[i].Latitude > 180)
{ // dummy incorrect coordinates had a lat bigger than 180.
errorsList.Add(new Tuple<string, int, string>("target", i, "Coordinate invalid."));
target[i] = null;
}
}
errors = errorsList.ToArray();
// remove invalid coordinates.
var sourceList = new List<GeoCoordinate>(source);
sourceList.RemoveAll(x => x == null);
source = sourceList.ToArray();
var targetList = new List<GeoCoordinate>(target);
targetList.RemoveAll(x => x == null);
target = targetList.ToArray();
// build a dummy response.
var matrices = new Tuple<string, double[][]>[outputs.Length];
for (var i = 0; i < outputs.Length; i++)
{
var weights = new double[source.Length][];
for (var x = 0; x < weights.Length; x++)
{
weights[x] = new double[target.Length];
for (var y = 0; y < target.Length; y++)
{
weights[x][y] = 100;
}
}
matrices[i] = new Tuple<string, double[][]>(outputs[i],
weights);
}
return matrices;
}
示例14: TestGeoCoordinateOffsetEstimate
public void TestGeoCoordinateOffsetEstimate()
{
GeoCoordinate coord1 = new GeoCoordinate(51, 4.8);
Meter distance = 10000;
GeoCoordinate coord3 = coord1.OffsetWithDistances(distance);
GeoCoordinate coord3_lat = new GeoCoordinate(coord3.Latitude, coord1.Longitude);
GeoCoordinate coord3_lon = new GeoCoordinate(coord1.Latitude, coord3.Longitude);
Meter distance_lat = coord3_lat.DistanceReal(coord1);
Meter distance_lon = coord3_lon.DistanceReal(coord1);
Assert.AreEqual(distance.Value, distance_lat.Value, 0.001);
Assert.AreEqual(distance.Value, distance_lon.Value, 0.001);
}
示例15: _mapView_MapTapEvent
/// <summary>
/// Handles the tap event.
/// </summary>
/// <param name="coordinate"></param>
async void _mapView_MapTapEvent(GeoCoordinate coordinate)
{
if (_previous != null)
{
var route = RouterFacade.Calculate(_previous, coordinate);
_routeLayer.Clear();
if (route != null)
{
_routeLayer.AddRoute(route);
// TODO: issue #120.
(_mapView as IMapView).Invalidate();
}
}
_previous = coordinate;
}