SQL Server - Praca z warstwami GIS w bazach danych MSSQL za pomocą C#
Contents
[
Hide
]
SQL Server to jedna z najczęściej używanych baz danych wśród oprogramowania. Aspose.GIS umożliwia pracę z bazami danych PostgreSQL.
Iteracja po warstwach w bazie danych SqlServer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
// First, we create the connection to the SQL Server. | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
connection.Open(); | |
// Then, we pass this connection to Dataset.Open method in order to access tables in the SQL Server. | |
using (var ds = Dataset.Open(connection, Drivers.SqlServer)) | |
{ | |
// Only spatial tables are exported as layers, so the following code will list all tables | |
// that have geometry column. | |
for (int i = 0; i < ds.LayersCount; ++i) | |
{ | |
Console.WriteLine(ds.GetLayerName(i)); | |
} | |
} | |
} |
Dodawanie nowej warstwy w bazie danych SqlServer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
// First, we create the connection to the SQL Server. | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
connection.Open(); | |
// Then, we pass this connection to Dataset.Open method in order to access tables in the SQL Server. | |
using (var ds = Dataset.Open(connection, Drivers.SqlServer)) | |
{ | |
// create table with the name "features_table" and fill it with data. | |
using (var layer = ds.CreateLayer("features_table")) | |
{ | |
layer.Attributes.Add(new FeatureAttribute("name", AttributeDataType.String) { Width = 50 }); | |
var feature = layer.ConstructFeature(); | |
feature.SetValue("name", "Name1"); | |
feature.Geometry = Geometry.FromText("POINT (10 20 30)"); | |
layer.Add(feature); | |
feature = layer.ConstructFeature(); | |
feature.SetValue("name", "Name2"); | |
feature.Geometry = Geometry.FromText("POINT (-10 -20 -30)"); | |
layer.Add(feature); | |
} | |
} | |
} |
Eksportowanie warstwy z bazy danych SqlServer do formatu pliku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
var outputPath = Path.Combine(RunExamples.GetDataDir(), "sql_server_out.kml"); | |
// First, we create the connection to the SQL Server. | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
connection.Open(); | |
// Then, we pass this connection to Dataset.Open method in order to access tables in the SQL Server. | |
using (var ds = Dataset.Open(connection, Drivers.SqlServer)) | |
{ | |
// open table with the name "features_table" in SQL Server database and save it to the Kml. | |
using (var table = ds.OpenLayer("features_table")) | |
{ | |
table.SaveTo(outputPath, Drivers.Kml); | |
} | |
Console.WriteLine("\nExport complete: " + outputPath); | |
} | |
} |
Usuwanie warstwy z bazy danych SqlServer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
// First, we create the connection to the SQL Server. | |
using (var connection = new SqlConnection(connectionString)) | |
{ | |
connection.Open(); | |
// Then, we pass this connection to Dataset.Open method in order to access tables in the SQL Server. | |
using (var ds = Dataset.Open(connection, Drivers.SqlServer)) | |
{ | |
// remove table with the name "features_table". | |
// It possible remove a table with geospatial data only. | |
// An exception isn't thrown if the table doesn't exist. | |
ds.RemoveLayer("features_table"); | |
} | |
} |