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
#include <Debug/logstream.hxx>
-#include "names.hxx"
+#include <Polygon/index.hxx>
+#include <Polygon/names.hxx>
#include "shape.hxx"
if ( argc != 3 ) {
FG_LOG( FG_GENERAL, FG_ALERT, "Usage: " << argv[0]
- << " <shapefile> <workdir>" );
+ << " <shape_file> <work_dir>" );
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();
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 );
// $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.
//
+++ /dev/null
-// 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/compiler.h>
-
-#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.
-//
+++ /dev/null
-// 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 <gfc/gadt_polygon.h>
-#include <gfc/gdbf.h>
-#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.
-//
#include <Bucket/newbucket.hxx>
#include <Debug/logstream.hxx>
-#include "names.hxx"
+#include <Polygon/index.hxx>
+#include <Polygon/names.hxx>
#include "shape.hxx"
};
-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) ) {
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);
// 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;
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 );
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;
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;
// $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.
//
#include <gpc.h>
}
-#include "names.hxx"
+#include <Polygon/names.hxx>
// Initialize structure we use to create polygons for the gpc library
// $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.
//