From 824d734eb44488643af11f3adddc779c4bab86c2 Mon Sep 17 00:00:00 2001 From: Ralf Gerlich Date: Sun, 20 Dec 2009 12:11:08 +0100 Subject: [PATCH] Load USGS-to-TerraGear translation from external file (closes #10) --- src/BuildTiles/Clipper/priorities.cxx | 6 +-- src/BuildTiles/Main/Makefile.am | 5 +- src/BuildTiles/Main/main.cxx | 71 ++++----------------------- src/BuildTiles/Main/usgs.cxx | 67 +++++++++++++++++++++++++ src/BuildTiles/Main/usgs.hxx | 35 +++++++++++++ src/BuildTiles/Main/usgsmap.txt | 51 +++++++++++++++++++ 6 files changed, 169 insertions(+), 66 deletions(-) create mode 100644 src/BuildTiles/Main/usgs.cxx create mode 100644 src/BuildTiles/Main/usgs.hxx create mode 100644 src/BuildTiles/Main/usgsmap.txt diff --git a/src/BuildTiles/Clipper/priorities.cxx b/src/BuildTiles/Clipper/priorities.cxx index 8666169a..445c3943 100644 --- a/src/BuildTiles/Clipper/priorities.cxx +++ b/src/BuildTiles/Clipper/priorities.cxx @@ -1,8 +1,8 @@ // priorities.cxx -- manage area type priorities // -// Written by Curtis Olson, started February 1999. +// Written by Ralf Gerlich // -// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt +// Copyright (C) 2008 Ralf Gerlich - ralf.gerlich custom-scenery org // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,8 +17,6 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// $Id: names.cxx,v 1.13 2004-11-19 22:25:50 curt Exp $ #include #include diff --git a/src/BuildTiles/Main/Makefile.am b/src/BuildTiles/Main/Makefile.am index aaebf756..24c7ba1a 100644 --- a/src/BuildTiles/Main/Makefile.am +++ b/src/BuildTiles/Main/Makefile.am @@ -2,7 +2,9 @@ bin_PROGRAMS = fgfs-construct fgfs-master fgfs_construct_SOURCES = \ construct.cxx construct.hxx \ - main.cxx + usgs.cxx main.cxx + +dist_pkgdata_DATA = usgsmap.txt fgfs_construct_LDADD = \ $(top_builddir)/src/BuildTiles/Clipper/libClipper.a \ @@ -24,6 +26,7 @@ fgfs_construct_LDADD = \ fgfs_master_SOURCES = master.cxx fgfs_master_LDADD = -lsgbucket -lsgmisc -lsgdebug -lsgxml +AM_CPPFLAGS = -DDEFAULT_USGS_MAPFILE="\"$(pkgdatadir)/usgsmap.txt\"" INCLUDES = \ -I$(top_srcdir)/src \ diff --git a/src/BuildTiles/Main/main.cxx b/src/BuildTiles/Main/main.cxx index 880ffef8..adb772d9 100644 --- a/src/BuildTiles/Main/main.cxx +++ b/src/BuildTiles/Main/main.cxx @@ -55,6 +55,7 @@ #include #include "construct.hxx" +#include "usgs.hxx" using std::cout; using std::cerr; @@ -79,67 +80,6 @@ static const double half_cover_size = cover_size * 0.5; static const double quarter_cover_size = cover_size * 0.25; double nudge=0.0; - - -// Translate USGS land cover values into TerraGear area types. -static AreaType translateUSGSCover (int usgs_value) -{ - switch (usgs_value) { - - case 1: // Urban and Built-Up Land - return BuiltUpCover; - case 2: // Dryland Cropland and Pasture - return DryCropPastureCover; - case 3: // Irrigated Cropland and Pasture - return IrrCropPastureCover; - case 4: // Mixed Dryland/Irrigated Cropland and Pasture - return MixedCropPastureCover; - case 5: // Cropland/Grassland Mosaic - return CropGrassCover; - case 6: // Cropland/Woodland Mosaic - return CropWoodCover; - case 7: // Grassland - return GrassCover; - case 8: // Shrubland - return ShrubCover; - case 9: // Mixed Shrubland/Grassland - return ShrubGrassCover; - case 10: // Savanna - return SavannaCover; - case 11: // Deciduous Broadleaf Forest - return DeciduousBroadCover; - case 12: // Deciduous Needleleaf Forest - return DeciduousNeedleCover; - case 13: // Evergreen Broadleaf Forest - return EvergreenBroadCover; - case 14: // Evergreen Needleleaf Forest - return EvergreenNeedleCover; - case 15: // Mixed Forest - return MixedForestCover; - case 16: // Water Bodies - // FIXME: use the type of an adjoining area if possible - // return WaterBodyCover; - return DefaultArea; - case 17: // Herbaceous Wetland - return HerbWetlandCover; - case 18: // Wooded Wetland - return WoodedWetlandCover; - case 19: // Barren or Sparsely Vegetated - return BarrenCover; - case 20: // Herbaceous Tundra - return HerbTundraCover; - case 21: // Wooded Tundra - return WoodedTundraCover; - case 22: // Mixed Tundra - return MixedTundraCover; - case 23: // Bare Ground Tundra - return BareTundraCover; - case 24: // Snow or Ice - return SnowCover; - default: // Unknown - return DefaultArea; - } -} // Scan a directory and load polygon files. @@ -1103,6 +1043,7 @@ static void usage( const string name ) { cout << " --xdist=" << endl; cout << " --ydist=" << endl; cout << " --nudge=" << endl; + cout << " --usgs-map=" << endl; cout << " --useUKgrid" << endl; cout << " --no-write-shared-edges" << endl; cout << " --use-own-shared-edges" << endl; @@ -1115,6 +1056,7 @@ int main(int argc, char **argv) { string output_dir = "."; string work_dir = "."; string cover = ""; + string usgs_map_file = DEFAULT_USGS_MAPFILE; double lon = -110.664244; // P13 double lat = 33.352890; double xdist = -1; // 1/2 degree in each direction @@ -1160,6 +1102,8 @@ int main(int argc, char **argv) { nudge = atof(arg.substr(8).c_str())*SG_EPSILON; } else if (arg.find("--cover=") == 0) { cover = arg.substr(8); + } else if (arg.find("--usgs-map=") == 0) { + usgs_map_file = arg.substr(11); } else if (arg.find("--useUKgrid") == 0) { useUKgrid = true; } else if (arg.find("--no-write-shared-edges") == 0) { @@ -1188,6 +1132,11 @@ int main(int argc, char **argv) { load_dirs.push_back(argv[i]); cout << "Load directory: " << argv[i] << endl; } + cout << "USGS Map file is " << usgs_map_file << endl; + if ( ! load_usgs_map( usgs_map_file ) ) { + SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load USGS map file " << usgs_map_file); + exit(-1); + } #if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) || defined( _MSC_VER ) // the next bit crashes Cygwin for me - DCL diff --git a/src/BuildTiles/Main/usgs.cxx b/src/BuildTiles/Main/usgs.cxx new file mode 100644 index 00000000..92665e27 --- /dev/null +++ b/src/BuildTiles/Main/usgs.cxx @@ -0,0 +1,67 @@ +// usgs.cxx -- manage USGS mapping +// +// Written by Ralf Gerlich, started December 2009 +// +// Copyright (C) 2009 Ralf Gerlich - ralf.gerlich custom-scenery org +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include +#include +#include + +#include +#include +#include + +#include "usgs.hxx" + +using std::fstream; +using std::string; +using std::vector; + +static vector usgs_map; + +int load_usgs_map( const std::string& filename ) { + fstream in ( filename.c_str() ); + + if ( ! in ) { + SG_LOG(SG_GENERAL, SG_ALERT, "Unable to open file " << filename); + return 0; + } + + in >> skipcomment; + while ( !in.eof() ) { + string name; + in >> name; + usgs_map.push_back( get_area_type( name ) ); + in >> skipcomment; + } + + in.close(); + + return 1; +} + +// Translate USGS land cover values into TerraGear area types. +AreaType translateUSGSCover (int usgs_value) +{ + if ( 0 custom-scenery org +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#ifndef _USGS_HXX +#define _USGS_HXX + +#include + +#include + +#include + +int load_usgs_map( const std::string& filename ); +AreaType translateUSGSCover( int usgs_value ); + +#endif // _USGS_HXX + diff --git a/src/BuildTiles/Main/usgsmap.txt b/src/BuildTiles/Main/usgsmap.txt new file mode 100644 index 00000000..42ed5097 --- /dev/null +++ b/src/BuildTiles/Main/usgsmap.txt @@ -0,0 +1,51 @@ +# Default setting +Default +# 1: Urban and Built-Up Land +BuiltUpCover +# 2: Dryland Cropland and Pasture +DryCropPastureCover +# 3: Irrigated Cropland and Pasture +IrrCropPastureCover +# 4: Mixed Dryland/Irrigated Cropland and Pasture +MixedCropPastureCover +# 5: Cropland/Grassland Mosaic +CropGrassCover +# 6: Cropland/Woodland Mosaic +CropWoodCover +# 7: Grassland +GrassCover +# 8: Shrubland +ShrubCover +# 9: Mixed Shrubland/Grassland +ShrubGrassCover +# 10: Savanna +SavannaCover +# 11: Deciduous Broadleaf Forest +DeciduousBroadCover +# 12: Deciduous Needleleaf Forest +DeciduousNeedleCover +# 13: Evergreen Broadleaf Forest +EvergreenBroadCover +# 14: Evergreen Needleleaf Forest +EvergreenNeedleCover +# 15: Mixed Forest +MixedForestCover +# 16: Water Bodies +Default +# 17: Herbaceous Wetland +HerbWetlandCover +# 18: Wooded Wetland +WoodedWetlandCover +# 19: Barren or Sparsely Vegetated +BarrenCover +# 20: Herbaceous Tundra +HerbTundraCover +# 21: Wooded Tundra +WoodedTundraCover +# 22: Mixed Tundra +MixedTundraCover +# 23: Bare Ground Tundra +BareTundraCover +# 24: Snow or Ice +SnowCover +