Räumliche Daten im SQLite-EF Core-AnbieterSpatial Data in the SQLite EF Core Provider

Diese Seite enthält zusätzliche Informationen zur Verwendung räumlicher Daten mit dem SQLite-Datenbankanbieter.This page includes additional information about using spatial data with the SQLite database provider. Allgemeine Informationen zur Verwendung räumlicher Daten in EF Core finden Sie in der Haupt Dokumentation zu räumlichen Daten .For general information about using spatial data in EF Core, see the main Spatial Data documentation.

Installieren von spatialiteInstalling SpatiaLite

Unter Windows wird die native mod_spatialite Bibliothek als eine nuget-Paketabhängigkeit verteilt.On Windows, the native mod_spatialite library is distributed as a NuGet package dependency. Andere Plattformen müssen Sie separat installieren.Other platforms need to install it separately. Dies erfolgt in der Regel mithilfe eines Softwarepaket-Managers.This is typically done using a software package manager. Beispielsweise können Sie apt für Debian und Ubuntu verwenden. und Homebrew unter MacOS.For example, you can use APT on Debian and Ubuntu; and Homebrew on MacOS.

# Debian/Ubuntu
apt-get install libsqlite3-mod-spatialite

# macOS
brew install libspatialite

Leider sind neuere Versionen von proj (eine Abhängigkeit von spatialite) mit dem standardmäßigen sqlitepclraw-Bundlevon EF nicht kompatibel.Unfortunately, newer versions of PROJ (a dependency of SpatiaLite) are incompatible with EF's default SQLitePCLRaw bundle. Sie können dieses Problem umgehen, indem Sie stattdessen die System SQLite-Bibliothek verwenden.You can work around this by using the system SQLite library instead.

<ItemGroup>
  <!-- Use bundle_sqlite3 instead with SpatiaLite on macOS and Linux -->
  <!--<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />-->
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.1.0" />
  <PackageReference Include="SQLitePCLRaw.bundle_sqlite3" Version="2.0.4" />

  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="3.1.0" />
</ItemGroup>

Unter macOSmüssen Sie auch eine Umgebungsvariable festlegen, bevor Sie Ihre APP ausführen, sodass Sie die Version von SQLite von Homebrew verwendet.On macOS, you'll also need set an environment variable before running your app so it uses Homebrew's version of SQLite. In Visual Studio für Mac können Sie diese Option Unterprojekt > Projektoptionen > > Konfigurationen ausführen > Standard Wert festlegen.In Visual Studio for Mac, you can set this under Project > Project Options > Run > Configurations > Default

DYLD_LIBRARY_PATH=/usr/local/opt/sqlite/lib

Konfigurieren von SRIDConfiguring SRID

In spatialite müssen Spalten eine SRID pro Spalte angeben.In SpatiaLite, columns need to specify an SRID per column. Der Standard-SRID ist 0 .The default SRID is 0. Geben Sie einen anderen SRID mithilfe der forsqlitehassrid-Methode an.Specify a different SRID using the ForSqliteHasSrid method.

modelBuilder.Entity<City>().Property(c => c.Location)
    .ForSqliteHasSrid(4326);

Hinweis

4326 bezieht sich auf WGS 84, einen in GPS und anderen geografischen Systemen verwendeten Standard.4326 refers to WGS 84, a standard used in GPS and other geographic systems.

DimensionDimension

Die Standard Dimension (oder Ordinate) einer Spalte ist X und Y. Konfigurieren Sie den Spaltentyp, um zusätzliche Ordinate wie Z oder M zu aktivieren.The default dimension (or ordinates) of a column is X and Y. To enable additional ordinates like Z or M, configure the column type.

modelBuilder.Entity<City>().Property(c => c.Location)
    .HasColumnType("POINTZ");

Zuordnungen für räumliche FunktionenSpatial function mappings

Diese Tabelle zeigt, welche nettopologysuite (NTS)-Member in welche SQL-Funktionen übersetzt werden.This table shows which NetTopologySuite (NTS) members are translated into which SQL functions.

