public void CanReadExtentFromGeoJsonFile() { 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); // Act // --- const string pathToOgrInfoExecutable = @"C:\Program Files\GDAL\ogrinfo.exe"; var result = OgrInfoCommandLineRunner.GetExtentFromGeoJson(new FileInfo(pathToOgrInfoExecutable), geoJson, totalMilliseconds); // Assert // ------ var expectedResult = new Tuple <double, double, double, double>(-122.825678, 45.555868, -122.272895, 45.938212); Assert.That(result.Item1, Is.EqualTo(expectedResult.Item1)); Assert.That(result.Item2, Is.EqualTo(expectedResult.Item2)); Assert.That(result.Item3, Is.EqualTo(expectedResult.Item3)); Assert.That(result.Item4, Is.EqualTo(expectedResult.Item4)); }
public void CanReadColumnNamesFromGeoJsonString() { 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, GdalGeoJsonTest.CoordinateSystemId, totalMilliseconds); var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true); var a = JsonTools.DeserializeObject <GeoJSON.Net.Feature.FeatureCollection>(geoJson); var columnList = new List <string> { "Ogr_Fid", "Ogr_Geometry", "MyIntColumn", "MyStringColumn", "MyFloatColumn" }; }
public void CanExecuteOgr2OgrForFileGdbToGeoJson() { // Arrange // ------- 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); // Assert // ------ Assert.That(geoJson, Contains.Substring("\"properties\":"), "Should have properties"); }
public void CanReadColumnNamesFromGeoJsonString() { // Arrange // ------- var gdbFileInfo = FileUtility.FirstMatchingFileUpDirectoryTree(@"LTInfo.Common\GdalOgr\SampleFileGeodatabase.gdb.zip"); const string sourceLayerName = "MySampleFeatureClass"; const int totalMilliseconds = 110000; const string pathToOgr2OgrExecutable = @"C:\Program Files\GDAL\ogr2ogr.exe"; var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(pathToOgr2OgrExecutable, LtInfoGeometryConfiguration.DefaultCoordinateSystemId, totalMilliseconds); // Act // --- var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true); // Assert // ------ var featureCollection = JsonTools.DeserializeObject <GeoJSON.Net.Feature.FeatureCollection>(geoJson); var propertyNames = featureCollection.Features.First().Properties.Select(x => x.Key).ToList(); var expectedPropertyNames = new List <string> { "MyStringColumn", "IgnoredTextColumn", "IgnoredIntColumn", "MyIntColumn", "MyFloatColumn", "Shape_Length", "Shape_Area" }; Assert.That(propertyNames, Is.EquivalentTo(expectedPropertyNames), "Should get expected columns"); }
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 } } }