additional fix for TNCM - handle western longitude and souther latitude rounding
This commit is contained in:
parent
733f9347ab
commit
c5d6c20998
6 changed files with 114 additions and 44 deletions
|
@ -41,8 +41,8 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
||||||
tgcontour_list slivers;
|
tgcontour_list slivers;
|
||||||
SGGeod p;
|
SGGeod p;
|
||||||
bool debug_area, debug_shape;
|
bool debug_area, debug_shape;
|
||||||
static int accum_idx = 0;
|
|
||||||
tgAccumulator accum;
|
tgAccumulator accum;
|
||||||
|
unsigned int accum_idx = 0;
|
||||||
|
|
||||||
// set up clipping tile : and remember to add the nodes!
|
// set up clipping tile : and remember to add the nodes!
|
||||||
p = bucket.get_corner( SG_BUCKET_SW );
|
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(layer, "pre_clip_%d", polys_in.get_poly( i, j ).GetId() );
|
||||||
sprintf(name, "shape %d,%d", i,j);
|
sprintf(name, "shape %d,%d", i,j);
|
||||||
tgShapefile::FromPolygon( tmp, ds_name, layer, name );
|
tgShapefile::FromPolygon( tmp, ds_name, layer, name );
|
||||||
|
tgPolygon::ToClipperFile( tmp, ds_name, layer );
|
||||||
sprintf(layer, "pre_clip_accum_%d_%d", accum_idx, polys_in.get_poly( i, j ).GetId() );
|
|
||||||
|
sprintf(layer, "pre_clip_accum_%d", polys_in.get_poly( i, j ).GetId() );
|
||||||
accum.ToShapefiles( ds_name, layer, false );
|
accum.ToShapefiles( ds_name, layer, false );
|
||||||
|
//accum.ToClipperFile( ds_name, layer, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
clipped = accum.Diff( tmp );
|
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 );
|
accum.Add( tmp );
|
||||||
if ( debug_area || debug_shape ) {
|
if ( debug_area || debug_shape ) {
|
||||||
char layer[32];
|
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.ToShapefiles( ds_name, layer, false );
|
||||||
|
accum.ToClipperfiles( ds_name, layer, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
accum_idx++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,8 +204,7 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
||||||
|
|
||||||
slivers.clear();
|
slivers.clear();
|
||||||
|
|
||||||
if ( debug_shapes.size() )
|
if ( debug_all || debug_shapes.size() || debug_areas.size() ) {
|
||||||
{
|
|
||||||
char layer[32];
|
char layer[32];
|
||||||
char name[32];
|
char name[32];
|
||||||
|
|
||||||
|
@ -206,15 +212,14 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
||||||
sprintf(name, "shape");
|
sprintf(name, "shape");
|
||||||
|
|
||||||
tgShapefile::FromPolygon( safety_base, ds_name, layer, name );
|
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
|
// finally, what ever is left over goes to ocean
|
||||||
remains = accum.Diff( safety_base );
|
remains = accum.Diff( safety_base );
|
||||||
|
|
||||||
if ( debug_shapes.size() )
|
if ( debug_all || debug_shapes.size() || debug_areas.size() ) {
|
||||||
{
|
char layer[32];
|
||||||
char layer[32];
|
|
||||||
char name[32];
|
char name[32];
|
||||||
|
|
||||||
sprintf(layer, "remains_sb" );
|
sprintf(layer, "remains_sb" );
|
||||||
|
@ -227,9 +232,8 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
||||||
remains = tgPolygon::RemoveDups( remains );
|
remains = tgPolygon::RemoveDups( remains );
|
||||||
remains = tgPolygon::RemoveCycles( remains );
|
remains = tgPolygon::RemoveCycles( remains );
|
||||||
|
|
||||||
if ( debug_shapes.size() )
|
if ( debug_all || debug_shapes.size() || debug_areas.size() ) {
|
||||||
{
|
char layer[32];
|
||||||
char layer[32];
|
|
||||||
char name[32];
|
char name[32];
|
||||||
|
|
||||||
sprintf(layer, "remains_postclean" );
|
sprintf(layer, "remains_postclean" );
|
||||||
|
|
|
@ -237,7 +237,10 @@ void TGConstruct::WriteBtgFile( void )
|
||||||
}
|
}
|
||||||
if (debug_all || debug_shapes.size())
|
if (debug_all || debug_shapes.size())
|
||||||
{
|
{
|
||||||
|
lock->lock();
|
||||||
result = obj.write_ascii( base, txtname, bucket );
|
result = obj.write_ascii( base, txtname, bucket );
|
||||||
|
lock->unlock();
|
||||||
|
|
||||||
if ( !result )
|
if ( !result )
|
||||||
{
|
{
|
||||||
throw sg_exception("error writing file. :-(");
|
throw sg_exception("error writing file. :-(");
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
|
||||||
#include "tg_accumulator.hxx"
|
#include "tg_accumulator.hxx"
|
||||||
|
@ -128,14 +132,19 @@ void tgAccumulator::Add( const tgContour& subject )
|
||||||
|
|
||||||
void tgAccumulator::Add( const tgPolygon& subject )
|
void tgAccumulator::Add( const tgPolygon& subject )
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < subject.Contours(); ++i ) {
|
if ( subject.Contours() ) {
|
||||||
for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) {
|
ClipperLib::Paths clipper_subject = tgPolygon::ToClipper( subject );
|
||||||
nodes.add( subject.GetNode(i, j) );
|
|
||||||
|
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 )
|
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 shapefile[32];
|
||||||
char layer[32];
|
char layer[32];
|
||||||
|
|
||||||
if ( individual ) {
|
if ( accum.size() ) {
|
||||||
for (unsigned int i=0; i < accum.size(); i++) {
|
if ( individual ) {
|
||||||
sprintf( layer, "%s_%d", layer_prefix.c_str(), i );
|
for (unsigned int i=0; i < accum.size(); i++) {
|
||||||
sprintf( shapefile, "accum_%d", i );
|
sprintf( layer, "%s_%d", layer_prefix.c_str(), i );
|
||||||
tgShapefile::FromClipper( accum[i], path, layer, std::string(shapefile) );
|
sprintf( shapefile, "accum_%d", i );
|
||||||
}
|
tgShapefile::FromClipper( accum[i], path, layer, std::string(shapefile) );
|
||||||
} else {
|
}
|
||||||
ClipperLib::Paths clipper_result;
|
} else {
|
||||||
ClipperLib::Clipper c;
|
ClipperLib::Paths clipper_result;
|
||||||
c.Clear();
|
ClipperLib::Clipper c;
|
||||||
|
c.Clear();
|
||||||
|
|
||||||
for ( unsigned int i=0; i<accum.size(); i++ ) {
|
for ( unsigned int i=0; i<accum.size(); i++ ) {
|
||||||
c.AddPaths(accum[i], ClipperLib::ptSubject, true);
|
c.AddPaths(accum[i], ClipperLib::ptSubject, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( c.Execute( ClipperLib::ctUnion, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
|
||||||
|
tgShapefile::FromClipper( clipper_result, path, layer_prefix, "accum" );
|
||||||
|
} else {
|
||||||
|
SG_LOG(SG_GENERAL, SG_ALERT, "Clipper Failure in tgAccumulator::ToShapefiles()" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Execute( ClipperLib::ctUnion, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tgShapefile::FromClipper( clipper_result, path, layer_prefix, "accum" );
|
void tgAccumulator::ToClipperfiles( const std::string& path, const std::string& layer_prefix, bool individual )
|
||||||
|
{
|
||||||
|
std::ofstream file;
|
||||||
|
char filename[256];
|
||||||
|
|
||||||
|
if ( accum.size() ) {
|
||||||
|
if ( individual ) {
|
||||||
|
for (unsigned int i=0; i < accum.size(); i++) {
|
||||||
|
sprintf( filename, "%s/%s_%d", path.c_str(), layer_prefix.c_str(), i );
|
||||||
|
|
||||||
|
file.open (filename);
|
||||||
|
file << accum[i];
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ClipperLib::Paths clipper_result;
|
||||||
|
ClipperLib::Clipper c;
|
||||||
|
c.Clear();
|
||||||
|
|
||||||
|
for ( unsigned int i=0; i<accum.size(); i++ ) {
|
||||||
|
c.AddPaths(accum[i], ClipperLib::ptSubject, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( c.Execute( ClipperLib::ctUnion, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
|
||||||
|
sprintf( filename, "%s/%s", path.c_str(), layer_prefix.c_str() );
|
||||||
|
|
||||||
|
file.open (filename);
|
||||||
|
file << clipper_result;
|
||||||
|
file.close();
|
||||||
|
} else {
|
||||||
|
SG_LOG(SG_GENERAL, SG_ALERT, "Clipper Failure in tgAccumulator::ToClipperFiles()" );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@ public:
|
||||||
void Add( const tgPolygon& subject );
|
void Add( const tgPolygon& subject );
|
||||||
|
|
||||||
void ToShapefiles( const std::string& path, const std::string& layer, bool individual );
|
void ToShapefiles( const std::string& path, const std::string& layer, bool individual );
|
||||||
|
void ToClipperfiles( const std::string& path, const std::string& layer_prefix, bool individual );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector < ClipperLib::Paths > clipper_polygons_list;
|
typedef std::vector < ClipperLib::Paths > clipper_polygons_list;
|
||||||
|
|
|
@ -10,8 +10,13 @@
|
||||||
|
|
||||||
const double isEqual2D_Epsilon = 0.000001;
|
const double isEqual2D_Epsilon = 0.000001;
|
||||||
|
|
||||||
#define CLIPPER_FIXEDPT (1000000000000)
|
#if 0
|
||||||
#define CLIPPER_METERS_PER_DEGREE (111000)
|
#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 )
|
SGGeod SGGeod_snap( const SGGeod& in, double grid )
|
||||||
{
|
{
|
||||||
|
@ -72,9 +77,18 @@ ClipperLib::IntPoint SGGeod_ToClipper( const SGGeod& p )
|
||||||
{
|
{
|
||||||
ClipperLib::cUInt x, y;
|
ClipperLib::cUInt x, y;
|
||||||
|
|
||||||
x = (ClipperLib::cUInt)( (p.getLongitudeDeg() * CLIPPER_FIXEDPT) + 0.5);
|
if ( p.getLongitudeDeg() > 0 ) {
|
||||||
y = (ClipperLib::cUInt)( (p.getLatitudeDeg() * CLIPPER_FIXEDPT) + 0.5);
|
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 );
|
return ClipperLib::IntPoint( x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -405,8 +405,6 @@ public:
|
||||||
static tgPolygon FromClipper( const ClipperLib::Paths& subject );
|
static tgPolygon FromClipper( const ClipperLib::Paths& subject );
|
||||||
static void ToClipperFile( const tgPolygon& subject, const std::string& path, const std::string& filename );
|
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
|
// T-Junctions and segment search
|
||||||
static tgPolygon AddColinearNodes( const tgPolygon& subject, UniqueSGGeodSet& nodes );
|
static tgPolygon AddColinearNodes( const tgPolygon& subject, UniqueSGGeodSet& nodes );
|
||||||
static tgPolygon AddColinearNodes( const tgPolygon& subject, std::vector<SGGeod>& nodes );
|
static tgPolygon AddColinearNodes( const tgPolygon& subject, std::vector<SGGeod>& nodes );
|
||||||
|
|
Loading…
Reference in a new issue