private void button4_Click(object sender, EventArgs e) { int lon = Convert.ToInt32(txtX6.Text); int lat = Convert.ToInt32(txtY6.Text); int zoom = Convert.ToInt32(txtZ6.Text); // crap var t = CesiumMerc.TileXYToNativeRectangle(lon, lat, zoom); // listBox1.Items.Add($" CesiumMerc (WS ,EN ({t.West} , {t.South}) - ({t.East} , {t.North})"); // var long1 = MapUtil.tile2long(lon, zoom); // var lat1 = MapUtil.tile2lat(lat, zoom); // listBox1.Items.Add($" Please Lat lon {lat1} , {long1})"); var bb2 = Geographic.TileXYToRectangleLL(lon, lat, zoom); listBox1.Items.Add($"Geographic.TileXYToRectangleLL WS ,EN ({bb2.West} , {bb2.South}) - ({bb2.East} , {bb2.North})"); var bb = MapGeo.TileXYZToRectLL(lon, lat, zoom); listBox1.Items.Add($"MapGeo.TileXYZToRectLL WS ,EN ({bb.West} , {bb.South}) - ({bb.East} , {bb.North})"); listBox1.Items.Add(""); // Now convert to ECEF coords var res2 = Coord.geo_to_ecef(new Vector3(MapUtil.Deg2Rad(bb.West), MapUtil.Deg2Rad(bb.South), 10)); listBox1.Items.Add($"WS to Meters EcEf XYZ:{res2.X} , {res2.Y} , {res2.Z}"); var res3 = Coord.geo_to_ecef(new Vector3(MapUtil.Deg2Rad(bb.East), MapUtil.Deg2Rad(bb.North), 10)); listBox1.Items.Add($"EN to Meters EcEf XYZ:{res3.X} , {res3.Y} , {res3.Z}"); var x = res2.X + FindDifference(res3.X, res2.X) / 2; var y = res2.Y + FindDifference(res3.Y, res2.Y) / 2; listBox1.Items.Add($"Center XY:{x} , {y}"); }
public void MapGeo_NumberOfTiles() { var tiles1 = MapGeo.GetNumberOfXTilesAtLevel(1); tiles1.Should().Be(4); var tiles2 = MapGeo.GetNumberOfYTilesAtLevel(1); tiles2.Should().Be(2); }
public async override Task <ElevationData> GetDemXYZ(int x, int y, int z) { lock (_object) // thread safe lookup contention. { // Get the lat lon boundary from xyz tile var rect = MapGeo.TileXYZToRectLL(x, y, z); // Make the DEM that will be used to make a quantized mesh return(MakeTileDEM(rect)); } }
public void TileBuilder_BuildTile() { LLBoundingBox TileBoundaryLL = MapGeo.TileXYZToRectLL(0, 0, 20, out var yFlip); ElevationData elevData = new ElevationData(0, 5); elevData.MakeEmptyTile(TileBoundaryLL, false); QMTileBuilder tileBuilder = new QMTileBuilder() { TileData = elevData, GridSize = elevData.GridSize }; var res = tileBuilder.BuildQuantizedMeshTile(); res.Should().Be(true); tileBuilder.QuantizedMeshTile.Should().HaveCountGreaterOrEqualTo(162); tileBuilder.QuantizedMeshTile.Should().HaveCountLessOrEqualTo(164); }
/// <summary> /// Executor that implements requesting and rendering grid information to create the grid rows /// </summary> /// <returns></returns> public async Task <bool> ExecuteAsync() { // Get the lat lon boundary from xyz tile request TileBoundaryLL = MapGeo.TileXYZToRectLL(TileX, TileY, TileZ, out var yFlip); _log.LogInformation($"#Tile#.({TileX},{TileY}) Execute Start. DMode:{DisplayMode}, HasLighting:{HasLighting}, Zoom:{TileZ} FlipY:{yFlip}. TileBoundary:{TileBoundaryLL.ToDisplay()}, DataModel:{DataModelUid}"); if (TileZ == 0) // Send back default root tile { MakeRootTile(); return(true); } SiteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DataModelUid); if (SiteModel == null) { ResultStatus = RequestErrorStatus.NoSuchDataModel; _log.LogError($"Tile.({TileX},{TileY}) Failed to obtain site model for {DataModelUid}"); return(false); } var siteModelExtentWithSurveyedSurfaces = SiteModel.GetAdjustedDataModelSpatialExtents(null); _log.LogDebug($"Tile.({TileX},{TileY}) Site model extents are {siteModelExtentWithSurveyedSurfaces}. TileBoundary:{TileBoundaryLL.ToDisplay()}"); if (!siteModelExtentWithSurveyedSurfaces.IsValidPlanExtent) // No data return empty tile { return(BuildEmptyTile()); } // We will draw all missing data just below lowest elevation for site LowestElevation = (float)siteModelExtentWithSurveyedSurfaces.MinZ - 1F; Initialise(); // setup tile requirements if (TileGridSize == QMConstants.FlatResolutionGridSize) // Too far out to see detail so return empty tile { return(BuildEmptyTile()); } if (DisplayMode == QMConstants.DisplayModeDemo) // development use only { return(BuildDemoTile()); } try { var setupResult = await SetupPipelineTask(siteModelExtentWithSurveyedSurfaces, SiteModel.CellSize); if (!setupResult) { if (ResultStatus != RequestErrorStatus.InvalidCoordinateRange) { _log.LogError($"Tile.({TileX},{TileY}) Unable to setup pipelinetask."); } return(BuildEmptyTile()); } processor.Process(); if (GriddedElevationsResponse.ResultStatus != RequestErrorStatus.OK) { _log.LogError($"Tile.({TileX},{TileY}) Unable to obtain data for gridded data. GriddedElevationRequestResponse: {GriddedElevationsResponse.ResultStatus.ToString()}"); return(BuildEmptyTile()); } ElevData.HasData = !float.IsPositiveInfinity(task.MinElevation); // check for data // Developer Debugging Only if (ElevData.HasData) { OutputDebugTile("Raw"); } if (!ElevData.HasData) { return(BuildEmptyTile()); } _log.LogInformation($"#Tile#.({TileX},{TileY}) Data successfully sampled. GridSize:{TileGridSize} Min:{task.MinElevation}, Max:{task.MaxElevation} FirstElev:{GriddedElevDataArray[0, 0].Elevation}, LastElev:{GriddedElevDataArray[TileGridSize - 1, TileGridSize - 1].Elevation}"); ElevData.HasLighting = HasLighting; // Transform gridded data into a format the mesh builder can use ConvertGridToDEM(task.MinElevation, task.MaxElevation); // Build a quantized mesh from sampled elevations QMTileBuilder tileBuilder = new QMTileBuilder() { TileData = ElevData, GridSize = TileGridSize }; _log.LogInformation($"Tile.({TileX},{TileY}) BuildQuantizedMeshTile. GridSize:{TileGridSize} Min:{ElevData.MinimumHeight}, Max:{ElevData.MaximumHeight}"); if (!tileBuilder.BuildQuantizedMeshTile()) { _log.LogError($"Tile.({TileX},{TileY}) BuildQuantizedMeshTile returned false with error code: {tileBuilder.BuildTileFaultCode}"); return(false); } QMTileResponse.data = tileBuilder.QuantizedMeshTile; // Make tile from mesh ResultStatus = RequestErrorStatus.OK; QMTileResponse.ResultStatus = ResultStatus; _log.LogDebug($"#Tile#.({TileX},{TileY}) Execute End. Returning production tile. CesiumY:{yFlip}, Zoom:{TileZ}, GridSize:{TileGridSize}"); return(true); } catch (Exception ex) { _log.LogError(ex, $"#Tile#.({TileX},{TileY}). Exception building QuantizedMesh tile: "); return(false); } }