bool vtElevLayer::TransformCoords(vtProjection &proj_new) { VTLOG("vtElevLayer::TransformCoords\n"); vtProjection proj_old; GetProjection(proj_old); if (proj_old == proj_new) return true; // No conversion necessary bool success = false; if (m_pGrid) { // Check to see if the projections differ *only* by datum vtProjection test = proj_old; test.SetDatum(proj_new.GetDatum()); if (test == proj_new) { success = m_pGrid->ReprojectExtents(proj_new); } else { bool bUpgradeToFloat = false; if (!m_pGrid->IsFloatMode()) { if (g_Options.GetValueBool(TAG_REPRO_TO_FLOAT_NEVER)) bUpgradeToFloat = false; else if (g_Options.GetValueBool(TAG_REPRO_TO_FLOAT_ALWAYS)) bUpgradeToFloat = true; else if (!IsGUIApp()) { // Be sure not to ask, if this is not a GUI app bUpgradeToFloat = false; } else { // Ask int res = wxMessageBox(_("Input grid is integer. Use floating-point values in reprojected grid?"), _("query"), wxYES_NO); if (res == wxYES) bUpgradeToFloat = true; } } // actually re-project the grid elements vtElevationGrid *grid_new = new vtElevationGrid; vtElevError err; success = grid_new->ConvertProjection(m_pGrid, proj_new, bUpgradeToFloat, progress_callback, &err); if (success) { delete m_pGrid; m_pGrid = grid_new; ReImage(); } else { wxString msg((const char *) err.message, wxConvUTF8); wxMessageBox(msg, _("Error")); delete grid_new; } } } if (m_pTin) { success = m_pTin->ConvertProjection(proj_new); } SetModified(true); return success; }
bool WriteTilesetHeader(const char *filename, int cols, int rows, int lod0size, const DRECT &area, const vtProjection &proj, float minheight, float maxheight, LODMap *lodmap, bool bJPEG) { FILE *fp = vtFileOpen(filename, "wb"); if (!fp) return false; fprintf(fp, "[TilesetDescription]\n"); fprintf(fp, "Columns=%d\n", cols); fprintf(fp, "Rows=%d\n", rows); fprintf(fp, "LOD0_Size=%d\n", lod0size); fprintf(fp, "Extent_Left=%.16lg\n", area.left); fprintf(fp, "Extent_Right=%.16lg\n", area.right); fprintf(fp, "Extent_Bottom=%.16lg\n", area.bottom); fprintf(fp, "Extent_Top=%.16lg\n", area.top); // write CRS, but pretty it up a bit OGRSpatialReference *poSimpleClone = proj.Clone(); poSimpleClone->GetRoot()->StripNodes( "AXIS" ); poSimpleClone->GetRoot()->StripNodes( "AUTHORITY" ); char *wkt; poSimpleClone->exportToWkt(&wkt); fprintf(fp, "CRS=%s\n", wkt); OGRFree(wkt); // Free CRS delete poSimpleClone; // For elevation tilesets, also write vertical extents if (minheight != INVALID_ELEVATION) { fprintf(fp, "Elevation_Min=%.f\n", minheight); fprintf(fp, "Elevation_Max=%.f\n", maxheight); } if (lodmap != NULL) { int mmin, mmax; for (int i = 0; i < rows; i++) { fprintf(fp, "RowLODs %2d:", i); for (int j = 0; j < cols; j++) { lodmap->get(j, i, mmin, mmax); fprintf(fp, " %d/%d", mmin, mmax); } fprintf(fp, "\n"); } } // create a transformation that will map from the current projection to Lat/Lon WGS84 vtProjection proj_llwgs84; proj_llwgs84.SetWellKnownGeogCS("WGS84"); OCT *LLWGS84transform=CreateCoordTransform(&proj,&proj_llwgs84); // write center point of the tileset in Lat/Lon WGS84 // this is helpful for libMini to compute an approximate translation double cx=(area.left+area.right)/2; double cy=(area.bottom+area.top)/2; if (LLWGS84transform->Transform(1,&cx,&cy)==1) fprintf(fp, "CenterPoint_LLWGS84=(%.16lg,%.16lg)\n",cx,cy); // write north point of the tileset in Lat/Lon WGS84 // this is helpful for libMini to compute an approximate rotation double nx=(area.left+area.right)/2; double ny=area.top; if (LLWGS84transform->Transform(1,&nx,&ny)==1) fprintf(fp, "NorthPoint_LLWGS84=(%.16lg,%.16lg)\n",nx,ny); // delete Lat/Lon WGS84 transformation delete LLWGS84transform; // write CRS info // this is helpful for libMini to easily identify the coordinate reference system // supported CRS are: Geographic, UTM, Mercator const int crs=mapCRS2MINI(proj); const int datum=mapEPSG2MINI(proj.GetDatum()); const int utmzone=proj.GetUTMZone(); fprintf(fp, "CoordSys=(%d,%d,%d)\n",crs,datum,utmzone); if (bJPEG) fprintf(fp, "Format=JPEG\n"); else fprintf(fp, "Format=DB\n"); fclose(fp); return true; }