diff --git a/src/BuildTiles/Main/tgconstruct_clip.cxx b/src/BuildTiles/Main/tgconstruct_clip.cxx index f2887167..332c888f 100644 --- a/src/BuildTiles/Main/tgconstruct_clip.cxx +++ b/src/BuildTiles/Main/tgconstruct_clip.cxx @@ -28,6 +28,7 @@ #include #include +#include #include "tgconstruct.hxx" @@ -39,32 +40,28 @@ bool TGConstruct::ClipLandclassPolys( void ) { tgPolygon safety_base; tgcontour_list slivers; SGGeod p; - SGVec2d min, max; bool debug_area, debug_shape; static int accum_idx = 0; - - // Get clip bounds - min.x() = bucket.get_center_lon() - 0.5 * bucket.get_width(); - min.y() = bucket.get_center_lat() - 0.5 * bucket.get_height(); - max.x() = bucket.get_center_lon() + 0.5 * bucket.get_width(); - max.y() = bucket.get_center_lat() + 0.5 * bucket.get_height(); - tgAccumulator accum; // set up clipping tile : and remember to add the nodes! - p = SGGeod::fromDegM( min.x(), min.y(), -9999.0 ); + p = bucket.get_corner( SG_BUCKET_SW ); + p.setElevationM( -9999.0 ); safety_base.AddNode( 0, p ); nodes.unique_add( p ); - p = SGGeod::fromDegM( max.x(), min.y(), -9999.0 ); + p = bucket.get_corner( SG_BUCKET_SE ); + p.setElevationM( -9999.0 ); safety_base.AddNode( 0, p ); nodes.unique_add( p ); - p = SGGeod::fromDegM( max.x(), max.y(), -9999.0 ); + p = bucket.get_corner( SG_BUCKET_NE ); + p.setElevationM( -9999.0 ); safety_base.AddNode( 0, p ); nodes.unique_add( p ); - p = SGGeod::fromDegM( min.x(), max.y(), -9999.0 ); + p = bucket.get_corner( SG_BUCKET_NW ); + p.setElevationM( -9999.0 ); safety_base.AddNode( 0, p ); nodes.unique_add( p ); diff --git a/src/Lib/terragear/tg_chopper.cxx b/src/Lib/terragear/tg_chopper.cxx index 2b27e14b..f36800b0 100644 --- a/src/Lib/terragear/tg_chopper.cxx +++ b/src/Lib/terragear/tg_chopper.cxx @@ -6,44 +6,21 @@ #include #include - #include "tg_chopper.hxx" #include "tg_shapefile.hxx" - -unsigned int clip_num = 0; +#include "tg_misc.hxx" tgPolygon tgChopper::Clip( const tgPolygon& subject, const std::string& type, SGBucket& b ) { - // p; - - SGGeod min, max; - SGGeod c = b.get_center(); - double span = b.get_width(); tgPolygon base, result; - // calculate bucket dimensions - if ( (c.getLatitudeDeg() >= -89.0) && (c.getLatitudeDeg() < 89.0) ) { - min = SGGeod::fromDeg( c.getLongitudeDeg() - span/2.0, c.getLatitudeDeg() - SG_HALF_BUCKET_SPAN ); - max = SGGeod::fromDeg( c.getLongitudeDeg() + span/2.0, c.getLatitudeDeg() + SG_HALF_BUCKET_SPAN ); - } else if ( c.getLatitudeDeg() < -89.0) { - min = SGGeod::fromDeg( -90.0, -180.0 ); - max = SGGeod::fromDeg( -89.0, 180.0 ); - } else if ( c.getLatitudeDeg() >= 89.0) { - min = SGGeod::fromDeg( 89.0, -180.0 ); - max = SGGeod::fromDeg( 90.0, 180.0 ); - } else { - SG_LOG( SG_GENERAL, SG_ALERT, "Out of range latitude in clip_and_write_poly() = " << c.getLatitudeDeg() ); - } - - SG_LOG( SG_GENERAL, SG_DEBUG, " (" << min << ") (" << max << ")" ); - - // set up clipping tile - base.AddNode( 0, SGGeod::fromDeg( min.getLongitudeDeg(), min.getLatitudeDeg()) ); - base.AddNode( 0, SGGeod::fromDeg( max.getLongitudeDeg(), min.getLatitudeDeg()) ); - base.AddNode( 0, SGGeod::fromDeg( max.getLongitudeDeg(), max.getLatitudeDeg()) ); - base.AddNode( 0, SGGeod::fromDeg( min.getLongitudeDeg(), max.getLatitudeDeg()) ); + // set up clipping tile : and remember to add the nodes! + base.AddNode( 0, b.get_corner( SG_BUCKET_SW ) ); + base.AddNode( 0, b.get_corner( SG_BUCKET_SE ) ); + base.AddNode( 0, b.get_corner( SG_BUCKET_NE ) ); + base.AddNode( 0, b.get_corner( SG_BUCKET_NW ) ); result = tgPolygon::Intersect( subject, base ); if ( result.Contours() > 0 ) { @@ -123,12 +100,10 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type ) for ( int row = 0; row <= dy; row++ ) { - // Generate a clip rectangle - add some buffer on top and bottom, so we don't clip directly on an edge when we - // clip the individual buckets - // TODO : May no longer be necessary + // Generate a clip rectangle for the whole row SGBucket b_clip = sgBucketOffset( bb.getMin().getLongitudeDeg(), bb.getMin().getLatitudeDeg(), 0, row ); - double clip_bottom = b_clip.get_center_lat() - SG_HALF_BUCKET_SPAN; // + 0.01); - double clip_top = b_clip.get_center_lat() + SG_HALF_BUCKET_SPAN; // + 0.01); + double clip_bottom = b_clip.get_center_lat() - SG_HALF_BUCKET_SPAN; + double clip_top = b_clip.get_center_lat() + SG_HALF_BUCKET_SPAN; tgPolygon clip_row, clipped; SG_LOG( SG_GENERAL, SG_DEBUG, " CLIPPED row " << row << " center lat is " << b_clip.get_center_lat() << " clip_botton is " << clip_bottom << " clip_top is " << clip_top ); @@ -153,26 +128,6 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type ) clipped.SetFlag(type); ClipRow( clipped, b_clip.get_center_lat(), type ); - -#if 0 - { - char layer[32]; - char ds_name[64]; - sprintf(ds_name, "./stripped_%s", type.c_str() ); - - sprintf(layer, "orig_%d", clip_num ); - tgShapefile::FromPolygon( subject, ds_name, layer, "poly" ); - - sprintf(layer, "clip_row_%d", clip_num ); - tgShapefile::FromPolygon( clip_row, ds_name, layer, "poly" ); - - sprintf(layer, "result_%d", clip_num ); - tgShapefile::FromPolygon( clipped, ds_name, layer, "poly" ); - - clip_num++; - } -#endif - } } } diff --git a/src/Lib/terragear/tg_misc.hxx b/src/Lib/terragear/tg_misc.hxx index 2bb89f4e..49ba7427 100644 --- a/src/Lib/terragear/tg_misc.hxx +++ b/src/Lib/terragear/tg_misc.hxx @@ -3,6 +3,13 @@ #include "clipper.hpp" #include "tg_rectangle.hxx" +// SGBucket corners +#define SG_BUCKET_SW (0) +#define SG_BUCKET_SE (1) +#define SG_BUCKET_NE (2) +#define SG_BUCKET_NW (3) + + // SGGeod Cleanup SGGeod SGGeod_snap( const SGGeod& in, double grid );