.NET平臺使用spatilite擴展
源碼github地址在此纵东,記得點星:
https://github.com/brandonxiang/SpatialiteSharp
當(dāng)然你先在NuGet上引用SQLite的安裝包。然后就是擴展驻龟,你當(dāng)然可以嘗試采用類似python的方法——將mod_spatialite.dll的包設(shè)為環(huán)境變量,然后enable_extension
之類谅海。但是很麻煩赌朋,不適合數(shù)據(jù)遷移。
參考SpatialiteSharp卫漫,在NuGet上引用。一行代碼
SpatialiteLoader.Load(conn);
解決戰(zhàn)斗肾砂×惺辏看看源碼,其實很簡單镐确,就是判斷X86還是X64包吝,后面就是一樣的。
public class SpatialiteLoader
{
private static readonly object Lock = new object();
private static bool _haveSetPath;
/// <summary>
/// Loads mod_spatialite.dll on the given connection
/// </summary>
public static void Load(SQLiteConnection conn)
{
lock (Lock)
{
//Need to work out where the file is and add it to the path so it can load all the other dlls too
if (!_haveSetPath)
{
var spatialitePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), (Environment.Is64BitProcess ? "x64" : "x86"), "spatialite");
Environment.SetEnvironmentVariable("PATH", spatialitePath + ";" + Environment.GetEnvironmentVariable("PATH"));
_haveSetPath = true;
}
}
conn.LoadExtension("mod_spatialite.dll");
}
}
但是這個包在ASP NET中不能很好的運行源葫,因為.NET的路徑問題诗越,不過將路徑改成AppDomain.CurrentDomain.BaseDirectory
即可。具體參考我的Github
轉(zhuǎn)載息堂,請表明出處嚷狞。總目錄Awesome GIS