public void CanExecuteOgr2OgrFromGeoJsonSingleColumnToExistingMsSql() { var gdbFileInfo = FileUtility.FirstMatchingFileUpDirectoryTree(@"LTInfo.Common\GdalOgr\SampleFileGeodatabase.gdb.zip"); const string sourceLayerName = "MySampleFeatureClass"; // Act // --- const int totalMilliseconds = 110000; const string pathToOgr2OgrExecutable = @"C:\Program Files\GDAL\ogr2ogr.exe"; var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(pathToOgr2OgrExecutable, CoordinateSystemId, totalMilliseconds); var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true); var sourceColumnName1 = "mystringcolumn"; var destinationTableName = "test_table"; var destinationColumnName = "attribute"; try { CreateOgrRequiredTables(destinationTableName, null); // Act // --- ogr2OgrCommandLineRunner.ImportGeoJsonToMsSql(geoJson, TempDbSqlDatabase.DatabaseConnectionStringToTempDb, destinationTableName, sourceColumnName1, destinationColumnName, string.Format(", {0} as ProjectID", 77)); var result = ExecAdHocSql($"select * from {destinationTableName}"); // Assert // ------ Assert.That(result, Is.Not.Null, "Should have found the table imported"); Assert.That(result.Rows.Count, Is.EqualTo(6), "Should have gotten 6 rows"); //var myStringColumns = result.Rows.Cast<DataRow>().Select(x => x.IsNull(destinationColumnName) ? null : x[destinationColumnName].ToString()).ToList(); //Assert.That(myStringColumns, Is.EquivalentTo(new[] { "?\0Excavate channels to lakes", "?\0Excavate channels to lakes", null, null, "?\0LCEP s", "?\0LCEP s" }), "Should have gotten these values for MyStringColumn"); } finally { // Cleanup // ------- try { ExecAdHocSql("drop table " + destinationTableName); } catch { // ignored } try { ExecAdHocSql("drop table spatial_ref_sys"); } catch { // ignored } try { ExecAdHocSql("drop table geometry_columns"); } catch { // ignored } } }
public void CanExecuteOgr2OgrFromGeoJsonSingleColumnToExistingMsSql() { AssertCustom.IgnoreOnBuildServer(); var gdbFileInfo = FileUtility.FirstMatchingFileUpDirectoryTree(@"LTInfo.Common\GdalOgr\SampleFileGeodatabase.gdb.zip"); const string sourceLayerName = "MySampleFeatureClass"; // Act // --- const int totalMilliseconds = 110000; const string pathToOgr2OgrExecutable = @"C:\Program Files\GDAL\ogr2ogr.exe"; var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(pathToOgr2OgrExecutable, CoordinateSystemId, totalMilliseconds); var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true); var destinationTableName = "test_table"; var sqlSelectClause = string.Format("mystringcolumn as attribute, {0} as ProjectID", 77); try { CreateOgrRequiredTables(destinationTableName, null); // Act // --- ogr2OgrCommandLineRunner.ImportGeoJsonToMsSql(geoJson, TempDbSqlDatabase.DatabaseConnectionStringToTempDb, destinationTableName, sqlSelectClause); var result = ExecAdHocSql(string.Format("select * from {0}", destinationTableName)); // Assert // ------ Assert.That(result, Is.Not.Null, "Should have found the table imported"); Assert.That(result.Rows.Count, Is.EqualTo(6), "Should have gotten 6 rows"); } finally { // Cleanup // ------- try { ExecAdHocSql("drop table " + destinationTableName); } catch { // ignored } try { ExecAdHocSql("drop table spatial_ref_sys"); } catch { // ignored } try { ExecAdHocSql("drop table geometry_columns"); } catch { // ignored } } }