public void OsmAllWithTerrain(string name, string bboxWKT, bool centerOnOrigin, float ZScale) { DEMDataSet dataset = DEMDataSet.NASADEM; var bbox = GeometryService.GetBoundingBox(bboxWKT); bool computeElevations = false; string outputDir = Directory.GetCurrentDirectory(); var transform = new ModelGenerationTransform(bbox, Reprojection.SRID_PROJECTED_MERCATOR, centerOnOrigin: centerOnOrigin, ZScale, centerOnZOrigin: false); var heightMap = _elevationService.GetHeightMap(ref bbox, dataset); transform.BoundingBox = bbox; // bbox changed by GetHeigtMap heightMap = transform.TransformHeightMap(heightMap); TileRange tiles = _imageryService.DownloadTiles(bbox, ImageryProvider.EsriWorldImagery, 15); string fileName = Path.Combine(outputDir, "Texture.jpg"); TextureInfo texInfo = _imageryService.ConstructTexture(tiles, bbox, fileName, TextureImageFormat.image_jpeg); var pbrTexture = PBRTexture.Create(texInfo, null); ModelRoot model = _osmProcessor.Run(null, OsmLayer.Buildings | OsmLayer.Highways, bbox, transform, computeElevations, dataset, downloadMissingFiles: true); model = _gltfService.AddTerrainMesh(model, heightMap, pbrTexture); model.SaveGLB(Path.Combine(outputDir, $"{nameof(OsmAllWithTerrain)}_{name}" + ".glb")); }
internal void Run(string wkt, string name, DEMDataSet dataSet, int precisionMeters = 10) { try { int outputSrid = Reprojection.SRID_PROJECTED_MERCATOR; var bbox = GeometryService.GetBoundingBox(wkt); _logger.LogInformation($"Getting height map..."); HeightMap hMap = _elevationService.GetHeightMap(ref bbox, dataSet); hMap = hMap.ZScale(2); _logger.LogInformation($"Generating TIN with {precisionMeters}m precision..."); hMap = hMap.ReprojectTo(4326, outputSrid); var model = TINGeneration.GenerateTIN(hMap, (double)precisionMeters, _glTFService, null, outputSrid); _logger.LogInformation($"Generating model..."); string v_nomFichierOut = Path.Combine(Directory.GetCurrentDirectory(), $"{name}_TIN_{dataSet.Name}.glb"); model.SaveGLB(v_nomFichierOut); _logger.LogInformation($"Model {v_nomFichierOut} generated."); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } }
public void BoudingBoxConservationTest(string datasetName) { var dataset = DEMDataSet.RegisteredDatasets.First(d => d.Name == datasetName); string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; BoundingBox bbox = GeometryService.GetBoundingBox(bboxWKT); Assert.NotNull(bbox); Assert.Equal(bboxWKT, bbox.WKT); HeightMap heightMap = _elevationService.GetHeightMap(ref bbox, dataset); heightMap = heightMap.ReprojectGeodeticToCartesian().BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); heightMap = heightMap.ZScale(2.5f).BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); heightMap = heightMap.CenterOnOrigin().BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); heightMap = heightMap.FitInto(30f).BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); }
public void Run() { try { DEMDataSet dataset = DEMDataSet.SRTM_GL3; Stopwatch sw = Stopwatch.StartNew(); string modelName = $"Montagne Sainte Victoire {dataset.Name}"; // You can get your boox from https://geojson.net/ (save as WKT) string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; _logger.LogInformation($"Processing model {modelName}..."); _logger.LogInformation($"Getting bounding box geometry..."); var bbox = GeometryService.GetBoundingBox(bboxWKT); _logger.LogInformation($"Getting height map data..."); var heightMap = _elevationService.GetHeightMap(ref bbox, dataset); _logger.LogInformation($"Processing height map data ({heightMap.Count} coordinates)..."); heightMap = heightMap .ReprojectGeodeticToCartesian() // Reproject to 3857 (useful to get coordinates in meters) .ZScale(2f) // Elevation exageration .CenterOnOrigin() // .FitInto(250f); // Make sure model fits into 250 coordinates units (3D printer size was 30x30cm) // Triangule Irregular Network (not implemented to STL yet) //var TINmesh =TINGeneration.GenerateTIN(heightMap, 2, _glTFService, null, 3857); // Triangulate height map // and add base and sides _logger.LogInformation($"Triangulating height map and generating box (5mm thick)..."); // STL axis differ from glTF var model = _sharpGltfService.CreateTerrainMesh(heightMap, GenOptions.BoxedBaseElevationMin, Matrix4x4.CreateRotationX((float)Math.PI / 2f)); _logger.LogInformation($"Exporting STL model..."); var stlFilePath = Path.Combine(Directory.GetCurrentDirectory(), $"{modelName}.stl"); _stlService.STLExport(model.LogicalMeshes[0].Primitives[0], stlFilePath, false); _logger.LogInformation($"Model exported in {stlFilePath}."); _logger.LogInformation($"Done in {sw.Elapsed:g}"); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } }
public void OSMStreetsBuildings(string name, string bboxWKT, bool centerOnOrigin, float ZScale, bool computeElevations = false) { string outputDir = Directory.GetCurrentDirectory(); // SF Big: POLYGON((-122.53517427420718 37.81548554152065,-122.35149660086734 37.81548554152065,-122.35149660086734 37.70311455416941,-122.53517427420718 37.70311455416941,-122.53517427420718 37.81548554152065)) // SF Small: POLYGON((-122.41967382241174 37.81034598808797,-122.39761533547326 37.81034598808797,-122.39761533547326 37.79162804294824,-122.41967382241174 37.79162804294824,-122.41967382241174 37.81034598808797)) var bbox = GeometryService.GetBoundingBox(bboxWKT); var transform = new ModelGenerationTransform(bbox, Reprojection.SRID_PROJECTED_MERCATOR, centerOnOrigin, ZScale, centerOnZOrigin: true); var model = _osmProcessor.Run(null, OsmLayer.Highways | OsmLayer.Buildings, bbox, transform, computeElevations: computeElevations, dataSet: DEMDataSet.NASADEM, downloadMissingFiles: false, withBuildingsColors: true); model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), $"OSMStreetsBuildings_{name}.glb")); }
public void DownloadTile_BBox() { const string WKT_BBOX_AIX_PUYRICARD = "POLYGON ((5.429993 43.537854, 5.459132 43.537854, 5.459132 43.58151, 5.429993 43.58151, 5.429993 43.537854))"; DEMDataSet dataset = DEMDataSet.SRTM_GL3; BoundingBox bbox = GeometryService.GetBoundingBox(WKT_BBOX_AIX_PUYRICARD); _elevationService.DownloadMissingFiles(dataset, bbox); var report = _rasterService.GenerateReport(dataset, bbox); Assert.NotNull(report); Assert.True(report.Count > 0); Assert.True(report.First().IsExistingLocally); Assert.Equal("N43E005.hgt", Path.GetFileName(report.First().LocalName)); }
public void Run() { try { DEMDataSet dataset = DEMDataSet.AW3D30; ImageryProvider imageryProvider = ImageryProvider.MapBoxSatellite; Stopwatch sw = Stopwatch.StartNew(); string modelName = $"Montagne Sainte Victoire {dataset.Name}"; string outputDir = Directory.GetCurrentDirectory(); // You can get your boox from https://geojson.net/ (save as WKT) string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; _logger.LogInformation($"Processing model {modelName}..."); _logger.LogInformation($"Getting bounding box geometry..."); var bbox = GeometryService.GetBoundingBox(bboxWKT); _logger.LogInformation($"Getting height map data..."); var heightMap = _elevationService.GetHeightMap(ref bbox, dataset); _logger.LogInformation($"Processing height map data ({heightMap.Count} coordinates)..."); heightMap = heightMap .ReprojectGeodeticToCartesian() // Reproject to 3857 (useful to get coordinates in meters) .ZScale(2f) // Elevation exageration .CenterOnOrigin(); TileRange tiles = _imageryService.DownloadTiles(bbox, imageryProvider, 8); var texture = _imageryService.ConstructTexture(tiles, bbox, Path.Combine(outputDir, modelName + "_texture.jpg"), TextureImageFormat.image_jpeg); var normalMap = _imageryService.GenerateNormalMap(heightMap, outputDir, modelName + "_normalmap.png"); var pbrTexture = PBRTexture.Create(texture, normalMap); // Triangulate height map _logger.LogInformation($"Triangulating height map and generating 3D mesh..."); var model = _sharpGltfService.CreateTerrainMesh(heightMap, pbrTexture); model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), modelName + ".glb")); _logger.LogInformation($"Done in {sw.Elapsed:g}"); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } }
public void BoudingBoxEqualityTest() { string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; BoundingBox bbox = GeometryService.GetBoundingBox(bboxWKT); Assert.NotNull(bbox); Assert.Equal(bboxWKT, bbox.WKT); HeightMap heightMap = _elevationService.GetHeightMap(ref bbox, DEMDataSet.SRTM_GL1); Assert.False(object.ReferenceEquals(bbox, null)); Assert.NotNull(heightMap.Coordinates.GetBoundingBox()); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); Assert.False(heightMap.BoundingBox != heightMap.Coordinates.GetBoundingBox()); }
public void Test_GLB_Export_Bbox(bool exportAsBinary) { DEMDataSet dataset = DEMDataSet.SRTM_GL3; var modelName = $"SteVictoireLatLon"; // You can get your boox from https://geojson.net/ (save as WKT) string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; var bbox = GeometryService.GetBoundingBox(bboxWKT); var heightMap = _elevationService.GetHeightMap(bbox, dataset); // Triangulate height map var mesh = _gltfService.GenerateTriangleMesh(heightMap); var model = _gltfService.GenerateModel(mesh, modelName); // Export Binary model file _gltfService.Export(model, Directory.GetCurrentDirectory(), modelName, exportglTF: !exportAsBinary, exportGLB: exportAsBinary); }
public void Test_GLB_Export_Bbox(bool exportAsBinary) { DEMDataSet dataset = DEMDataSet.SRTM_GL3; var modelName = $"SteVictoireLatLon.glb"; // You can get your boox from https://geojson.net/ (save as WKT) string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; var bbox = GeometryService.GetBoundingBox(bboxWKT); var heightMap = _elevationService.GetHeightMap(ref bbox, dataset); // Triangulate height map var model = _sharpGltfService.CreateTerrainMesh(heightMap); // Export Binary model file model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), modelName)); Assert.True(File.Exists(Path.Combine(Directory.GetCurrentDirectory(), modelName))); }
public void DownloadTile_BBox(string datasetName) { var datasets = DEMDataSet.RegisteredDatasets; Assert.True(datasets.Any(), "No datasets found"); DEMDataSet dataset = datasets.FirstOrDefault(d => d.Name == datasetName); Assert.NotNull(dataset); const string WKT_BBOX_AIX_PUYRICARD = "POLYGON ((5.429993 43.537854, 5.459132 43.537854, 5.459132 43.58151, 5.429993 43.58151, 5.429993 43.537854))"; BoundingBox bbox = GeometryService.GetBoundingBox(WKT_BBOX_AIX_PUYRICARD); _elevationService.DownloadMissingFiles(dataset, bbox); var report = _rasterService.GenerateReport(dataset, bbox); Assert.NotNull(report); Assert.True(report.Count > 0); Assert.True(report.First().IsExistingLocally); }
public void Run() { // DjebelMarra var bbox = GeometryService.GetBoundingBox("POLYGON((7.713614662985839 46.03014517094771,7.990332802634277 46.03014517094771,7.990332802634277 45.86877753239648,7.713614662985839 45.86877753239648,7.713614662985839 46.03014517094771))"); var dataset = DEMDataSet.NASADEM; string modelName = $"{dataset.Name}_{DateTime.Now:yyyyMMdd_HHmmss}"; string outputDir = Directory.GetCurrentDirectory(); //var modelTest = _sharpGltfService.CreateNewModel(); //var triangulation = CreateText("20 km", VectorsExtensions.CreateColor(255, 255, 255)); //_sharpGltfService.AddMesh(modelTest, "Text", triangulation); //// Save model //modelTest.SaveGLB(Path.Combine(outputDir, modelName + ".glb")); var modelAndBbox = GenerateSampleModel(bbox, dataset, withTexture: true); if (modelAndBbox.Model != null) { var model = modelAndBbox.Model; // add adornments Stopwatch swAdornments = Stopwatch.StartNew(); TriangulationList <Vector3> adornments = _adornmentsService.CreateModelAdornments(dataset, ImageryProvider.MapBoxSatellite, bbox, modelAndBbox.projectedBbox); model = _sharpGltfService.AddMesh(model, "Adornments", adornments, default(Vector4), doubleSided: true); swAdornments.Stop(); _logger.LogInformation($"Adornments generation: {swAdornments.ElapsedMilliseconds:N1} ms"); // Save model model.SaveGLB(Path.Combine(outputDir, modelName + ".glb")); _logger.LogInformation($"Model exported as {Path.Combine(outputDir, modelName + ".glb")}"); } }
public List <BeanPoint_internal> GetPointsTestsByBBox(string p_bbox, DEMDataSet dataset, int sridCible) { List <BeanPoint_internal> v_pointsToTest = new List <BeanPoint_internal>(); try { IRasterService v_rasterService = new RasterService(null); IElevationService v_elevationService = new ElevationService(v_rasterService, null); BoundingBox v_bbox = GeometryService.GetBoundingBox(p_bbox); v_elevationService.DownloadMissingFiles(dataset, v_bbox); // HeightMap v_hMap; v_hMap = v_elevationService.GetHeightMap(ref v_bbox, dataset); v_hMap = v_hMap.ReprojectTo(4326, sridCible); v_pointsToTest = GetGeoPointsByHMap(v_hMap, sridCible); } catch (Exception) { throw; } return(v_pointsToTest); }
public void BoudingBoxConservationTest() { string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; BoundingBox bbox = GeometryService.GetBoundingBox(bboxWKT); Assert.NotNull(bbox); Assert.Equal(bboxWKT, bbox.WKT); HeightMap heightMap = _elevationService.GetHeightMap(bbox, DEMDataSet.SRTM_GL1); heightMap = heightMap.ReprojectGeodeticToCartesian().BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); heightMap = heightMap.ZScale(2.5f).BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); heightMap = heightMap.CenterOnOrigin().BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); heightMap = heightMap.FitInto(30f).BakeCoordinates(); Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox()); }
internal void Run(Microsoft.Extensions.DependencyInjection.ServiceProvider serviceProvider) { //======================= // Normal map Console.WriteLine("Height map..."); var bbox = GeometryService.GetBoundingBox(_bbox); HeightMap hMap = _elevationService.GetHeightMap(bbox, DEMDataSet.SRTM_GL3); var coords1 = hMap.Coordinates.ToList(); var coords2 = hMap.Coordinates.ToList(); Logger.RestartPerf("Projection with count"); for (int i = 0; i < 5; i++) { coords2.ReprojectTo(4326, Reprojection.SRID_PROJECTED_MERCATOR, coords2.Count).ToList(); } Logger.StopPerf("Projection with count"); Logger.RestartPerf("Projection without count"); for (int i = 0; i < 5; i++) { coords1.ReprojectTo(4326, Reprojection.SRID_PROJECTED_MERCATOR, null).ToList(); } Logger.StopPerf("Projection without count"); }
public List <BeanPoint_internal> GetPointsTestsByBBox(string p_bbox, DEMDataSet dataset, int sridCible) { List <BeanPoint_internal> v_pointsToTest = new List <BeanPoint_internal>(); try { // fix issue #86 to work with opentopography files without proper DI injection RasterIndexServiceResolver rasterIndexServiceResolver = dataSourceType => { switch (dataSourceType) { case DEMDataSourceType.GDALVrt: return(new GDALVRTFileService(null, null)); default: throw new KeyNotFoundException(); // or maybe return null, up to you } }; RasterService v_rasterService = new RasterService(rasterIndexServiceResolver); ElevationService v_elevationService = new ElevationService(v_rasterService, null); BoundingBox v_bbox = GeometryService.GetBoundingBox(p_bbox); v_elevationService.DownloadMissingFiles(dataset, v_bbox); // HeightMap v_hMap; v_hMap = v_elevationService.GetHeightMap(ref v_bbox, dataset); v_hMap = v_hMap.ReprojectTo(4326, sridCible); v_pointsToTest = GetGeoPointsByHMap(v_hMap, sridCible); } catch (Exception) { throw; } return(v_pointsToTest); }
public void Run(DEMDataSet dataset, bool withTexture = true) { try { //_rasterService.GenerateDirectoryMetadata(dataset, false); Stopwatch sw = Stopwatch.StartNew(); string modelName = $"Montagne Sainte Victoire {dataset.Name}"; string outputDir = Directory.GetCurrentDirectory(); ImageryProvider provider = ImageryProvider.MapBoxSatelliteStreet;// new TileDebugProvider(new GeoPoint(43.5,5.5)); // You can get your boox from https://geojson.net/ (save as WKT) string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))"; // string bboxWKT = // "POLYGON((5.594457381483949 43.545276557046044,5.652135604140199 43.545276557046044,5.652135604140199 43.52038635099936,5.594457381483949 43.52038635099936,5.594457381483949 43.545276557046044))"; // _logger.LogInformation($"Processing model {modelName}..."); // // // _logger.LogInformation($"Getting bounding box geometry..."); var bbox = GeometryService.GetBoundingBox(bboxWKT); //var bbox = new BoundingBox(5.5613898348431485,5.597185285307553,43.49372969433046,43.50939068558466); _logger.LogInformation($"Getting height map data..."); var heightMap = _elevationService.GetHeightMap(ref bbox, dataset); _logger.LogInformation($"Processing height map data ({heightMap.Count} coordinates)..."); heightMap = heightMap .ReprojectGeodeticToCartesian() // Reproject to 3857 (useful to get coordinates in meters) .ZScale(2f); // Elevation exageration //======================= // Textures // PBRTexture pbrTexture = null; if (withTexture) { Console.WriteLine("Download image tiles..."); TileRange tiles = _imageryService.DownloadTiles(bbox, provider, TEXTURE_TILES); string fileName = Path.Combine(outputDir, "Texture.jpg"); Console.WriteLine("Construct texture..."); TextureInfo texInfo = _imageryService.ConstructTexture(tiles, bbox, fileName, TextureImageFormat.image_jpeg); // //======================= //======================= // Normal map Console.WriteLine("Height map..."); //float Z_FACTOR = 0.00002f; //hMap = hMap.CenterOnOrigin().ZScale(Z_FACTOR); var normalMap = _imageryService.GenerateNormalMap(heightMap, outputDir); pbrTexture = PBRTexture.Create(texInfo, normalMap); //hMap = hMap.CenterOnOrigin(Z_FACTOR); // //======================= } // Triangulate height map // and add base and sides _logger.LogInformation($"Triangulating height map and generating 3D mesh..."); var model = _sharpGltfService.CreateTerrainMesh(heightMap, pbrTexture); model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), modelName + ".glb")); model = _sharpGltfService.CreateTerrainMesh(heightMap, GenOptions.Normals | GenOptions.BoxedBaseElevationMin); model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), modelName + "_normalsBox.glb")); _logger.LogInformation($"Model exported as {Path.Combine(Directory.GetCurrentDirectory(), modelName + ".gltf")} and .glb"); _logger.LogInformation($"Done in {sw.Elapsed:g}"); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } }
public void GenerateModel(string bboxWkt, DEMDataSet litto3DDataset, ImageryProvider imageryProvider, float zFactor = 3f, bool withTexture = true, bool withboat = true, bool withWaterSurface = true, DEMDataSet fallbackDataset = null) { try { bool centerOnOrigin = true; int TEXTURE_TILES = 20; string outputDir = Directory.GetCurrentDirectory(); string modelName = $"{litto3DDataset.ResolutionMeters}m_z{zFactor}_{imageryProvider.Name}-{DateTime.Now:yyyyMMdd-hhmmss}"; _logger.LogInformation($"Getting height map data..."); var bbox = GeometryService.GetBoundingBox(bboxWkt).ReprojectTo(4326, litto3DDataset.SRID); var heightMap = _elevationService.GetHeightMap(ref bbox, litto3DDataset); heightMap = heightMap.BakeCoordinates(); var nullCoordsEnumerator = heightMap.Coordinates.Where(c => (c.Elevation ?? litto3DDataset.NoDataValue) == litto3DDataset.NoDataValue); var interpolator = _elevationService.GetInterpolator(InterpolationMode.Bilinear); using (IRasterFile raster = _rasterService.OpenFile(@"D:\Data\ELEVATION_DO_NOT_DELETE\GEBCO2020\cote azur\gebco_2020_subset.tif", DEMFileType.GEOTIFF)) using (RasterFileDictionary dic = new RasterFileDictionary()) { var metadata = raster.ParseMetaData(fallbackDataset.FileFormat); dic.Add(metadata, raster); foreach (var pt in nullCoordsEnumerator) { var proj = pt.ReprojectTo(litto3DDataset.SRID, fallbackDataset.SRID); pt.Elevation = _elevationService.GetElevationAtPoint(raster, dic, metadata, proj.Latitude, proj.Longitude, 0, interpolator, NoDataBehavior.UseNoDataDefinedInDem); } } var nullCoords = heightMap.Coordinates.Where(c => (c.Elevation ?? litto3DDataset.NoDataValue) == litto3DDataset.NoDataValue).ToList(); var nullCoordsFallbackProj = nullCoords.ReprojectTo(litto3DDataset.SRID, fallbackDataset.SRID, nullCoords.Count); var nullCoordsFallbackProj2 = _elevationService.GetPointsElevation(nullCoordsFallbackProj, fallbackDataset, InterpolationMode.Bilinear, NoDataBehavior.UseNoDataDefinedInDem); ModelGenerationTransform transform = new ModelGenerationTransform(bbox, 3857, centerOnOrigin: centerOnOrigin, zFactor, centerOnZOrigin: false); ModelGenerationTransform transformFrom4326 = new ModelGenerationTransform(bbox.ReprojectTo(2154, 4326), 3857, centerOnOrigin: centerOnOrigin, zFactor, centerOnZOrigin: false); _logger.LogInformation($"Processing height map data ({heightMap.Count} coordinates)..."); heightMap = transform.TransformHeightMap(heightMap); var min = heightMap.Coordinates.Where(g => (g.Elevation ?? 0d) > litto3DDataset.NoDataValue).Min(g => g.Elevation ?? 0d); heightMap.Coordinates = heightMap.Coordinates.Select(p => { if (p.Elevation.GetValueOrDefault(0) <= litto3DDataset.NoDataValue) { p.Elevation = min; } return(p); }); //======================= // Textures // PBRTexture pbrTexture = null; if (withTexture) { var bbox4326 = bbox.ReprojectTo(2154, 4326); Console.WriteLine("Download image tiles..."); TileRange tiles = _imageryService.DownloadTiles(bbox4326, imageryProvider, TEXTURE_TILES); string fileName = Path.Combine(outputDir, "Texture.jpg"); Console.WriteLine("Construct texture..."); //TextureInfo texInfo = _imageryService.ConstructTexture(tiles, bbox4326, fileName, TextureImageFormat.image_jpeg); TextureInfo texInfo; if (withboat) { var trackPoints = GetGeoPointFromGeoJson(BoatCourseGeoJson); texInfo = _imageryService.ConstructTextureWithGpxTrack(tiles, bbox4326, fileName, TextureImageFormat.image_jpeg, trackPoints, drawGpxVertices: true, color: SixLabors.ImageSharp.PixelFormats.Rgba32.Green, 30); } else { texInfo = _imageryService.ConstructTexture(tiles, bbox4326, fileName, TextureImageFormat.image_jpeg); } // //======================= //======================= // Normal map Console.WriteLine("Height map..."); //float Z_FACTOR = 0.00002f; //hMap = hMap.CenterOnOrigin().ZScale(Z_FACTOR); //var normalMap = _imageryService.GenerateNormalMap(heightMap, outputDir); pbrTexture = PBRTexture.Create(texInfo, null);// normalMap); //hMap = hMap.CenterOnOrigin(Z_FACTOR); // //======================= } // Triangulate height map // and add base and sides _logger.LogInformation($"Triangulating height map and generating 3D mesh..."); heightMap = heightMap.BakeCoordinates(); var coords = heightMap.Coordinates.ToList(); var model = _sharpGltfService.CreateTerrainMesh(heightMap, pbrTexture); if (withWaterSurface) { var bottomLeft = coords[heightMap.Width * (heightMap.Height - 1)].AsVector3(); bottomLeft.Z = 0; var topRight = coords[heightMap.Width - 1].AsVector3(); topRight.Z = 0; var topLeft = coords[0].AsVector3(); topLeft.Z = 0; var bottomRight = coords.Last().AsVector3(); bottomRight.Z = 0; var waterSurface = _meshService.CreateWaterSurface(bottomLeft, topRight, topLeft, bottomRight, minZ: (float)min, color: VectorsExtensions.CreateColor(0, 150, 255, 64)); model = _sharpGltfService.AddMesh(model, "Water", waterSurface, doubleSided: true); } if (withboat) { var boatInitPos = centerOnOrigin ? new GeoPoint(0, 0).AsVector3() : new GeoPoint(43.010625204304304, 6.3711613671060086).ReprojectTo(4326, 3857).AsVector3(); var axis = _meshService.CreateAxis(2, 10, 3, 3).Translate(boatInitPos); model = _sharpGltfService.AddMesh(model, "Boat", axis, doubleSided: false); var boatCourse = transformFrom4326.TransformPoints(GetGeoPointFromGeoJson(BoatCourseGeoJson)).ToList(); //ReprojectGeodeticToCartesian().CenterOnOrigin().ToList(); model = _sharpGltfService.AddLine(model, "BoatCourse", boatCourse, VectorsExtensions.CreateColor(255, 0, 0, 128), 4); } model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), modelName + ".glb")); _logger.LogInformation($"Model exported as {Path.Combine(Directory.GetCurrentDirectory(), modelName + ".gltf")} and .glb"); //var point = new GeoPoint(43.01142119356318, 6.385200681010872).ReprojectTo(4326, 2154); //point = _elevationService.GetPointElevation(point, litto3DDataset); } catch (Exception e) { _logger.LogError(e, e.Message); } }
private void Buildings3DOnly() { string outputDir = Directory.GetCurrentDirectory(); string WKT_SF_BIG = "POLYGON((-122.53517427420718 37.81548554152065,-122.35149660086734 37.81548554152065,-122.35149660086734 37.70311455416941,-122.53517427420718 37.70311455416941,-122.53517427420718 37.81548554152065))"; string WKT_SF_SMALL = "POLYGON((-122.42722692299768 37.81034598808797, -122.38886060524865 37.81034598808797, -122.38886060524865 37.784573673820816, -122.42722692299768 37.784573673820816, -122.42722692299768 37.81034598808797))"; string WKT_SF_SUPERSMALL = "POLYGON((-122.41063177228989 37.80707295150412,-122.40904390455307 37.80707295150412,-122.40904390455307 37.806064225434206,-122.41063177228989 37.806064225434206,-122.41063177228989 37.80707295150412))"; // FULL string WKT_PRIPYAT_FULL = "POLYGON((30.021919548702254 51.41813804241615,30.083030998897566 51.41813804241615,30.083030998897566 51.389438684773985,30.021919548702254 51.389438684773985,30.021919548702254 51.41813804241615))"; // Cas 1 //string WKT_PRIPYAT = "POLYGON((30.05430313958436 51.404795567637294,30.055118531124887 51.404795567637294,30.055118531124887 51.40432372279637,30.05430313958436 51.40432372279637,30.05430313958436 51.404795567637294))"; // cas 2 //string WKT_PRIPYAT = "POLYGON((30.062877280833636 51.40748141189236,30.063456637980853 51.40748141189236,30.063456637980853 51.40716017522757,30.062877280833636 51.40716017522757,30.062877280833636 51.40748141189236))"; // cas 3 //string WKT_PRIPYAT = "POLYGON((30.065251398582948 51.407283441091266,30.066243815918458 51.407283441091266,30.066243815918458 51.40558353075506,30.065251398582948 51.40558353075506,30.065251398582948 51.407283441091266))"; string WKT_PRIPRYAT_SOMEROADS = "POLYGON((30.062684362726948 51.40792711901257,30.064690655070088 51.40792711901257,30.064690655070088 51.40693664170241,30.062684362726948 51.40693664170241,30.062684362726948 51.40792711901257))"; // SF Big: POLYGON((-122.53517427420718 37.81548554152065,-122.35149660086734 37.81548554152065,-122.35149660086734 37.70311455416941,-122.53517427420718 37.70311455416941,-122.53517427420718 37.81548554152065)) // SF Small: POLYGON((-122.41967382241174 37.81034598808797,-122.39761533547326 37.81034598808797,-122.39761533547326 37.79162804294824,-122.41967382241174 37.79162804294824,-122.41967382241174 37.81034598808797)) // Napoli, multi polygon (https://www.openstreetmap.org/relation/8955771) //new BoundingBox(14.364430059744153, 14.365218629194532, 40.78433307340424, 40.785023575175295); string WKT_AIX_FULL = "POLYGON((5.402291662243135 43.565714431347274,5.48056925013376 43.565714431347274,5.48056925013376 43.50797300081391,5.402291662243135 43.50797300081391,5.402291662243135 43.565714431347274))"; string WKT_AIX_WITHTERRAIN = "POLYGON((5.440657648511835 43.55957815383877,5.444434198804804 43.55957815383877,5.444434198804804 43.5579454365131,5.440657648511835 43.5579454365131,5.440657648511835 43.55957815383877))"; string WKT_AIX_SMALLOSMBUG = "POLYGON((5.441805234256467 43.55910060792738,5.442684998813352 43.55910060792738,5.442684998813352 43.55877017799191,5.441805234256467 43.55877017799191,5.441805234256467 43.55910060792738))"; string WKT_MONACO = "POLYGON((7.392147587957001 43.75577569838535,7.4410710803886415 43.75577569838535,7.4410710803886415 43.71757458493263,7.392147587957001 43.71757458493263,7.392147587957001 43.75577569838535))"; string WKT_MONACO_DEBUG = "POLYGON((7.421709439122424 43.73663530909531,7.433961769902453 43.73663530909531,7.433961769902453 43.733007331111345,7.421709439122424 43.733007331111345,7.421709439122424 43.73663530909531))";//"POLYGON((7.426780270757294 43.73870913810349,7.432520198049164 43.73870913810349,7.432520198049164 43.73501926928533,7.426780270757294 43.73501926928533,7.426780270757294 43.73870913810349))"; string WKT_HK = "POLYGON((114.13119740014092 22.360520982593926,114.21050495629326 22.360520982593926,114.21050495629326 22.28874575980822,114.13119740014092 22.28874575980822,114.13119740014092 22.360520982593926))"; string WKT_FRISCO = "POLYGON((-122.5235839391063 37.81433638393927,-122.36222224477036 37.81433638393927,-122.36222224477036 37.71228516909579,-122.5235839391063 37.71228516909579,-122.5235839391063 37.81433638393927))"; string WKT_DEFENSE = "POLYGON((2.222075572216413 48.902615468120246,2.3024130966304757 48.902615468120246,2.3024130966304757 48.86355756505397,2.222075572216413 48.86355756505397,2.222075572216413 48.902615468120246))"; DEMDataSet dataset = DEMDataSet.NASADEM; var name = nameof(WKT_DEFENSE); var bbox = GeometryService.GetBoundingBox(WKT_DEFENSE); bool computeElevations = true; ModelRoot model = _gltfService.CreateNewModel(); bool withTerrain = false; if (withTerrain) { var heightMap = _elevationService.GetHeightMap(ref bbox, dataset); var transform = new ModelGenerationTransform(bbox, Reprojection.SRID_PROJECTED_MERCATOR, centerOnOrigin: true, ZScale, centerOnZOrigin: true); heightMap = transform.TransformHeightMap(heightMap); TileRange tiles = _imageryService.DownloadTiles(bbox, ImageryProvider.MapBoxSatellite, 15); string fileName = Path.Combine(outputDir, "Texture.jpg"); TextureInfo texInfo = _imageryService.ConstructTexture(tiles, bbox, fileName, TextureImageFormat.image_jpeg); var pbrTexture = PBRTexture.Create(texInfo, null); model = _osmProcessor.Run(model, OsmLayer.Buildings | OsmLayer.Highways, bbox, transform, computeElevations, dataset, downloadMissingFiles: true); model = _gltfService.AddTerrainMesh(model, heightMap, pbrTexture); } else { var transform = new ModelGenerationTransform(bbox, Reprojection.SRID_PROJECTED_MERCATOR, centerOnOrigin: true, ZScale, centerOnZOrigin: true); model = _osmProcessor.Run(model, OsmLayer.Buildings | OsmLayer.Highways, bbox, transform, computeElevations, dataset, downloadMissingFiles: true); } model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), name + ".glb")); }
internal void Run(ServiceProvider serviceProvider) { bool useTIN = false; // still buggy with SRID 3857 int v_outSrid = Reprojection.SRID_PROJECTED_MERCATOR; IglTFService glTF = serviceProvider.GetService <IglTFService>(); IElevationService elevationService = serviceProvider.GetService <IElevationService>(); string outputDir = Path.GetFullPath(Path.Combine(_outputDirectory, "glTF")); Logger.Info("============================"); Logger.Info($"= {nameof(TextureSamples)}"); Logger.Info("============================"); Logger.Info($"= {nameof(TextureSamples)} : Datadirectory report"); // Get GPX points var bbox = GeometryService.GetBoundingBox(_bboxWkt); //======================= // Textures // TextureInfo texInfo = null; ImageryService imageryService = new ImageryService(); Console.WriteLine("Download image tiles..."); TileRange tiles = imageryService.DownloadTiles(bbox, ImageryProvider.StamenToner, 1); Console.WriteLine("Construct texture..."); string fileName = Path.Combine(outputDir, "Texture.jpg"); texInfo = imageryService.ConstructTexture(tiles, bbox, fileName, TextureImageFormat.image_jpeg); // //======================= //======================= // Normal map Console.WriteLine("Height map..."); float Z_FACTOR = 2f; HeightMap hMapNormal = elevationService.GetHeightMap(bbox, _normalsDataSet); //HeightMap hMapNormal = _elevationService.GetHeightMap(bbox, Path.Combine(_localdatadir, "ETOPO1", "ETOPO1_Bed_g_geotiff.tif"), DEMFileFormat.GEOTIFF); hMapNormal = hMapNormal.ReprojectTo(4326, v_outSrid); //hMapNormal = hMapNormal.ReprojectGeodeticToCartesian(); Console.WriteLine("Generate normal map..."); TextureInfo normal = imageryService.GenerateNormalMap(hMapNormal, outputDir); // //======================= //======================= // Get height map HeightMap hMap = elevationService.GetHeightMap(bbox, _meshDataSet); //HeightMap hMap = _elevationService.GetHeightMap(bbox, Path.Combine(_localdatadir, "ETOPO1","ETOPO1_Bed_g_geotiff.tif"), DEMFileFormat.GEOTIFF); //======================= // UV mapping (before projection) PBRTexture pBRTexture = PBRTexture.Create(texInfo, normal, imageryService.ComputeUVMap(hMap, texInfo)); hMap = hMap.ReprojectTo(4326, v_outSrid); hMap = hMap.CenterOnOrigin().ZScale(Z_FACTOR); //======================= //======================= // MESH 3D terrain List <MeshPrimitive> meshes = new List <MeshPrimitive>(); // generate mesh with texture MeshPrimitive triangleMesh; if (useTIN) { Console.WriteLine("Create TIN..."); //triangleMesh = GenerateTIN(hMapTIN, glTF, pBRTexture); triangleMesh = TINGeneration.GenerateTIN(hMap, 10d, glTF, pBRTexture, v_outSrid); } else { Console.WriteLine("GenerateTriangleMesh..."); triangleMesh = glTF.GenerateTriangleMesh_Boxed(hMap); } meshes.Add(triangleMesh); // model export Console.WriteLine("GenerateModel..."); Model model = glTF.GenerateModel(meshes, this.GetType().Name); glTF.Export(model, outputDir, $"{GetType().Name} NONormal", false, true); }