public void FastGeoJsonWriterShouldSerializeSameGeometryAsGeoJsonObjectWriter() { var geometrys = new Geometry[] { GeometryFactory.MultiPoint().Point(10.2, 11.2).Point(0.1, 0.1).Build(), GeometryFactory.Polygon().Ring(33.1, -110).LineTo(1,2).LineTo(35.97, -110.15).LineTo(11.45, 87.75).Ring(35.97, -110).LineTo(0.03, -0.01).LineTo(45.23, 23.10).Build() }; var converter = new GeometryTypeConverter(); ValidateSerializationResultShouldBeSame(OriginalWriteJsonLight, (instance, writer) => converter.WriteJsonLight(instance, writer), geometrys); }
static ODataSpatialTypeUtil() { // Geometry type values. GeometryValue = GeometryFactory.Point(32.0, -10.0).Build(); GeometryPointValue = GeometryFactory.Point(33.1, -11.0).Build(); GeometryLineStringValue = GeometryFactory.LineString(33.1, -11.5).LineTo(35.97, -11).Build(); GeometryPolygonValue = GeometryFactory.Polygon().Ring(33.1, -13.6).LineTo(35.97, -11.15).LineTo(11.45, 87.75).Ring(35.97, -11).LineTo(36.97, -11.15).LineTo(45.23, 23.18).Build(); GeometryCollectionValue = GeometryFactory.Collection().Point(-19.99, -12.0).Build(); GeometryMultiPointValue = GeometryFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build(); GeometryMultiLineStringValue = GeometryFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build(); GeometryMultiPolygonValue = GeometryFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build(); // Geography type values. GeographyValue = GeographyFactory.Point(32.0, -100.0).Build(); GeographyPointValue = GeographyFactory.Point(33.1, -110.0).Build(); GeographyLineStringValue = GeographyFactory.LineString(33.1, -110.0).LineTo(35.97, -110).Build(); GeographyPolygonValue = GeographyFactory.Polygon().Ring(33.1, -110.0).LineTo(35.97, -110.15).LineTo(11.45, 87.75).Ring(35.97, -110).LineTo(36.97, -110.15).LineTo(45.23, 23.18).Build(); GeographyCollectionValue = GeographyFactory.Collection().Point(-19.99, -12.0).Build(); GeographyMultiPointValue = GeographyFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build(); GeographyMultiLineStringValue = GeographyFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build(); GeographyMultiPolygonValue = GeographyFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build(); }
/// <summary> /// Try to parse the given text to a Geometry object. /// </summary> /// <param name="text">Text to parse.</param> /// <param name="targetValue">Geometry to return.</param> /// <param name="reason">The detailed reason of parsing error.</param> /// <returns>True if succeeds, false if not.</returns> private static bool TryUriStringToGeometry(string text, out Geometry targetValue, out string reason) { reason = null; if (!TryRemoveLiteralPrefix(ExpressionConstants.LiteralPrefixGeometry, ref text)) { targetValue = default(Geometry); return false; } if (!TryRemoveQuotes(ref text)) { targetValue = default(Geometry); return false; } try { targetValue = LiteralUtils.ParseGeometry(text); return true; } catch (ParseErrorException e) { targetValue = default(Geometry); reason = e.Message; return false; } }
/// <summary> /// Try to parse the given text to a Geometry object. /// </summary> /// <param name="text">Text to parse.</param> /// <param name="targetValue">Geometry to return.</param> /// <param name="parsingFailureReasonException">The detailed reason of parsing error.</param> /// <returns>True if succeeds, false if not.</returns> private static bool TryUriStringToGeometry(string text, out Geometry targetValue, out UriLiteralParsingException parsingFailureReasonException) { parsingFailureReasonException = null; if (!UriParserHelper.TryRemoveLiteralPrefix(ExpressionConstants.LiteralPrefixGeometry, ref text)) { targetValue = default(Geometry); return false; } if (!UriParserHelper.TryRemoveQuotes(ref text)) { targetValue = default(Geometry); return false; } try { targetValue = LiteralUtils.ParseGeometry(text); return true; } catch (ParseErrorException e) { targetValue = default(Geometry); parsingFailureReasonException = new UriLiteralParsingException(e.Message); return false; } }
/// <summary>Indicates the Geometry LineString's length.</summary> /// <returns>The operation result.</returns> /// <param name="operand">The Operand.</param> public virtual double Length(Geometry operand) { throw new NotImplementedException(); }
/// <summary>Indicates the Geometry Intersects() method.</summary> /// <returns>The operation result.</returns> /// <param name="operand1">The Operand 1, point.</param> /// <param name="operand2">The Operand 2, polygon.</param> public virtual bool Intersects(Geometry operand1, Geometry operand2) { throw new NotImplementedException(); }
/// <summary> /// Convert to string the given Geometry instance. /// </summary> /// <param name="instance">Instance to convert.</param> /// <returns>Well-known text representation.</returns> internal static string ToWellKnownText(Geometry instance) { return Formatter.Write(instance); }
/// <summary>Indicates the Geometry Distance.</summary> /// <returns>The operation result.</returns> /// <param name="operand1">The Operand 1.</param> /// <param name="operand2">The Operand 2.</param> public virtual double Distance(Geometry operand1, Geometry operand2) { throw new NotImplementedException(); }
/// <summary>Indicates the Geometry Intersects() method.</summary> /// <returns>The operation result.</returns> /// <param name="operand1">The Operand 1, point.</param> /// <param name="operand2">The Operand 2, polygon.</param> public override bool Intersects(Geometry operand1, Geometry operand2) { var point = operand1 as GeometryPoint; var polygon = operand2 as GeometryPolygon; if ((point != null) && (polygon != null)) { // mock logic for Intersects() method return polygon.Rings.Count <= 2 && polygon.Rings[0].Points[0].X < 32.1; } throw new NotImplementedException(); }
/// <summary>Indicates the Geometry LineString's length.</summary> /// <returns>The operation result.</returns> /// <param name="operand">The Operand.</param> public override double Length(Geometry operand) { UnitTestGeometryDistanceCalculator calc = new UnitTestGeometryDistanceCalculator(); var tmp = ((GeometryLineString)operand).Points; tmp[0].SendTo(calc); tmp[1].SendTo(calc); return calc.sum; }
public override double Distance(Geometry operand1, Geometry operand2) { UnitTestGeometryDistanceCalculator calc = new UnitTestGeometryDistanceCalculator(); operand1.SendTo(calc); operand2.SendTo(calc); return calc.sum; }
/// <summary>Determines if geometry point and polygon will intersect.</summary> /// <returns>The operation result.</returns> /// <param name="operand1">The first operand, point.</param> /// <param name="operand2">The second operand, polygon.</param> public static bool? Intersects(this Geometry operand1, Geometry operand2) { return OperationsFor(operand1, operand2).IfValidReturningNullable(ops => ops.Intersects(operand1, operand2)); }
/// <summary>Determines the distance of the geometry.</summary> /// <returns>The operation result.</returns> /// <param name="operand1">The first operand.</param> /// <param name="operand2">The second operand.</param> public static double? Distance(this Geometry operand1, Geometry operand2) { return OperationsFor(operand1, operand2).IfValidReturningNullable(ops => ops.Distance(operand1, operand2)); }