X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=ShapeFile%2Fmain.cxx;h=3af9438c61d37db7a9783ca0faff7083b39fbbde;hb=1a7c97601d6203a5c26e3531d80a50277db2236f;hp=966b14f4ad111a3ad33269e0fcb16bf9d517bc79;hpb=d4950f5e70344d81e868e91cc544fcda0c9eb3f9;p=flightgear.git diff --git a/ShapeFile/main.cxx b/ShapeFile/main.cxx index 966b14f4a..3af9438c6 100644 --- a/ShapeFile/main.cxx +++ b/ShapeFile/main.cxx @@ -30,11 +30,9 @@ #if defined ( linux ) # define _LINUX_ #endif - #include #include #include - #undef E #undef DEG_TO_RAD #undef RAD_TO_DEG @@ -44,68 +42,42 @@ extern "C" { #include } -#include -#include +#include +#include STL_STRING -class point2d { -public: - double x, y; -}; - - -static void clip_and_write_poly( FGBucket b, int n_vertices, double *coords ) { - point2d c, min, max; - c.x = b.get_center_lon(); - c.y = b.get_center_lat(); - double span = bucket_span(c.y); - - // calculate bucket dimensions - if ( (c.y >= -89.0) && (c.y < 89.0) ) { - min.x = c.x - span / 2.0; - max.x = c.x + span / 2.0; - min.y = c.y - FG_HALF_BUCKET_SPAN; - max.y = c.y + FG_HALF_BUCKET_SPAN; - } else if ( c.y < -89.0) { - min.x = -90.0; - max.x = -89.0; - min.y = -180.0; - max.y = 180.0; - } else if ( c.y >= 89.0) { - min.x = 89.0; - max.x = 90.0; - min.y = -180.0; - max.y = 180.0; - } else { - FG_LOG ( FG_GENERAL, FG_ALERT, - "Out of range latitude in clip_and_write_poly() = " << c.y ); - } +#include - -} +#include "names.hxx" +#include "shape.hxx" int main( int argc, char **argv ) { - point2d min, max; + gpc_polygon gpc_shape; + int i, j; fglog().setLogLevels( FG_ALL, FG_DEBUG ); - if ( argc != 2 ) { - FG_LOG( FG_GENERAL, FG_ALERT, "Usage: " << argv[0] << " " ); + 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 structure for building gpc polygons + shape_utils_init(); + GShapeFile * sf = new GShapeFile( argv[1] ); - GDBFile *names = new GDBFile( argv[1] ); + GDBFile *dbf = new GDBFile( argv[1] ); + string path = argv[2]; GPolygon shape; double *coords; // in decimal degrees int n_vertices; - double lon, lat; - FG_LOG( FG_GENERAL, FG_INFO, sf->numRecords() ); + FG_LOG( FG_GENERAL, FG_INFO, "shape file records = " << sf->numRecords() ); GShapeFile::ShapeType t = sf->shapeType(); if ( t != GShapeFile::av_Polygon ) { @@ -113,78 +85,178 @@ int main( int argc, char **argv ) { exit(-1); } - for ( int i = 0; i < sf->numRecords(); i++ ) { + for ( i = 16473; i < sf->numRecords(); i++ ) { //fetch i-th record (shape) - FG_LOG( FG_GENERAL, FG_DEBUG, names->getRecord( i ) ); - sf->getShapeRec(i, &shape); - FG_LOG( FG_GENERAL, FG_DEBUG, "Record = " << i << " rings = " << shape.numRings() ); - for ( int j = 0; j < shape.numRings(); j++ ) { - //return j-th branch's coords, # of vertices - n_vertices = shape.getRing(j, coords); - - FG_LOG( FG_GENERAL, FG_DEBUG, " ring " << j << " = " ); - FG_LOG( FG_GENERAL, FG_INFO, n_vertices ); - - // find min/max of this polygon - min.x = min.y = 200.0; - max.x = max.y = -200.0; - for ( int k = 0; k < n_vertices; k++ ) { - if ( coords[k*2+0] < min.x ) { min.x = coords[k*2+0]; } - if ( coords[k*2+1] < min.y ) { min.y = coords[k*2+1]; } - if ( coords[k*2+0] > max.x ) { max.x = coords[k*2+0]; } - if ( coords[k*2+1] > max.y ) { max.y = coords[k*2+1]; } + AreaType area = get_area_type(dbf, i); + FG_LOG( FG_GENERAL, FG_DEBUG, "area type = " << (int)area ); + + FG_LOG( FG_GENERAL, FG_INFO, " record = " << i + << " ring = " << 0 ); + + if ( area == MarshArea ) { + // interior of polygon is marsh, holes are water + + // do main outline first + init_shape(&gpc_shape); + n_vertices = shape.getRing(0, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + + // do lakes (individually) next + for ( j = 1; j < shape.numRings(); j++ ) { + FG_LOG( FG_GENERAL, FG_INFO, " record = " << i + << " ring = " << j ); + init_shape(&gpc_shape); + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + process_shape(path, LakeArea, &gpc_shape); + free_shape(&gpc_shape); + } + } else if ( area == OceanArea ) { + // interior of polygon is ocean, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == LakeArea ) { + // interior of polygon is lake, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == DryLakeArea ) { + // interior of polygon is dry lake, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == IntLakeArea ) { + // interior of polygon is intermittent lake, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == ReservoirArea ) { + // interior of polygon is reservoir, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == IntReservoirArea ) { + // interior of polygon is intermittent reservoir, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == StreamArea ) { + // interior of polygon is stream, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == CanalArea ) { + // interior of polygon is canal, holes are islands + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == GlacierArea ) { + // interior of polygon is glacier, holes are dry land + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == VoidArea ) { + // interior is ???? + + // skip for now + FG_LOG( FG_GENERAL, FG_ALERT, "Void area ... SKIPPING!" ); + + if ( shape.numRings() > 1 ) { + FG_LOG( FG_GENERAL, FG_ALERT, " Void area with holes!" ); + // exit(-1); } - FG_LOG( FG_GENERAL, FG_INFO, "min = " << min.x << "," << min.y - << " max = " << max.x << "," << max.y ); - - // find buckets for min, and max points of convex hull. - // note to self: self, you should think about checking for - // polygons that span the date line - FGBucket b_min(min.x, min.y); - FGBucket b_max(max.x, max.y); - cout << "Bucket min = " << b_min << endl; - cout << "Bucket max = " << b_max << endl; - - if ( b_min == b_max ) { - clip_and_write_poly( b_min, n_vertices, coords ); - } else { - FGBucket b_cur; - int dx, dy, i, j; - - fgBucketDiff(b_min, b_max, &dx, &dy); - cout << "airport spans tile boundaries" << endl; - cout << " dx = " << dx << " dy = " << dy << endl; - - if ( (dx > 1) || (dy > 1) ) { - cout << "somethings really wrong!!!!" << endl; - exit(-1); - } - - 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( b_cur, n_vertices, coords ); - } - } - // string answer; cin >> answer; + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); } + // process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else if ( area == NullArea ) { + // interior is ???? - for ( int k = 0; k < n_vertices; k++ ) { - lon = coords[k*2+0]; - lat = coords[k*2+1]; - FG_LOG( FG_GENERAL, FG_INFO, lon << " " << lat ); + // skip for now + FG_LOG( FG_GENERAL, FG_ALERT, "Null area ... SKIPPING!" ); + + if ( shape.numRings() > 1 ) { + FG_LOG( FG_GENERAL, FG_ALERT, " Null area with holes!" ); + // exit(-1); } + + init_shape(&gpc_shape); + for ( j = 0; j < shape.numRings(); j++ ) { + n_vertices = shape.getRing(j, coords); + add_to_shape(n_vertices, coords, &gpc_shape); + } + // process_shape(path, area, &gpc_shape); + free_shape(&gpc_shape); + } else { + FG_LOG( FG_GENERAL, FG_ALERT, "Uknown area!" ); + exit(-1); } } return 0; } + // $Log$ +// Revision 1.3 1999/02/23 01:29:04 curt +// Additional progress. +// // Revision 1.2 1999/02/19 19:05:18 curt // Working on clipping shapes and distributing into buckets. //