.NET.NET SQLSQL
et. Feldgeometry.Area Bereich ( @geometry )Area(@geometry)
et. AsBinary ()geometry.AsBinary() AsBinary ( @geometry )AsBinary(@geometry)
et. AsText ()geometry.AsText() AsText ( @geometry )AsText(@geometry)
et. Begrenzungsgeometry.Boundary Grenze ( @geometry )Boundary(@geometry)
et. Puffer (Entfernung)geometry.Buffer(distance) Puffer ( @geometry , @distance )Buffer(@geometry, @distance)
et. Buffer (Distance, quadrantsegments)geometry.Buffer(distance, quadrantSegments) Puffer ( @geometry , @distance , @quadrantSegments )Buffer(@geometry, @distance, @quadrantSegments)
et. Schwerpunktgeometry.Centroid Centroid ( @geometry )Centroid(@geometry)
et. Enthält (g)geometry.Contains(g) Enthält ( @geometry , @g )Contains(@geometry, @g)
et. "Anvexhull ()"geometry.ConvexHull() "Anvexhull ( @geometry )"ConvexHull(@geometry)
et. Coveredby (g)geometry.CoveredBy(g) Coveredby ( @geometry , @g )CoveredBy(@geometry, @g)
et. Cover (g)geometry.Covers(g) Deckt ( @geometry , @g )Covers(@geometry, @g)
et. Kreuze (g)geometry.Crosses(g) Kreuze ( @geometry , @g )Crosses(@geometry, @g)
et. Differenz (sonstige)geometry.Difference(other) Differenz ( @geometry , @other )Difference(@geometry, @other)
et. Maßgeometry.Dimension Dimension ( @geometry )Dimension(@geometry)
et. Disjoint (g)geometry.Disjoint(g) Disjoint ( @geometry , @g )Disjoint(@geometry, @g)
et. Abstand (g)geometry.Distance(g) Abstand ( @geometry , @g )Distance(@geometry, @g)
et. Versendetgeometry.Envelope Umschlag ( @geometry )Envelope(@geometry)
et. Equalstopologisch (g)geometry.EqualsTopologically(g) Ist gleich( @geometry , @g )Equals(@geometry, @g)
et. Geometrytypegeometry.GeometryType Geometrytype ( @geometry )GeometryType(@geometry)
et. Getgeometryn (n)geometry.GetGeometryN(n) Geometryn ( @geometry , @n + 1)GeometryN(@geometry, @n + 1)
et. Interiorpointgeometry.InteriorPoint Pointonsurface ( @geometry )PointOnSurface(@geometry)
et. Schnittmenge (sonstige)geometry.Intersection(other) Schnittmenge ( @geometry , @other )Intersection(@geometry, @other)
et. Schnittpunkte (g)geometry.Intersects(g) Überschneidet ( @geometry , @g )Intersects(@geometry, @g)
et. IsEmptygeometry.IsEmpty IsEmpty ( @geometry )IsEmpty(@geometry)
et. IsSimplegeometry.IsSimple IsSimple ( @geometry )IsSimple(@geometry)
et. IsValidgeometry.IsValid IsValid ( @geometry )IsValid(@geometry)
et. Iswithindistance (Geom, Distance)geometry.IsWithinDistance(geom, distance) Distance ( @geometry , @geom ) <= @distanceDistance(@geometry, @geom) <= @distance
et. Füllgeometry.Length GLength ( @geometry )GLength(@geometry)
et. Numgeometriesgeometry.NumGeometries Numgeometries ( @geometry )NumGeometries(@geometry)
et. NumPointsgeometry.NumPoints NumPoints ( @geometry )NumPoints(@geometry)
et. Ogcgeometrytypegeometry.OgcGeometryType Fall geometrytype ( @geometry ), wenn ' Point ' dann 1... SchließlichCASE GeometryType(@geometry) WHEN 'POINT' THEN 1 ... END
et. Überlappungen (g)geometry.Overlaps(g) Überlappung ( @geometry , @g )Overlaps(@geometry, @g)
et. Pointonsurfacegeometry.PointOnSurface Pointonsurface ( @geometry )PointOnSurface(@geometry)
et. Beziehung (g, intersectionpattern)geometry.Relate(g, intersectionPattern) Beziehung ( @geometry , @g , @intersectionPattern )Relate(@geometry, @g, @intersectionPattern)
et. Umkehren ()geometry.Reverse() ST_Reverse ( @geometry )ST_Reverse(@geometry)
et. SRIDgeometry.SRID SRID ( @geometry )SRID(@geometry)
et. Symmetricdifference (sonstige)geometry.SymmetricDifference(other) Symdifference ( @geometry , @other )SymDifference(@geometry, @other)
et. "$ Binary ()"geometry.ToBinary() AsBinary ( @geometry )AsBinary(@geometry)
et. "-Text ()"geometry.ToText() AsText ( @geometry )AsText(@geometry)
et. Berührungen (g)geometry.Touches(g) Berührt ( @geometry , @g )Touches(@geometry, @g)
et. Union ()geometry.Union() Unaryunion ( @geometry )UnaryUnion(@geometry)
et. Union (sonstige)geometry.Union(other) Gunion ( @geometry , @other )GUnion(@geometry, @other)
et. In (g)geometry.Within(g) In ( @geometry , @g )Within(@geometry, @g)
GeometryCollection [i]geometryCollection[i] Geometryn ( @geometryCollection , @i + 1)GeometryN(@geometryCollection, @i + 1)
GeometryCollection. CountgeometryCollection.Count Numgeometries ( @geometryCollection )NumGeometries(@geometryCollection)
LineString. CountlineString.Count NumPoints ( @lineString )NumPoints(@lineString)
LineString. EndPointlineString.EndPoint Endpunkt ( @lineString )EndPoint(@lineString)
LineString. getpointn (n)lineString.GetPointN(n) Pointn ( @lineString , @n + 1)PointN(@lineString, @n + 1)
LineString. IsClosedlineString.IsClosed IsClosed ( @lineString )IsClosed(@lineString)
LineString. isringlineString.IsRing Isring ( @lineString )IsRing(@lineString)
LineString. StartPointlineString.StartPoint StartPoint ( @lineString )StartPoint(@lineString)
MultiLineString. IsClosedmultiLineString.IsClosed IsClosed ( @multiLineString )IsClosed(@multiLineString)
Punkt. 800point.M M ( @point )M(@point)
Punkt. Stubenpoint.X X ( @point )X(@point)
Punkt. Teeniepoint.Y J ( @point )Y(@point)
Punkt. Zpoint.Z Z ( @point )Z(@point)
Polygon. ExteriorRingpolygon.ExteriorRing ExteriorRing ( @polygon )ExteriorRing(@polygon)
Polygon. Getinteriorringn (n)polygon.GetInteriorRingN(n) Interiorringn ( @polygon , @n + 1)InteriorRingN(@polygon, @n + 1)
Polygon. Numinteriorringspolygon.NumInteriorRings Numinteriorring ( @polygon )NumInteriorRing(@polygon)

Zusätzliche RessourcenAdditional resources