public void SerializeToJsonTest() { // arrange var t0 = new Tile(0, new Wkx.BoundingBox()); var t1 = new Tile(1, new Wkx.BoundingBox()); var tiles = new List <Tile> { t0, t1 }; var translation = new double[] { -8406745.0078531764, 4744614.2577285888, 38.29 }; var bbox = new double[] { 0, 0, 1, 1 }; // act var json = TreeSerializer.ToJson(tiles, translation, bbox, 500, "replace"); var jsonobject = JObject.Parse(json); Assert.IsTrue(jsonobject != null); }
static void Main(string[] args) { var version = Assembly.GetEntryAssembly().GetName().Version; Console.WriteLine($"tool: pg2b3dm {version}"); Parser.Default.ParseArguments <Options>(args).WithParsed(o => { o.User = string.IsNullOrEmpty(o.User) ? Environment.UserName : o.User; o.Database = string.IsNullOrEmpty(o.Database) ? Environment.UserName : o.Database; var connectionString = $"Host={o.Host};Username={o.User};Database={o.Database};Port={o.Port}"; var istrusted = TrustedConnectionChecker.HasTrustedConnection(connectionString); if (!istrusted) { Console.Write($"password for user {o.User}: "); password = PasswordAsker.GetPassword(); connectionString += $";password={password}"; Console.WriteLine(); } Console.WriteLine($"start processing...."); var stopWatch = new Stopwatch(); stopWatch.Start(); var output = o.Output; var outputTiles = $"{output}{Path.DirectorySeparatorChar}tiles"; if (!Directory.Exists(output)) { Directory.CreateDirectory(output); } if (!Directory.Exists(outputTiles)) { Directory.CreateDirectory(outputTiles); } Console.WriteLine($"input table: {o.GeometryTable}"); if (o.Query != String.Empty) { Console.WriteLine($"query: {o.Query}"); } Console.WriteLine($"input geometry column: {o.GeometryColumn}"); Console.WriteLine($"output directory: {outputTiles}"); var geometryTable = o.GeometryTable; var geometryColumn = o.GeometryColumn; var idcolumn = o.IdColumn; var lodcolumn = o.LodColumn; var query = o.Query; var geometricErrors = Array.ConvertAll(o.GeometricErrors.Split(','), double.Parse);; var conn = new NpgsqlConnection(connectionString); var lods = (lodcolumn != string.Empty ? LodsRepository.GetLods(conn, geometryTable, lodcolumn, query) : new List <int> { 0 }); if ((geometricErrors.Length != lods.Count + 1) && lodcolumn == string.Empty) { Console.WriteLine($"lod levels: [{ String.Join(',', lods)}]"); Console.WriteLine($"geometric errors: {o.GeometricErrors}"); Console.WriteLine("error: parameter -g --geometricerrors is wrongly specified..."); Console.WriteLine("end of program..."); Environment.Exit(0); } if (lodcolumn != String.Empty) { Console.WriteLine($"lod levels: {String.Join(',', lods)}"); if (lods.Count >= geometricErrors.Length) { Console.WriteLine($"calculating geometric errors starting from {geometricErrors[0]}"); geometricErrors = GeometricErrorCalculator.GetGeometricErrors(geometricErrors[0], lods); } } ; Console.WriteLine("geometric errors: " + String.Join(',', geometricErrors)); var bbox3d = BoundingBoxRepository.GetBoundingBox3DForTable(conn, geometryTable, geometryColumn, query); // Console.WriteLine($"3D Boundingbox {geometryTable}.{geometryColumn}: [{bbox3d.XMin}, {bbox3d.YMin}, {bbox3d.ZMin},{bbox3d.XMax},{bbox3d.YMax}, {bbox3d.ZMax}]"); var translation = bbox3d.GetCenter().ToVector(); // Console.WriteLine($"translation {geometryTable}.{geometryColumn}: [{string.Join(',', translation) }]"); var boundingboxAllFeatures = BoundingBoxCalculator.TranslateRotateX(bbox3d, Reverse(translation), Math.PI / 2); var box = boundingboxAllFeatures.GetBox(); var sr = SpatialReferenceRepository.GetSpatialReference(conn, geometryTable, geometryColumn, query); Console.WriteLine($"spatial reference: {sr}"); var tiles = TileCutter.GetTiles(0, conn, o.ExtentTile, geometryTable, geometryColumn, bbox3d, sr, 0, lods, geometricErrors.Skip(1).ToArray(), lodcolumn, query); Console.WriteLine(); var nrOfTiles = RecursiveTileCounter.CountTiles(tiles.tiles, 0); Console.WriteLine($"tiles with features: {nrOfTiles} "); CalculateBoundingBoxes(translation, tiles.tiles, bbox3d.ZMin, bbox3d.ZMax); Console.WriteLine("writing tileset.json..."); var json = TreeSerializer.ToJson(tiles.tiles, translation, box, geometricErrors[0], o.Refinement); File.WriteAllText($"{o.Output}/tileset.json", json); WriteTiles(conn, geometryTable, geometryColumn, idcolumn, translation, tiles.tiles, sr, o.Output, 0, nrOfTiles, o.RoofColorColumn, o.AttributesColumn, o.LodColumn, query); stopWatch.Stop(); Console.WriteLine(); Console.WriteLine($"elapsed: {stopWatch.ElapsedMilliseconds / 1000} seconds"); Console.WriteLine("program finished."); }); }