Exemplo n.º 1
0
        private void AppendCoordinate(StringBuilder builder, CoordinateInfo coordinate)
        {
            builder.Append(coordinate.X.ToString(CultureInfo.InvariantCulture));
            builder.Append(" ");
            builder.Append(coordinate.Y.ToString(CultureInfo.InvariantCulture));

            if (coordinate.Z.HasValue && _settings.MaxDimesions > 2)
            {
                builder.Append(" ");
                builder.Append(coordinate.Z.Value.ToString(CultureInfo.InvariantCulture));
            }

            if (coordinate.M.HasValue && _settings.MaxDimesions > 3)
            {
                builder.Append(" ");
                builder.Append(coordinate.M.Value.ToString(CultureInfo.InvariantCulture));
            }
        }
        private static void WriteJsonCoordinate(JsonWriter writer, CoordinateInfo coordinate)
        {
            writer.WriteStartArray();

            writer.WriteValue(coordinate.X);
            writer.WriteValue(coordinate.Y);

            if (coordinate.Z.HasValue)
            {
                writer.WriteValue(coordinate.Z.Value);
            }

            if (coordinate.Z.HasValue && coordinate.M.HasValue)
            {
                writer.WriteValue(coordinate.M.Value);
            }

            writer.WriteEndArray();
        }
 private bool TryParseCoordinate(RavenJArray coordinates, out CoordinateInfo result)
 {
     if (coordinates != null && coordinates.Length > 1 && coordinates.All(x => x is RavenJValue))
     {
         var vals = coordinates.Cast <RavenJValue>().ToList();
         if (vals.All(x => x.Type == JTokenType.Float || x.Type == JTokenType.Integer))
         {
             result = new CoordinateInfo
             {
                 X = Convert.ToDouble(vals[0].Value),
                 Y = Convert.ToDouble(vals[1].Value),
                 Z = vals.Count > 2 ? Convert.ToDouble(vals[2].Value) : (double?)null,
                 M = vals.Count > 3 ? Convert.ToDouble(vals[3].Value) : (double?)null
             };
             return(true);
         }
     }
     result = null;
     return(false);
 }
		private bool TryParseCoordinateArrayArrayArray(RavenJArray coordinates, out CoordinateInfo[][][] result)
		{
			result = null;
			if (coordinates == null)
				return false;

			var valid = coordinates.All(x => x is RavenJArray);
			if (!valid)
				return false;

			var tempResult = new CoordinateInfo[coordinates.Length][][];
			for (var index = 0; index < coordinates.Length; index++)
			{
				if (!TryParseCoordinateArrayArray((RavenJArray)coordinates[index], out tempResult[index]))
					return false;
			}
			result = tempResult;
			return true;
		}
		private bool TryParseCoordinate(RavenJArray coordinates, out CoordinateInfo result)
		{
			if (coordinates != null && coordinates.Length > 1 && coordinates.All(x => x is RavenJValue))
			{
				var vals = coordinates.Cast<RavenJValue>().ToList();
				if (vals.All(x => x.Type == JTokenType.Float || x.Type == JTokenType.Integer))
				{
					result = new CoordinateInfo
						{
							X = Convert.ToDouble(vals[0].Value),
							Y = Convert.ToDouble(vals[1].Value),
							Z = vals.Count > 2 ? Convert.ToDouble(vals[2].Value) : (double?) null,
							M = vals.Count > 3 ? Convert.ToDouble(vals[3].Value) : (double?) null
						};
					return true;
				}
			}
			result = null;
			return false;
		}
		private Dimensions GetDimensions(CoordinateInfo[] coordinates)
		{
			return coordinates.Aggregate(Dimensions.XY, (current, coordinate) => current | coordinate.GetDimensions());
		}
		private void AppendCoordinate(StringBuilder builder, CoordinateInfo coordinate)
		{
			builder.Append(coordinate.X.ToString(CultureInfo.InvariantCulture));
			builder.Append(" ");
			builder.Append(coordinate.Y.ToString(CultureInfo.InvariantCulture));

			if (coordinate.Z.HasValue && _settings.MaxDimesions > 2)
			{
				builder.Append(" ");
				builder.Append(coordinate.Z.Value.ToString(CultureInfo.InvariantCulture));
			}

			if (coordinate.M.HasValue && _settings.MaxDimesions > 3)
			{
				builder.Append(" ");
				builder.Append(coordinate.M.Value.ToString(CultureInfo.InvariantCulture));
			}
		}
		private void AppendCoordinates(StringBuilder builder, CoordinateInfo[] coordinates)
		{
			for (var i = 0; i < coordinates.Length; i++)
			{
				if (i > 0)
					builder.Append(", ");
				AppendCoordinate(builder, coordinates[i]);
			}
		}
		//private void AppendTriangle(StringBuilder builder, object polygon)
		//{
		//	builder.Append("TRIANGLE");
		//	AppendDimensions(builder, polygon);
		//	builder.Append(" ");
		//	AppendPolygonInner(builder, polygon);
		//}

		private void AppendPolygonInner(StringBuilder builder, CoordinateInfo[][] polygon)
		{
			if (polygon.Length == 0)
			{
				builder.Append("EMPTY");
				return;
			}

			builder.Append("(");
			AppendLineStringInner(builder, polygon[0]);
			for (var i = 1; i < polygon.Length; i++)
			{
				builder.Append(", ");
				AppendLineStringInner(builder, polygon[i]);
			}
			builder.Append(")");
		}
Exemplo n.º 10
0
		//private void AppendLinearRing(StringBuilder builder, object linearRing)
		//{
		//	builder.Append("LINEARRING");
		//	AppendDimensions(builder, linearRing);
		//	builder.Append(" ");
		//	AppendLineStringInner(builder, linearRing.Coordinates);
		//}

		private void AppendLineStringInner(StringBuilder builder, CoordinateInfo[] lineString)
		{
			if (lineString.Length == 0)
			{
				builder.Append("EMPTY");
				return;
			}

			builder.Append("(");
			AppendCoordinates(builder, lineString);
			builder.Append(")");
		}
Exemplo n.º 11
0
		private void AppendPointInner(StringBuilder builder, CoordinateInfo point)
		{
			if (point == null)
			{
				builder.Append("EMPTY");
				return;
			}

			builder.Append("(");
			AppendCoordinate(builder, point);
			builder.Append(")");
		}
		protected static void WriteJsonCoordinatesEnumerable2(JsonWriter writer, CoordinateInfo[][][] coordinates)
		{
			writer.WriteStartArray();
			foreach (var coordinate in coordinates)
				WriteJsonCoordinatesEnumerable(writer, coordinate);
			writer.WriteEndArray();
		}
		private static void WriteJsonCoordinate(JsonWriter writer, CoordinateInfo coordinate)
		{
			writer.WriteStartArray();

			writer.WriteValue(coordinate.X);
			writer.WriteValue(coordinate.Y);

			if (coordinate.Z.HasValue)
				writer.WriteValue(coordinate.Z.Value);

			if (coordinate.Z.HasValue && coordinate.M.HasValue)
				writer.WriteValue(coordinate.M.Value);

			writer.WriteEndArray();
		}