次の方法で共有


SQL Server EF Core プロバイダーでの空間データ

このページには、Microsoft SQL Server データベース プロバイダーでの空間データの使用に関する追加情報が含まれています。 EF Core での空間データの使用に関する一般的な情報については、メインの空間データに関するドキュメントを参照してください。

geography または geometry

既定では、空間プロパティは、SQL Server の geography 列にマップされます。 geometry を使用するには、モデルの列の型を構成します

地理的多角形リング

geography 列型を使用する場合、SQL Server では、外部リング (またはシェル) と内部リング (またはホール) に追加の要件が課されます。 外部リングは反時計回り、内部リングは時計回りを向いている必要があります。 NetTopologySuite (NTS) では、データベースに値を送信する前にこれを検証します。

FullGlobe

SQL Server には、geography 列型を使用する場合に地球全体を表す非標準の geometry 型 があります。 また、地球全体に基づいて (外部リングなしで) 多角形を表す方法も用意されています。 どちらも NTS ではサポートされません。

警告

NTS では、FullGlobe と、これに基づく多角形はサポートされません。

カーブ

メインの空間データに関するドキュメントで説明したように、NTS では現在、曲線を表すことができません。 つまり、EF Core で使用する前に、STCurveToLine メソッドを使用して、CircularString、CompoundCurve、および CircularPolygon の値を変換する必要があります。

警告

NTS では CircularString、CompoundCurve、CircularPolygon はサポートされません。

空間関数のマッピング

次の表は、どの NTS メンバーがどの SQL 関数に変換されるかを示しています。 変換は、列が geography 型か geometry 型かによって異なります。

.NET SQL (geography) SQL (geometry) 追加されたバージョン:
EF.Functions.CurveToLine(geometry) @geometry.STCurveToLine() @geometry.STCurveToLine() EF Core 7.0
geometry.Area @geometry.STArea() @geometry.STArea()
geometry.AsBinary() @geometry.STAsBinary() @geometry.STAsBinary()
geometry.AsText() @geometry.AsTextZM() @geometry.AsTextZM()
geometry.Boundary @geometry.STBoundary()
geometry.Buffer(distance) @geometry.STBuffer(@distance) @geometry.STBuffer(@distance)
geometry.Centroid @geometry.STCentroid()
geometry.Contains(g) @geometry.STContains(@g) @geometry.STContains(@g)
geometry.ConvexHull() @geometry.STConvexHull() @geometry.STConvexHull()
geometry.Crosses(g) @geometry.STCrosses(@g)
geometry.Difference(other) @geometry.STDifference(@other) @geometry.STDifference(@other)
geometry.Dimension @geometry.STDimension() @geometry.STDimension()
geometry.Disjoint(g) @geometry.STDisjoint(@g) @geometry.STDisjoint(@g)
geometry.Distance(g) @geometry.STDistance(@g) @geometry.STDistance(@g)
geometry.Envelope @geometry.STEnvelope()
geometry.EqualsTopologically(g) @geometry.STEquals(@g) @geometry.STEquals(@g)
geometry.GeometryType @geometry.STGeometryType() @geometry.STGeometryType()
geometry.GetGeometryN(n) @geometry.STGeometryN(@n + 1) @geometry.STGeometryN(@n + 1)
geometry.InteriorPoint @geometry.STPointOnSurface()
geometry.Intersection(other) @geometry.STIntersection(@other) @geometry.STIntersection(@other)
geometry.Intersects(g) @geometry.STIntersects(@g) @geometry.STIntersects(@g)
geometry.IsEmpty @geometry.STIsEmpty() @geometry.STIsEmpty()
geometry.IsSimple @geometry.STIsSimple()
geometry.IsValid @geometry.STIsValid() @geometry.STIsValid()
geometry.IsWithinDistance(geom, distance) @geometry.STDistance(@geom)<= @distance @geometry.STDistance(@geom)<= @distance
geometry.Length @geometry.STLength() @geometry.STLength()
geometry.NumGeometries @geometry.STNumGeometries() @geometry.STNumGeometries()
geometry.NumPoints @geometry.STNumPoints() @geometry.STNumPoints()
geometry.OgcGeometryType CASE @geometry.STGeometryType() WHEN N'Point' THEN 1 ...End CASE @geometry.STGeometryType() WHEN N'Point' THEN 1 ...End
geometry.Overlaps(g) @geometry.STOverlaps(@g) @geometry.STOverlaps(@g)
geometry.PointOnSurface @geometry.STPointOnSurface()
geometry.Relate(g, intersectionPattern) @geometry.STRelate(@g、@intersectionPattern)
geometry.SRID @geometry.STSrid @geometry.STSrid
geometry.SymmetricDifference(other) @geometry.STSymDifference(@other) @geometry.STSymDifference(@other)
geometry.ToBinary() @geometry.STAsBinary() @geometry.STAsBinary()
geometry.ToText() @geometry.AsTextZM() @geometry.AsTextZM()
geometry.Touches(g) @geometry.STTouches(@g)
geometry.Union(other) @geometry.STUnion(@other) @geometry.STUnion(@other)
geometry.Within(g) @geometry.STWithin(@g) @geometry.STWithin(@g)
geometryCollection[i] @geometryCollection.STGeometryN(@i + 1) @geometryCollection.STGeometryN(@i + 1)
geometryCollection.Count @geometryCollection.STNumGeometries() @geometryCollection.STNumGeometries()
lineString.Count @lineString.STNumPoints() @lineString.STNumPoints()
lineString.EndPoint @lineString.STEndPoint() @lineString.STEndPoint()
lineString.GetPointN(n) @lineString.STPointN(@n + 1) @lineString.STPointN(@n + 1)
lineString.IsClosed @lineString.STIsClosed() @lineString.STIsClosed()
lineString.IsRing @lineString.IsRing()
lineString.StartPoint @lineString.STStartPoint() @lineString.STStartPoint()
multiLineString.IsClosed @multiLineString.STIsClosed() @multiLineString.STIsClosed()
point.M @point.M @point.M
point.X @point.Long @point.STX
point.Y @point.Lat @point.STY
point.Z @point.Z @point.Z
polygon.ExteriorRing @polygon.RingN(1) @polygon.STExteriorRing()
polygon.GetInteriorRingN(n) @polygon.RingN(@n + 2) @polygon.STInteriorRingN(@n + 1)
polygon.NumInteriorRings @polygon.NumRings() - 1 @polygon.STNumInteriorRing()

集計関数

.NET SQL 追加されたバージョン:
GeometryCombiner.Combine(group.Select(x => x.Property)) CollectionAggregate(Property) EF Core 7.0
ConvexHull.Create(group.Select(x => x.Property)) ConvexHullAggregate(Property) EF Core 7.0
UnaryUnionOp.Union(group.Select(x => x.Property)) UnionAggregate(Property) EF Core 7.0
EnvelopeCombiner.CombineAsGeometry(group.Select(x => x.Property)) EnvelopeAggregate(Property) EF Core 7.0

その他のリソース