Load USGS-to-TerraGear translation from external file (closes #10)
This commit is contained in:
parent
3bee1edab4
commit
824d734eb4
6 changed files with 169 additions and 66 deletions
|
@ -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 <at> custom-scenery <dot> 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 <simgear/compiler.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include <landcover/landcover.hxx>
|
||||
|
||||
#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=<degrees>" << endl;
|
||||
cout << " --ydist=<degrees>" << endl;
|
||||
cout << " --nudge=<float>" << endl;
|
||||
cout << " --usgs-map=<filename>" << 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
|
||||
|
|
67
src/BuildTiles/Main/usgs.cxx
Normal file
67
src/BuildTiles/Main/usgs.cxx
Normal file
|
@ -0,0 +1,67 @@
|
|||
// usgs.cxx -- manage USGS mapping
|
||||
//
|
||||
// Written by Ralf Gerlich, started December 2009
|
||||
//
|
||||
// Copyright (C) 2009 Ralf Gerlich - ralf.gerlich <at> custom-scenery <dot> 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 <simgear/compiler.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/misc/sgstream.hxx>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "usgs.hxx"
|
||||
|
||||
using std::fstream;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
static vector<AreaType> 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<usgs_value && usgs_value<usgs_map.size() ) {
|
||||
return usgs_map[usgs_value];
|
||||
} else {
|
||||
return usgs_map[0];
|
||||
}
|
||||
}
|
||||
|
35
src/BuildTiles/Main/usgs.hxx
Normal file
35
src/BuildTiles/Main/usgs.hxx
Normal file
|
@ -0,0 +1,35 @@
|
|||
// usgs.hxx -- manage USGS mapping
|
||||
//
|
||||
// Written by Ralf Gerlich, started December 2009
|
||||
//
|
||||
// Copyright (C) 2009 Ralf Gerlich - ralf.gerlich <at> custom-scenery <dot> 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 <Clipper/priorities.hxx>
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
int load_usgs_map( const std::string& filename );
|
||||
AreaType translateUSGSCover( int usgs_value );
|
||||
|
||||
#endif // _USGS_HXX
|
||||
|
51
src/BuildTiles/Main/usgsmap.txt
Normal file
51
src/BuildTiles/Main/usgsmap.txt
Normal file
|
@ -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
|
||||
|
Loading…
Reference in a new issue