public static ImportShapefile ( |
||
conn | ||
client | IDataClient | |
filename | string | |
tableName | string | |
srid | int | |
Результат | bool |
public static bool ImportShapefile(DbConnection conn, IDataClient client, string filename, string tableName, int srid)
{
try
{
if (!File.Exists(filename))
{
_log.ErrorFormat("ImportShapefile Failed!: File does not exist {0}", filename);
return false;
}
if (DataClient.HasTable(conn, client, tableName))
{
client.GetCommand(string.Format("DROP TABLE \"{0}\"", tableName)).ExecuteNonQuery();
}
//trim off the '.shp' from the end
filename = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename));
string sql = string.Format("CREATE VIRTUAL TABLE " + tableName + " USING VirtualShape('{0}', CP1252, {1});", filename, srid);
client.GetCommand(sql, conn).ExecuteNonQuery();
_log.DebugFormat("Imported Shapefile {0} into table {1}",
Path.GetFileNameWithoutExtension(filename),
tableName);
return true;
}
catch (Exception ex)
{
_log.Error("ImportShapefile failed: Error while loading shapefile ", ex);
}
return false;
}
/// <summary> /// Helper function for testing the shapefile importer /// </summary> /// <param name="filename"></param> /// <param name="tableName"></param> /// <returns></returns> public static bool OpenShapefile(string filename, string tableName) { string databaseFileName = Path.Combine(Path.GetDirectoryName(filename), "shape.dat"); var client = new SqliteDataClient(databaseFileName); using (DbConnection conn = client.GetConnection()) { return(ShapefileHelper.ImportShapefile(conn, client, filename, tableName, -1)); } }