]> git.mxchange.org Git - flightgear.git/blob - ShapeFile/main.cxx
Initial revision.
[flightgear.git] / ShapeFile / main.cxx
1 // main.cxx -- process shapefiles and extract polygon outlines,
2 //             clipping against and sorting them into the revelant
3 //             tiles.
4 //
5 // Written by Curtis Olson, started February 1999.
6 //
7 // Copyright (C) 1999  Curtis L. Olson  - curt@flightgear.org
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 //
23 // $Id$
24 // (Log is kept at end of this file)
25  
26
27 // Include Geographic Foundation Classes library
28
29 // libgfc.a includes need this bit o' strangeness
30 #if defined ( linux )
31 #  define _LINUX_
32 #endif
33
34 #include <gfc/gadt_polygon.h>
35 #include <gfc/gdbf.h>
36 #include <gfc/gshapefile.h>
37
38 // include Generic Polygon Clipping Library
39
40 extern "C" {
41 #include <gpc.h>
42 }
43
44 #include <Debug/logstream.hxx>
45
46
47 int main( int argc, char **argv ) {
48     fglog().setLogLevels( FG_ALL, FG_DEBUG );
49
50     if ( argc != 2 ) {
51         FG_LOG( FG_GENERAL, FG_ALERT, "Usage: " << argv[0] << " <shapefile>" );
52         exit(-1);
53     }
54
55     FG_LOG( FG_GENERAL, FG_DEBUG, "Opening " << argv[1] << " for reading." );
56
57     GShapeFile * sf = new GShapeFile( argv[1] );
58     GDBFile *names = new GDBFile( argv[1] );
59
60     GPolygon shape;
61     double  *coords; // in decimal degrees
62     int n_vertices;
63     double lon, lat;
64
65     FG_LOG( FG_GENERAL, FG_INFO, sf->numRecords() );
66
67     GShapeFile::ShapeType t = sf->shapeType();
68     if ( t != GShapeFile::av_Polygon ) {
69         FG_LOG( FG_GENERAL, FG_ALERT, "Can't handle non-polygon shape files" );
70         exit(-1);
71     }
72
73     for ( int i = 0; i < sf->numRecords(); i++ ) {
74         //fetch i-th record (shape)
75         FG_LOG( FG_GENERAL, FG_DEBUG, names->getRecord( i ) );
76
77         sf->getShapeRec(i, &shape); 
78
79         FG_LOG( FG_GENERAL, FG_DEBUG, "Record = " << i << "  rings = " 
80                 << shape.numRings() );
81
82         for ( int j = 0; j < shape.numRings(); j++ ) {
83             //return j-th branch's coords, # of vertices
84             n_vertices = shape.getRing(j, coords);
85
86             FG_LOG( FG_GENERAL, FG_DEBUG, "  ring " << j << " = " );
87             FG_LOG( FG_GENERAL, FG_INFO, n_vertices );
88
89             for ( int k = 0; k < n_vertices; k++ ) {
90                 lon = coords[k*2+0];
91                 lat = coords[k*2+1];
92                 FG_LOG( FG_GENERAL, FG_INFO, lon << " " << lat );
93             }
94         }
95     }
96
97     return 0;
98 }
99
100 // $Log$
101 // Revision 1.1  1999/02/15 19:10:23  curt
102 // Initial revision.
103 //