From: curt Date: Thu, 25 Feb 1999 21:31:04 +0000 (+0000) Subject: First working version??? X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8de225f5bff36deb953d59067118c961cbf84445;p=flightgear.git First working version??? --- diff --git a/ShapeFile/Makefile.am b/ShapeFile/Makefile.am index c0c4b666e..6aec7fdec 100644 --- a/ShapeFile/Makefile.am +++ b/ShapeFile/Makefile.am @@ -1,12 +1,14 @@ bin_PROGRAMS = shape-decode -shape_decode_SOURCES = names.cxx names.hxx main.cxx shape.cxx shape.hxx +shape_decode_SOURCES = main.cxx shape.cxx shape.hxx -shape_decode_LDADD = $(top_builddir)/Lib/Debug/libDebug.a \ +shape_decode_LDADD = \ + $(top_builddir)/Tools/Polygon/libPolygon.a \ + $(top_builddir)/Lib/Debug/libDebug.a \ $(top_builddir)/Lib/Bucket/libBucket.a \ $(top_builddir)/Lib/Misc/libMisc.a \ $(top_builddir)/Lib/zlib/libz.a \ -lgfc -lgpc -INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib +INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Tools diff --git a/ShapeFile/main.cxx b/ShapeFile/main.cxx index 3af9438c6..58ebf52a1 100644 --- a/ShapeFile/main.cxx +++ b/ShapeFile/main.cxx @@ -48,7 +48,8 @@ extern "C" { #include -#include "names.hxx" +#include +#include #include "shape.hxx" @@ -60,12 +61,17 @@ int main( int argc, char **argv ) { if ( argc != 3 ) { FG_LOG( FG_GENERAL, FG_ALERT, "Usage: " << argv[0] - << " " ); + << " " ); exit(-1); } FG_LOG( FG_GENERAL, FG_DEBUG, "Opening " << argv[1] << " for reading." ); + // initialize persistant polygon counter + string counter_file = argv[2]; + counter_file += "/polygon.counter"; + poly_index_init( counter_file ); + // initialize structure for building gpc polygons shape_utils_init(); @@ -85,14 +91,15 @@ int main( int argc, char **argv ) { exit(-1); } - for ( i = 16473; i < sf->numRecords(); i++ ) { + for ( i = 0; i < sf->numRecords(); i++ ) { //fetch i-th record (shape) sf->getShapeRec(i, &shape); FG_LOG( FG_GENERAL, FG_DEBUG, "Record = " << i << " rings = " << shape.numRings() ); AreaType area = get_area_type(dbf, i); - FG_LOG( FG_GENERAL, FG_DEBUG, "area type = " << (int)area ); + FG_LOG( FG_GENERAL, FG_DEBUG, "area type = " << get_area_name(area) + << " (" << (int)area << ")" ); FG_LOG( FG_GENERAL, FG_INFO, " record = " << i << " ring = " << 0 ); @@ -254,6 +261,9 @@ int main( int argc, char **argv ) { // $Log$ +// Revision 1.4 1999/02/25 21:31:05 curt +// First working version??? +// // Revision 1.3 1999/02/23 01:29:04 curt // Additional progress. // diff --git a/ShapeFile/names.cxx b/ShapeFile/names.cxx deleted file mode 100644 index 61be113cc..000000000 --- a/ShapeFile/names.cxx +++ /dev/null @@ -1,104 +0,0 @@ -// 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 == "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; - } -} - - -// $Log$ -// Revision 1.1 1999/02/23 01:29:05 curt -// Additional progress. -// diff --git a/ShapeFile/names.hxx b/ShapeFile/names.hxx deleted file mode 100644 index b9dafc524..000000000 --- a/ShapeFile/names.hxx +++ /dev/null @@ -1,68 +0,0 @@ -// 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 { - MarshArea = 0, - OceanArea = 1, - LakeArea = 2, - DryLakeArea = 3, - IntLakeArea = 4, - ReservoirArea = 5, - IntReservoirArea = 6, - StreamArea = 7, - CanalArea = 8, - GlacierArea = 9, - VoidArea = 9997, - NullArea = 9998, - UnknownArea = 9999 -}; - - -// return the type of the shapefile record -AreaType get_area_type(GDBFile *dbf, int rec); - - -#endif // _NAMES_HXX - - -// $Log$ -// Revision 1.1 1999/02/23 01:29:05 curt -// Additional progress. -// diff --git a/ShapeFile/shape.cxx b/ShapeFile/shape.cxx index 1f2dec60c..ae3e1432f 100644 --- a/ShapeFile/shape.cxx +++ b/ShapeFile/shape.cxx @@ -29,7 +29,8 @@ #include #include -#include "names.hxx" +#include +#include #include "shape.hxx" @@ -43,14 +44,14 @@ public: }; -static void clip_and_write_poly( string root, AreaType area, +static void clip_and_write_poly( string root, int p_index, AreaType area, FGBucket b, gpc_polygon *shape ) { point2d c, min, max; c.x = b.get_center_lon(); c.y = b.get_center_lat(); double span = bucket_span(c.y); gpc_polygon base, result; - char tmp[256]; + char tile_name[256], poly_index[256]; // calculate bucket dimensions if ( (c.y >= -89.0) && (c.y < 89.0) ) { @@ -106,42 +107,28 @@ static void clip_and_write_poly( string root, AreaType area, gpc_polygon_clip(GPC_INT, &base, shape, &result); if ( result.num_contours > 0 ) { - long int index = b.gen_index(); + long int t_index = b.gen_index(); string path = root + "/Scenery/" + b.gen_base_path(); string command = "mkdir -p " + path; system( command.c_str() ); - sprintf(tmp, "%ld", index); - string polyfile = path + "/" + tmp; - - if ( area == MarshArea ) { - polyfile += ".marsh"; - } else if ( area == OceanArea ) { - polyfile += ".ocean"; - } else if ( area == LakeArea ) { - polyfile += ".lake"; - } else if ( area == DryLakeArea ) { - polyfile += ".drylake"; - } else if ( area == IntLakeArea ) { - polyfile += ".intlake"; - } else if ( area == ReservoirArea ) { - polyfile += ".reservoir"; - } else if ( area == IntReservoirArea ) { - polyfile += ".intreservoir"; - } else if ( area == StreamArea ) { - polyfile += ".stream"; - } else if ( area == CanalArea ) { - polyfile += ".canal"; - } else if ( area == GlacierArea ) { - polyfile += ".glacier"; - } else { + sprintf( tile_name, "%ld", t_index ); + string polyfile = path + "/" + tile_name; + + sprintf( poly_index, "%d", p_index ); + polyfile += "."; + polyfile += poly_index; + + string poly_type = get_area_name( area ); + if ( poly_type == "Unknown" ) { cout << "unknown area type in clip_and_write_poly()!" << endl; exit(-1); } - FILE *rfp= fopen(polyfile.c_str(), "w"); - gpc_write_polygon(rfp, &result); - fclose(rfp); + FILE *rfp= fopen( polyfile.c_str(), "w" ); + fprintf( rfp, "%s\n", poly_type.c_str() ); + gpc_write_polygon( rfp, &result ); + fclose( rfp ); } gpc_free_polygon(&base); @@ -181,6 +168,7 @@ void add_to_shape(int count, double *coords, gpc_polygon *shape) { // process shape (write polygon to all intersecting tiles) void process_shape(string path, AreaType area, gpc_polygon *gpc_shape) { point2d min, max; + int index; int i, j; min.x = min.y = 200.0; @@ -206,6 +194,9 @@ void process_shape(string path, AreaType area, gpc_polygon *gpc_shape) { exit(-1); */ + // get next polygon index + index = poly_index_next(); + FG_LOG( FG_GENERAL, FG_INFO, " min = " << min.x << "," << min.y << " max = " << max.x << "," << max.y ); @@ -218,7 +209,7 @@ void process_shape(string path, AreaType area, gpc_polygon *gpc_shape) { FG_LOG( FG_GENERAL, FG_INFO, " Bucket max = " << b_max ); if ( b_min == b_max ) { - clip_and_write_poly( path, area, b_min, gpc_shape ); + clip_and_write_poly( path, index, area, b_min, gpc_shape ); } else { FGBucket b_cur; int dx, dy, i, j; @@ -238,7 +229,7 @@ void process_shape(string path, AreaType area, gpc_polygon *gpc_shape) { for ( j = 0; j <= dy; j++ ) { for ( i = 0; i <= dx; i++ ) { b_cur = fgBucketOffset(min.x, min.y, i, j); - clip_and_write_poly( path, area, b_cur, gpc_shape ); + clip_and_write_poly( path, index, area, b_cur, gpc_shape ); } } // string answer; cin >> answer; @@ -253,6 +244,9 @@ void free_shape(gpc_polygon *shape) { // $Log$ +// Revision 1.2 1999/02/25 21:31:08 curt +// First working version??? +// // Revision 1.1 1999/02/23 01:29:06 curt // Additional progress. // diff --git a/ShapeFile/shape.hxx b/ShapeFile/shape.hxx index ea8bcb5f5..6a59b77e3 100644 --- a/ShapeFile/shape.hxx +++ b/ShapeFile/shape.hxx @@ -31,7 +31,7 @@ extern "C" { #include } -#include "names.hxx" +#include // Initialize structure we use to create polygons for the gpc library @@ -56,6 +56,9 @@ void free_shape(gpc_polygon *shape); // $Log$ +// Revision 1.2 1999/02/25 21:31:09 curt +// First working version??? +// // Revision 1.1 1999/02/23 01:29:06 curt // Additional progress. //