Skip to content

Commit

Permalink
NaturalEarth data as test
Browse files Browse the repository at this point in the history
  • Loading branch information
xfischer committed Oct 24, 2016
1 parent 7c7dca3 commit a74b0a1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
52 changes: 41 additions & 11 deletions SqlServerSpatial.Toolkit.Test/NaturalEarthData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,32 @@ namespace SqlServerSpatial.Toolkit.Test
{
static class NaturalEarthData
{
private static List<string> naturalEarthTables = null;
private const string naturalEarthconnectionString = @"Data Source=.\MSSQL2014;Initial Catalog=NaturalEarth_CulturalVectors_110;Integrated Security=True";
public static List<string> GetNaturalEarthTables()
public enum DataSetType { Cultural, Physical }

private static Dictionary<string, HashSet<string>> naturalEarthTables = new Dictionary<string, HashSet<string>>();
private const string naturalEarthCulturalconnectionString = @"Data Source=.\MSSQL2014;Initial Catalog=NaturalEarth_CulturalVectors_110;Integrated Security=True;Connection Timeout=5";
private const string naturalEarthPhysicalconnectionString = @"Data Source=.\MSSQL2014;Initial Catalog=NaturalEarth_PhysicalVectors_110;Integrated Security=True;Connection Timeout=5";

public static List<string> GetNaturalEarthTables(DataSetType dataSet)
{
if (dataSet == DataSetType.Cultural)
{
return GetNaturalEarthTables(naturalEarthCulturalconnectionString);
}
else if (dataSet == DataSetType.Physical)
{
return GetNaturalEarthTables(naturalEarthPhysicalconnectionString);
}
else
return null;
}
private static List<string> GetNaturalEarthTables(string connectionString)
{
if (naturalEarthTables == null)
if (!naturalEarthTables.ContainsKey(connectionString))
{
naturalEarthTables = new List<string>();
naturalEarthTables.Add(connectionString, new HashSet<string>());

using (SqlConnection con = new SqlConnection(naturalEarthconnectionString))
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand com = new SqlCommand("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES", con))
Expand All @@ -29,20 +46,33 @@ public static List<string> GetNaturalEarthTables()
{
while (dr.Read())
{
naturalEarthTables.Add(dr.GetString(0));
naturalEarthTables[connectionString].Add(dr.GetString(0));
}
}
}
}
}

return naturalEarthTables;
return naturalEarthTables[connectionString].ToList();
}

public static List<NaturalEarthRow> GetNatualEarthTableRows(string tableName)
public static List<NaturalEarthRow> GetNaturalEarthTableRows(DataSetType dataSet, string tableName)
{
if (dataSet == DataSetType.Cultural)
{
return GetNaturalEarthTableRows(tableName, naturalEarthCulturalconnectionString);
}
else if (dataSet == DataSetType.Physical)
{
return GetNaturalEarthTableRows(tableName, naturalEarthPhysicalconnectionString);
}
else
return null;
}
private static List<NaturalEarthRow> GetNaturalEarthTableRows(string tableName, string connectionString)
{
List<NaturalEarthRow> rows = new List<NaturalEarthRow>();
using (SqlConnection con = new SqlConnection(naturalEarthconnectionString))
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand com = new SqlCommand(string.Format("SELECT * FROM [{0}]", tableName), con))
Expand Down Expand Up @@ -76,7 +106,7 @@ public static List<NaturalEarthRow> GetNatualEarthTableRows(string tableName)
return rows;
}


private static ColInfo FindColumnByNameOrType(List<ColInfo> colInfos, string colName, string typeName = null)
{
ColInfo nameCol = colInfos.FirstOrDefault(c => c.Name.ToLower() == colName);
Expand Down
21 changes: 12 additions & 9 deletions SqlServerSpatial.Toolkit.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ static void Main(string[] args)
{
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

TestNaturalEarth();
TestNaturalEarth110();

//TestTrace();

//TestVariousGeometries();

TestWorld(true, true);
}

private static void TestNaturalEarth()
private static void TestNaturalEarth110()
{
foreach(string table in NaturalEarthData.GetNaturalEarthTables())
foreach(string table in NaturalEarthData.GetNaturalEarthTables(NaturalEarthData.DataSetType.Cultural))
{
TraceNaturalEarthTable(NaturalEarthData.DataSetType.Cultural, table);
}
foreach (string table in NaturalEarthData.GetNaturalEarthTables(NaturalEarthData.DataSetType.Physical))
{
TraceNaturalEarthTable(table);
TraceNaturalEarthTable(NaturalEarthData.DataSetType.Physical, table);
}
SpatialTrace.ShowDialog();
}
Expand Down Expand Up @@ -120,14 +125,14 @@ static void TestCentroid()
SpatialTrace.Clear();
}

static void TraceNaturalEarthTable(string tableName)
static void TraceNaturalEarthTable(NaturalEarthData.DataSetType dataSet, string tableName)
{
if (NaturalEarthData.GetNaturalEarthTables().Contains(tableName))
if (NaturalEarthData.GetNaturalEarthTables(dataSet).Contains(tableName))
{
SpatialTrace.Enable();
SpatialTrace.Indent(tableName);

foreach (NaturalEarthRow neRow in NaturalEarthData.GetNatualEarthTableRows(tableName))
foreach (NaturalEarthRow neRow in NaturalEarthData.GetNaturalEarthTableRows(dataSet, tableName))
{
SpatialTrace.TraceGeometry(neRow.Geometry, neRow.name, neRow.name);
}
Expand All @@ -142,8 +147,6 @@ static void TraceNaturalEarthTable(string tableName)

}



static void TestWorld(bool useLabels = false, bool useIndents = false)
{
SpatialTrace.Enable();
Expand Down

0 comments on commit a74b0a1

Please sign in to comment.