diff --git a/src/BuildTiles/Main/tgconstruct_clip.cxx b/src/BuildTiles/Main/tgconstruct_clip.cxx index 4c71e2e7..8b98d29d 100644 --- a/src/BuildTiles/Main/tgconstruct_clip.cxx +++ b/src/BuildTiles/Main/tgconstruct_clip.cxx @@ -41,8 +41,8 @@ bool TGConstruct::ClipLandclassPolys( void ) { tgcontour_list slivers; SGGeod p; bool debug_area, debug_shape; - static int accum_idx = 0; tgAccumulator accum; + unsigned int accum_idx = 0; // set up clipping tile : and remember to add the nodes! p = bucket.get_corner( SG_BUCKET_SW ); @@ -129,9 +129,11 @@ bool TGConstruct::ClipLandclassPolys( void ) { sprintf(layer, "pre_clip_%d", polys_in.get_poly( i, j ).GetId() ); sprintf(name, "shape %d,%d", i,j); tgShapefile::FromPolygon( tmp, ds_name, layer, name ); - - sprintf(layer, "pre_clip_accum_%d_%d", accum_idx, polys_in.get_poly( i, j ).GetId() ); + tgPolygon::ToClipperFile( tmp, ds_name, layer ); + + sprintf(layer, "pre_clip_accum_%d", polys_in.get_poly( i, j ).GetId() ); accum.ToShapefiles( ds_name, layer, false ); + //accum.ToClipperFile( ds_name, layer, false ); } clipped = accum.Diff( tmp ); @@ -163,16 +165,21 @@ bool TGConstruct::ClipLandclassPolys( void ) { } } } - + if ( debug_area || debug_shape ) { + char layer[32]; + sprintf(layer, "pre2_clip_accum_%d", polys_in.get_poly( i, j ).GetId() ); + + accum.ToShapefiles( ds_name, layer, false ); + accum.ToClipperfiles( ds_name, layer, false ); + } accum.Add( tmp ); if ( debug_area || debug_shape ) { char layer[32]; - sprintf(layer, "post_clip_accum_%d_%d", accum_idx, polys_in.get_poly( i, j ).GetId() ); - + sprintf(layer, "post_clip_accum_%d_%d", accum_idx++, polys_in.get_poly( i, j ).GetId() ); + accum.ToShapefiles( ds_name, layer, false ); + accum.ToClipperfiles( ds_name, layer, false ); } - - accum_idx++; } } @@ -197,8 +204,7 @@ bool TGConstruct::ClipLandclassPolys( void ) { slivers.clear(); - if ( debug_shapes.size() ) - { + if ( debug_all || debug_shapes.size() || debug_areas.size() ) { char layer[32]; char name[32]; @@ -206,15 +212,14 @@ bool TGConstruct::ClipLandclassPolys( void ) { sprintf(name, "shape"); tgShapefile::FromPolygon( safety_base, ds_name, layer, name ); - tgPolygon::ToClipperFile( safety_base, ds_name, layer ); + //tgPolygon::ToClipperFile( safety_base, ds_name, layer ); } // finally, what ever is left over goes to ocean remains = accum.Diff( safety_base ); - if ( debug_shapes.size() ) - { - char layer[32]; + if ( debug_all || debug_shapes.size() || debug_areas.size() ) { + char layer[32]; char name[32]; sprintf(layer, "remains_sb" ); @@ -227,9 +232,8 @@ bool TGConstruct::ClipLandclassPolys( void ) { remains = tgPolygon::RemoveDups( remains ); remains = tgPolygon::RemoveCycles( remains ); - if ( debug_shapes.size() ) - { - char layer[32]; + if ( debug_all || debug_shapes.size() || debug_areas.size() ) { + char layer[32]; char name[32]; sprintf(layer, "remains_postclean" ); diff --git a/src/BuildTiles/Main/tgconstruct_output.cxx b/src/BuildTiles/Main/tgconstruct_output.cxx index 7b8a5811..a54bc731 100644 --- a/src/BuildTiles/Main/tgconstruct_output.cxx +++ b/src/BuildTiles/Main/tgconstruct_output.cxx @@ -237,7 +237,10 @@ void TGConstruct::WriteBtgFile( void ) } if (debug_all || debug_shapes.size()) { + lock->lock(); result = obj.write_ascii( base, txtname, bucket ); + lock->unlock(); + if ( !result ) { throw sg_exception("error writing file. :-("); diff --git a/src/Lib/terragear/tg_accumulator.cxx b/src/Lib/terragear/tg_accumulator.cxx index 90e8882a..0adf3c5b 100644 --- a/src/Lib/terragear/tg_accumulator.cxx +++ b/src/Lib/terragear/tg_accumulator.cxx @@ -1,3 +1,7 @@ +#include +#include +#include + #include #include "tg_accumulator.hxx" @@ -128,14 +132,19 @@ void tgAccumulator::Add( const tgContour& subject ) void tgAccumulator::Add( const tgPolygon& subject ) { - for ( unsigned int i = 0; i < subject.Contours(); ++i ) { - for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) { - nodes.add( subject.GetNode(i, j) ); + if ( subject.Contours() ) { + ClipperLib::Paths clipper_subject = tgPolygon::ToClipper( subject ); + + for ( unsigned int i = 0; i < subject.Contours(); ++i ) { + for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) { + nodes.add( subject.GetNode(i, j) ); + } } - } - ClipperLib::Paths clipper_subject = tgPolygon::ToClipper( subject ); - accum.push_back( clipper_subject ); + accum.push_back( clipper_subject ); + } else { + SG_LOG(SG_GENERAL, SG_ALERT, "tgAccumulator::Add() - Adding poly with " << subject.Contours() << " contours " ); + } } void tgAccumulator::ToShapefiles( const std::string& path, const std::string& layer_prefix, bool individual ) @@ -143,22 +152,63 @@ void tgAccumulator::ToShapefiles( const std::string& path, const std::string& la char shapefile[32]; char layer[32]; - if ( individual ) { - for (unsigned int i=0; i < accum.size(); i++) { - sprintf( layer, "%s_%d", layer_prefix.c_str(), i ); - sprintf( shapefile, "accum_%d", i ); - tgShapefile::FromClipper( accum[i], path, layer, std::string(shapefile) ); - } - } else { - ClipperLib::Paths clipper_result; - ClipperLib::Clipper c; - c.Clear(); + if ( accum.size() ) { + if ( individual ) { + for (unsigned int i=0; i < accum.size(); i++) { + sprintf( layer, "%s_%d", layer_prefix.c_str(), i ); + sprintf( shapefile, "accum_%d", i ); + tgShapefile::FromClipper( accum[i], path, layer, std::string(shapefile) ); + } + } else { + ClipperLib::Paths clipper_result; + ClipperLib::Clipper c; + c.Clear(); - for ( unsigned int i=0; i clipper_polygons_list; diff --git a/src/Lib/terragear/tg_misc.cxx b/src/Lib/terragear/tg_misc.cxx index 4f0dd510..79ae0a84 100644 --- a/src/Lib/terragear/tg_misc.cxx +++ b/src/Lib/terragear/tg_misc.cxx @@ -10,8 +10,13 @@ const double isEqual2D_Epsilon = 0.000001; -#define CLIPPER_FIXEDPT (1000000000000) -#define CLIPPER_METERS_PER_DEGREE (111000) +#if 0 +#define CLIPPER_FIXEDPT (1000000000000) +#define CLIPPER_METERS_PER_DEGREE (111000) +#else +#define CLIPPER_FIXEDPT (10000000000000000) +#define CLIPPER_METERS_PER_DEGREE (1110000000) +#endif SGGeod SGGeod_snap( const SGGeod& in, double grid ) { @@ -72,9 +77,18 @@ ClipperLib::IntPoint SGGeod_ToClipper( const SGGeod& p ) { ClipperLib::cUInt x, y; - x = (ClipperLib::cUInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) + 0.5); - y = (ClipperLib::cUInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) + 0.5); - + if ( p.getLongitudeDeg() > 0 ) { + x = (ClipperLib::cUInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) + 0.5 ); + } else { + x = (ClipperLib::cUInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) - 0.5 ); + } + + if ( p.getLatitudeDeg() > 0 ) { + y = (ClipperLib::cUInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) + 0.5 ); + } else { + y = (ClipperLib::cUInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) - 0.5 ); + } + return ClipperLib::IntPoint( x, y ); } diff --git a/src/Lib/terragear/tg_polygon.hxx b/src/Lib/terragear/tg_polygon.hxx index c31e9dfd..7b695ce2 100644 --- a/src/Lib/terragear/tg_polygon.hxx +++ b/src/Lib/terragear/tg_polygon.hxx @@ -405,8 +405,6 @@ public: static tgPolygon FromClipper( const ClipperLib::Paths& subject ); static void ToClipperFile( const tgPolygon& subject, const std::string& path, const std::string& filename ); - static void ToShapefile( const tgPolygon& subject, const std::string& datasource, const std::string& layer, const std::string& feature ); - // T-Junctions and segment search static tgPolygon AddColinearNodes( const tgPolygon& subject, UniqueSGGeodSet& nodes ); static tgPolygon AddColinearNodes( const tgPolygon& subject, std::vector& nodes );