From ad34c1e4e4fe7870d0b99a268879935bfb09e2d2 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 25 Feb 1999 21:30:24 +0000 Subject: [PATCH] Initial revision. --- Polygon/Makefile.am | 7 +++ Polygon/index.cxx | 76 +++++++++++++++++++++++ Polygon/index.hxx | 48 ++++++++++++++ Polygon/names.cxx | 148 ++++++++++++++++++++++++++++++++++++++++++++ Polygon/names.hxx | 76 +++++++++++++++++++++++ 5 files changed, 355 insertions(+) create mode 100644 Polygon/Makefile.am create mode 100644 Polygon/index.cxx create mode 100644 Polygon/index.hxx create mode 100644 Polygon/names.cxx create mode 100644 Polygon/names.hxx diff --git a/Polygon/Makefile.am b/Polygon/Makefile.am new file mode 100644 index 000000000..caa4c59be --- /dev/null +++ b/Polygon/Makefile.am @@ -0,0 +1,7 @@ +noinst_LIBRARIES = libPolygon.a + +libPolygon_a_SOURCES = \ + index.cxx index.hxx \ + names.cxx names.hxx + +INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib diff --git a/Polygon/index.cxx b/Polygon/index.cxx new file mode 100644 index 000000000..a467c0ba6 --- /dev/null +++ b/Polygon/index.cxx @@ -0,0 +1,76 @@ +// index.cxx -- routines to handle a unique/persistant integer polygon index +// +// Written by Curtis Olson, started February 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.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. +// +// $Id$ +// (Log is kept at end of this file) + +#include + +#include STL_STRING + +#include + +#include "index.hxx" + + +static int poly_index; +static string poly_path; + + +// initialize the unique polygon index counter stored in path +bool poly_index_init( string path ) { + poly_path = path; + + FILE *fp = fopen( poly_path.c_str(), "r" ); + + if ( fp == NULL ) { + cout << "Error cannot open " << poly_path << endl; + poly_index = 0; + return false; + } + + fscanf( fp, "%d", &poly_index ); + + fclose( fp ); +} + + +// increment the persistant counter and return the next poly_index +int poly_index_next() { + ++poly_index; + + FILE *fp = fopen( poly_path.c_str(), "w" ); + + if ( fp == NULL ) { + cout << "Error cannot open " << poly_path << " for writing" << endl; + } + + fprintf( fp, "%d\n", poly_index ); + + fclose( fp ); + + return poly_index; +} + + +// $Log$ +// Revision 1.1 1999/02/25 21:30:24 curt +// Initial revision. +// diff --git a/Polygon/index.hxx b/Polygon/index.hxx new file mode 100644 index 000000000..ddc8acb6f --- /dev/null +++ b/Polygon/index.hxx @@ -0,0 +1,48 @@ +// index.cxx -- routines to handle a unique/persistant integer polygon index +// +// Written by Curtis Olson, started February 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.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. +// +// $Id$ +// (Log is kept at end of this file) + + +#ifndef _INDEX_HXX +#define _INDEX_HXX + + +#include + +#include STL_STRING + + +// initialize the unique polygon index counter stored in path +bool poly_index_init( string path ); + +// increment the persistant counter and return the next poly_index +int poly_index_next(); + + + +#endif // _INDEX_HXX + + +// $Log$ +// Revision 1.1 1999/02/25 21:30:24 curt +// Initial revision. +// diff --git a/Polygon/names.cxx b/Polygon/names.cxx new file mode 100644 index 000000000..d01dd9b8d --- /dev/null +++ b/Polygon/names.cxx @@ -0,0 +1,148 @@ +// names.cxx -- process shapefiles names +// +// Written by Curtis Olson, started February 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.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. +// +// $Id$ +// (Log is kept at end of this file) + +#include + +#include STL_STRING + +#include "names.hxx" + + +// return the type of the shapefile record +AreaType get_area_type(GDBFile *dbf, int rec) { + GDBFieldDesc *fdesc[128]; // 128 is an arbitrary number here + GDBFValue *fields; //an array of field values + char* dbf_rec; //a record containing all the fields + + // grab the meta-information for all the fields + // this applies to all the records in the DBF file. + // for ( int i = 0; i < dbf->numFields(); i++ ) { + // fdesc[i] = dbf->getFieldDesc(i); + // cout << i << ") " << fdesc[i]->name << endl; + // } + + // this is the whole name record + dbf_rec = dbf->getRecord( rec ); + + // parse it into individual fields + if ( dbf_rec ) { + fields = dbf->recordDeform( dbf_rec ); + } + + string area = fields[4].str_v; + // strip leading spaces + while ( area[0] == ' ' ) { + area = area.substr(1, area.length() - 1); + } + // strip trailing spaces + while ( area[area.length() - 1] == ' ' ) { + area = area.substr(0, area.length() - 1); + } + // strip other junk encountered + while ( (int)area[area.length() - 1] == 9 ) { + area = area.substr(0, area.length() - 1); + } + + if ( area == "AirportKeep" ) { + return AirportKeepArea; + } else if ( area == "AirportIgnore" ) { + return AirportIgnoreArea; + } else if ( area == "Swamp or Marsh" ) { + return MarshArea; + } else if ( area == "Bay Estuary or Ocean" ) { + return OceanArea; + } else if ( area == "Lake" ) { + return LakeArea; + } else if ( area == "Lake Dry" ) { + return DryLakeArea; + } else if ( area == "Lake Intermittent" ) { + return IntLakeArea; + } else if ( area == "Reservoir" ) { + return ReservoirArea; + } else if ( area == "Reservoir Intermittent" ) { + return IntReservoirArea; + } else if ( area == "Stream" ) { + return StreamArea; + } else if ( area == "Canal" ) { + return CanalArea; + } else if ( area == "Glacier" ) { + return GlacierArea; + } else if ( area == "Void Area" ) { + return VoidArea; + } else if ( area == "Null" ) { + return NullArea; + } else { + cout << "unknown area = '" << area << "'" << endl; + // cout << "area = " << area << endl; + for ( int i = 0; i < area.length(); i++ ) { + cout << i << ") " << (int)area[i] << endl; + } + return UnknownArea; + } +} + + +// return text form of area name +string get_area_name( AreaType area ) { + if ( area == AirportKeepArea ) { + return "AirportKeep"; + } else if ( area == AirportIgnoreArea ) { + return "AirportIgnore"; + } else if ( area == MarshArea ) { + return "Marsh"; + } else if ( area == OceanArea ) { + return "Ocean"; + } else if ( area == LakeArea ) { + return "Lake"; + } else if ( area == DryLakeArea ) { + return "DryLake"; + } else if ( area == IntLakeArea ) { + return "IntermittentLake"; + } else if ( area == ReservoirArea ) { + return "Reservoir"; + } else if ( area == IntReservoirArea ) { + return "IntermittentReservoir"; + } else if ( area == StreamArea ) { + return "Stream"; + } else if ( area == CanalArea ) { + return "Canal"; + } else if ( area == GlacierArea ) { + return "Glacier"; + } else if ( area == VoidArea ) { + return "VoidArea"; + } else if ( area == NullArea ) { + return "Null"; + } else { + cout << "unknown area code = " << (int)area << endl; + return "Unknown"; + } +} + + +// $Log$ +// Revision 1.1 1999/02/25 21:30:24 curt +// Initial revision. +// +// Revision 1.1 1999/02/23 01:29:05 curt +// Additional progress. +// diff --git a/Polygon/names.hxx b/Polygon/names.hxx new file mode 100644 index 000000000..50222d104 --- /dev/null +++ b/Polygon/names.hxx @@ -0,0 +1,76 @@ +// names.hxx -- process shapefiles names +// +// Written by Curtis Olson, started February 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.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. +// +// $Id$ +// (Log is kept at end of this file) + + +#ifndef _NAMES_HXX +#define _NAMES_HXX + + +// libgfc.a includes need this bit o' strangeness +#if defined ( linux ) +# define _LINUX_ +#endif +#include +#include +#undef E +#undef DEG_TO_RAD +#undef RAD_TO_DEG + + +// Posible shape file types +enum AreaType { + AirportKeepArea = 0, + AirportIgnoreArea = 1, + MarshArea = 2, + OceanArea = 3, + LakeArea = 4, + DryLakeArea = 5, + IntLakeArea = 6, + ReservoirArea = 7, + IntReservoirArea = 8, + StreamArea = 9, + CanalArea = 10, + GlacierArea = 11, + VoidArea = 9997, + NullArea = 9998, + UnknownArea = 9999 +}; + + +// return the type of the shapefile record +AreaType get_area_type(GDBFile *dbf, int rec); + +// return text form of area name +string get_area_name( AreaType area ); + + +#endif // _NAMES_HXX + + +// $Log$ +// Revision 1.1 1999/02/25 21:30:24 curt +// Initial revision. +// +// Revision 1.1 1999/02/23 01:29:05 curt +// Additional progress. +//