Esempio n. 1
0
 public void LineString()
 {
     var reader = new GeoJsonReader();
     var geo = new LineString(new Coordinate(0, 0), new Coordinate(1, 1));
     Assert.AreEqual(@"{""type"":""LineString"",""coordinates"":[[0,0],[1,1]]}",
         geo.ToGeoJson());
     Assert.AreEqual(geo, reader.Read(geo.ToGeoJson()));
 }
		private static bool TryReadRoute(RavenJObject geo, LineString lineString, out object result)
		{
			var route = new Route();
			route.Coordinates.AddRange(lineString.Coordinates);
			ReadMetadata(geo, route.Metadata);
			result = route;
			return true;
		}
Esempio n. 3
0
 public void LineStringTests()
 {
     var lineString = new LineString(new[] { new Coordinate(0, 0), new Coordinate(1, 1), new Coordinate(1, 2) });
     AssertThatIndexPropertyIsGenerated(lineString);
     AssertTrue(lineString, SpatialRelation.Within, new Circle(0, 0, 600000));
     AssertFalse(lineString, SpatialRelation.Within, new Circle(0, 160, 600000));
     //AssertThat(lineString, SpatialRelation.Disjoint, new Circle(0, 160, 600000));
     AssertTrue(lineString, SpatialRelation.Intersects, new LineString(new[] { new Coordinate(1, 0), new Coordinate(0, 1) }));
     //AssertTrue(lineString, SpatialRelation.Intersects, new LineString(new[] { new Point(0, 1), new Point(1, 1), new Point(2, 1) }));
 }
        public void Encode()
        {
            var lineString = new LineString(new Coordinate(38.5, -120.2),
                                            new Coordinate(40.7, -120.95),
                                            new Coordinate(43.252, -126.453));

            var result = new GooglePolylineEncoder().Encode(lineString);

            Assert.AreEqual("_p~iF~ps|U_ulLnnqC_mqNvxq`@", result);
        }
Esempio n. 5
0
        public string Encode(LineString lineString)
        {
            var plat = 0;
            var plng = 0;

            var builder = new StringBuilder();

            foreach (var coordinate in lineString.Coordinates)
            {
                var late5 = (int)(coordinate.Latitude * CoordinateFactor);
                var lnge5 = (int)(coordinate.Longitude * CoordinateFactor);

                EncodeNumber(builder, late5 - plat);
                EncodeNumber(builder, lnge5 - plng);

                plat = late5;
                plng = lnge5;
            }

            return builder.ToString();
        }
		private static bool TryReadTrack(RavenJObject geo, LineString lineString, out object result)
		{
			var times = geo["times"] as RavenJArray;
			if (times != null)
			{
				var times2 = times.OfType<RavenJArray>().ToList();
				var track = new Track();
				ReadMetadata(geo, track.Metadata);
				var fixCount = 0;
				foreach (var ti in times2)
				{
					var tt = ti.OfType<RavenJValue>().Where(x => x.Type == JTokenType.String).Select(x => DateTime.Parse((string)x.Value)).ToList();

					var segment = new TrackSegment();
					for (var i = 0; i < tt.Count; i++)
					{
						if (fixCount + 1 > lineString.Coordinates.Count)
							break;

						var coord2D = lineString.Coordinates[fixCount];
						var coord3D = coord2D as Is3D;
						if (coord3D == null)
							segment.Fixes.Add(new Fix(coord2D.Latitude, coord2D.Longitude, tt[i]));
						else
							segment.Fixes.Add(new Fix(coord2D.Latitude, coord2D.Longitude,
													  coord3D.Elevation, tt[i]));
						fixCount++;
					}
					track.Segments.Add(segment);
				}

				if (fixCount == lineString.Coordinates.Count)
				{
					result = track;
					return true;
				}
			}
			result = default(object);
			return false;
		}
Esempio n. 7
0
 private bool TryParseLineString(JsonObject obj, out object result)
 {
     var coordinates = obj["coordinates"] as JsonArray;
     Coordinate[] co;
     if (coordinates != null && TryParseCoordinateArray(coordinates, out co))
     {
         result = new LineString(co);
         return true;
     }
     result = null;
     return false;
 }
Esempio n. 8
0
 private void AppendLineString(StringBuilder builder, LineString lineString)
 {
     builder.Append("LINESTRING");
     AppendDimensions(builder, lineString);
     builder.Append(" ");
     AppendLineStringInner(builder, lineString.Coordinates);
 }
Esempio n. 9
0
 private void WriteLineString(LineString lineString, WkbBinaryWriter writer)
 {
     WriteEncoding(writer, _settings.Encoding);
     WriteGeometryType(lineString, WkbGeometryType.LineString, writer);
     WriteCoordinates(lineString.Coordinates, writer);
 }
Esempio n. 10
0
 protected bool Equals(LineString other)
 {
     return Equals(Coordinates, other.Coordinates);
 }
Esempio n. 11
0
        /// <summary>
        /// Calculates the route.
        /// </summary>
        /// <param name="transportMode">The transport mode.</param>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <returns>
        /// A new <see cref="RouteModel" /> with the route details.
        /// </returns>
        public RouteModel CalculatePointToPoint(VehicleEnum transportMode, GeoCoordinate start, GeoCoordinate end)
        {
            // calculate route.
            var startPoint = router.Resolve(transportMode, start);
            var endPoint = router.Resolve(transportMode, end);
            var route = router.Calculate(transportMode, startPoint, endPoint);

            if (route == null)
            {
                throw new RoutingException("No matching route found.");
            }

            var coordinates = route.Entries
                .Select(x => new Coordinate(x.Latitude, x.Longitude))
                .ToList();

            var lineString = new LineString(coordinates);

            var feature = new Feature(
                lineString,
                new Dictionary<string, object>
                    {
                        { "name", "Test route result." },
                        { "distance", route.TotalDistance },
                        { "journeytime", route.TotalTime },
                    });

            var generator = new InstructionGenerator();
            var instructions = generator.Generate(route, interpreter, new SimpleEnglishLanguageGenerator());

            return new RouteModel
                       {
                           Results = new ResultSet(feature)
                       };
        }
Esempio n. 12
0
 private Dictionary<string, object> WriteLineString(LineString lineString)
 {
     return new Dictionary<string, object>
     {
         { "type", "LineString" },
         { "coordinates", WriteCoordinates(lineString.Coordinates) }
     };
 }