Compartir a través de


Datos espaciales en el proveedor SQL Server de EF Core

En esta página se incluye información adicional sobre el uso de datos espaciales con el proveedor de bases de datos Microsoft SQL Server. Para obtener información general sobre el uso de datos espaciales en EF Core, vea la documentación principal de Datos espaciales.

Geografía o geometría

De manera predeterminada, las propiedades espaciales se asignan a columnas geography de SQL Server. Para usar geometry, configure el tipo de columna en el modelo.

Anillos de polígono de geografía

Al usar el tipo de columna geography, SQL Server impone requisitos adicionales en el anillo exterior (o shell) y anillos interiores (o agujeros). El anillo exterior debe orientarse en sentido contrario a las agujas de las agujas del reloj y los anillos interiores en el sentido de las agujas del reloj. NetTopologySuite (NTS) valida esto antes de enviar valores a la base de datos.

FullGlobe

SQL Server tiene un tipo de geometría no estándar para representar todo el globo cuando se usa el tipo de columna geography. También tiene una manera de representar polígonos basados en todo el globo (sin un anillo exterior). En NTS no se admite ninguno de estos elementos.

Advertencia

FullGlobe y los polígonos basados en FullGlobe no se admiten en NTS.

Curvas

Como se menciona en la documentación principal de Datos espaciales, actualmente NTS no puede representar curvas. Esto significa que tendrá que transformar los valores CircularString, CompoundCurve y CurePolygon mediante el método STCurveToLine antes de usarlos en EF Core.

Advertencia

NTS no admite CircularString, CompoundCurve ni CurePolygon.

Asignaciones de funciones espaciales

En esta tabla se muestran los miembros de NTS traducidos a funciones SQL. Tenga en cuenta que las traducciones varían en función de si la columna es de tipo geografía o geometría.

.NET SQL (geografía) SQL (geometría) Agregado en
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 ... FIN CASE @geometry.STGeometryType() WHEN N"Point" THEN 1 ... FIN
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()

Funciones de agregado

.NET SQL Agregado en
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

Recursos adicionales