Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected override string GenerateNonNullSqlLiteral(object value)
}

builder
.Append(geometry.AsText())
.Append(new WKTWriter(4).Write(geometry))
.Append('\'');

return builder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override Geometry FromJsonTyped(ref Utf8JsonReaderManager manager, object
/// <inheritdoc />
public override void ToJsonTyped(Utf8JsonWriter writer, Geometry value)
{
var wkt = value.ToText();
var wkt = new WKTWriter(4).Write(value);

// If the SRID is defined, prefix the WKT with it (SRID=4326;POINT(-44.3 60.1))
// Although this is a PostgreSQL extension, NetTopologySuite supports it (see #3236)
Expand Down
4 changes: 2 additions & 2 deletions test/EFCore.PG.FunctionalTests/JsonTypesNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public override async Task Can_read_write_point_with_M()
await Can_read_and_write_JSON_value<PointMType, Point>(
nameof(PointMType.PointM),
factory.CreatePoint(new CoordinateM(2, 4, 6)),
"""{"Prop":"SRID=4326;POINT (2 4)"}""");
"""{"Prop":"SRID=4326;POINT M(2 4 6)"}""");
}

public override async Task Can_read_write_point_with_Z()
Expand All @@ -508,7 +508,7 @@ public override async Task Can_read_write_point_with_Z_and_M()
await Can_read_and_write_JSON_value<PointZMType, Point>(
nameof(PointZMType.PointZM),
factory.CreatePoint(new CoordinateZM(1, 2, 3, 4)),
"""{"Prop":"SRID=4326;POINT Z(1 2 3)"}""");
"""{"Prop":"SRID=4326;POINT ZM(1 2 3 4)"}""");
}

public override async Task Can_read_write_line_string()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using NetTopologySuite.Geometries;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage;

public class NpgsqlNetTopologySuiteTypeMappingTest
{
[Fact]
public void GenerateSqlLiteral_returns_point_literal()
=> Assert.Equal(
"GEOMETRY 'POINT (1 2)'",
new NpgsqlGeometryTypeMapping<Point>("geometry", isGeography: false).GenerateSqlLiteral(new Point(1, 2)));

[Fact]
public void GenerateSqlLiteral_returns_point_literal_with_Z()
=> Assert.Equal(
"GEOMETRY 'POINT Z(1 2 3)'",
new NpgsqlGeometryTypeMapping<Point>("geometry", isGeography: false).GenerateSqlLiteral(new Point(new CoordinateZ(1, 2, 3))));

[Fact] // #4093
public void GenerateSqlLiteral_returns_point_literal_with_M()
=> Assert.Equal(
"GEOMETRY 'POINT M(1 2 4)'",
new NpgsqlGeometryTypeMapping<Point>("geometry", isGeography: false).GenerateSqlLiteral(new Point(new CoordinateM(1, 2, 4))));

[Fact] // #4093
public void GenerateSqlLiteral_returns_point_literal_with_Z_and_M()
=> Assert.Equal(
"GEOGRAPHY 'SRID=4326;POINT ZM(1 2 3 4)'",
new NpgsqlGeometryTypeMapping<Point>("geography", isGeography: true).GenerateSqlLiteral(
new Point(new CoordinateZM(1, 2, 3, 4)) { SRID = 4326 }));
}