1
0
Fork 0

finally fixed the crazy valleys / ridges

- issue is caused by very long edges.  osm_coastline has lots of them.
- split_long_edges info was getting lost in many cases, as clipper
  'optimizes' the output.  To work around this, I would gather the
  nodes before a clip, then add them back after.  Unfortunately, I was
  only getting one of the polygons nodes
  ( sometimes, just a bucket - 4 nodes )
This commit is contained in:
Peter Sadrozinski 2013-08-17 10:52:31 -04:00
parent 9d4f65f766
commit d71aacde76
6 changed files with 105 additions and 48 deletions

View file

@ -14,6 +14,10 @@ tgPolygon tgAccumulator::Diff( const tgContour& subject )
all_nodes.add( subject.GetNode(i) );
}
for ( unsigned int i = 0; i < nodes.size(); i++ ) {
all_nodes.add( nodes[i] );
}
unsigned int num_hits = 0;
tgRectangle box1 = subject.GetBoundingBox();
@ -50,40 +54,6 @@ tgPolygon tgAccumulator::Diff( const tgContour& subject )
return result;
}
void tgAccumulator::Add( const tgContour& subject )
{
tgPolygon poly;
poly.AddContour( subject );
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( poly );
accum.push_back( clipper_subject );
}
void tgAccumulator::ToShapefiles( const std::string& path, const std::string& layer_prefix, bool individual )
{
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::Polygons clipper_result;
ClipperLib::Clipper c;
c.Clear();
for ( unsigned int i=0; i<accum.size(); i++ ) {
c.AddPolygons(accum[i], ClipperLib::ptSubject);
}
c.Execute( ClipperLib::ctUnion, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
tgShapefile::FromClipper( clipper_result, path, layer_prefix, "accum" );
}
}
tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
{
tgPolygon result;
@ -96,6 +66,10 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
}
}
for ( unsigned int i = 0; i < nodes.size(); i++ ) {
all_nodes.add( nodes[i] );
}
unsigned int num_hits = 0;
tgRectangle box1 = subject.GetBoundingBox();
@ -137,8 +111,54 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
return result;
}
void tgAccumulator::Add( const tgContour& subject )
{
tgPolygon poly;
// Add the nodes
for ( unsigned int i = 0; i < subject.GetSize(); ++i ) {
nodes.add( subject.GetNode(i) );
}
poly.AddContour( subject );
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( poly );
accum.push_back( clipper_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) );
}
}
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
accum.push_back( clipper_subject );
}
void tgAccumulator::ToShapefiles( const std::string& path, const std::string& layer_prefix, bool individual )
{
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::Polygons clipper_result;
ClipperLib::Clipper c;
c.Clear();
for ( unsigned int i=0; i<accum.size(); i++ ) {
c.AddPolygons(accum[i], ClipperLib::ptSubject);
}
c.Execute( ClipperLib::ctUnion, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
tgShapefile::FromClipper( clipper_result, path, layer_prefix, "accum" );
}
}

View file

@ -20,6 +20,7 @@ private:
typedef std::vector < ClipperLib::Polygons > clipper_polygons_list;
clipper_polygons_list accum;
UniqueSGGeodSet nodes;
};
#endif // _TGACCUMULATOR_HXX

View file

@ -45,7 +45,7 @@ tgPolygon tgChopper::Clip( const tgPolygon& subject,
base.AddNode( 0, SGGeod::fromDeg( max.getLongitudeDeg(), max.getLatitudeDeg()) );
base.AddNode( 0, SGGeod::fromDeg( min.getLongitudeDeg(), max.getLatitudeDeg()) );
result = tgPolygon::Intersect( base, subject );
result = tgPolygon::Intersect( subject, base );
if ( result.Contours() > 0 ) {
if ( subject.GetPreserve3D() ) {
result.InheritElevations( subject );
@ -138,21 +138,21 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type )
clip_row.AddNode( 0, SGGeod::fromDeg( 180.0, clip_top) );
clip_row.AddNode( 0, SGGeod::fromDeg(-180.0, clip_top) );
clipped = tgPolygon::Intersect( clip_row, subject );
clipped = tgPolygon::Intersect( subject, clip_row );
if ( clipped.TotalNodes() > 0 ) {
if ( subject.GetPreserve3D() ) {
clipped.InheritElevations( subject );
clipped.SetPreserve3D( true );
}
clipped.SetTexParams( subject.GetTexParams() );
if ( subject.GetTexMethod() == TG_TEX_BY_GEODE ) {
// need to set center latitude for geodetic texturing
clipped.SetTexMethod( TG_TEX_BY_GEODE, b_clip.get_center_lat() );
}
clipped.SetFlag(type);
if ( subject.GetPreserve3D() ) {
clipped.InheritElevations( subject );
clipped.SetPreserve3D( true );
}
clipped.SetTexParams( subject.GetTexParams() );
if ( subject.GetTexMethod() == TG_TEX_BY_GEODE ) {
// need to set center latitude for geodetic texturing
clipped.SetTexMethod( TG_TEX_BY_GEODE, b_clip.get_center_lat() );
}
clipped.SetFlag(type);
ClipRow( clipped, b_clip.get_center_lat(), type );
ClipRow( clipped, b_clip.get_center_lat(), type );
#if 0
{

View file

@ -456,6 +456,12 @@ tgPolygon tgContour::Union( const tgContour& subject, tgPolygon& clip )
all_nodes.add( subject.GetNode(i) );
}
for ( unsigned int i = 0; i < clip.Contours(); ++i ) {
for ( unsigned int j = 0; j < clip.ContourSize( i ); ++j ) {
all_nodes.add( clip.GetNode(i, j) );
}
}
ClipperLib::Polygon clipper_subject = tgContour::ToClipper( subject );
ClipperLib::Polygons clipper_clip = tgPolygon::ToClipper( clip );
ClipperLib::Polygons clipper_result;
@ -482,6 +488,12 @@ tgPolygon tgContour::Diff( const tgContour& subject, tgPolygon& clip )
all_nodes.add( subject.GetNode(i) );
}
for ( unsigned int i = 0; i < clip.Contours(); ++i ) {
for ( unsigned int j = 0; j < clip.ContourSize( i ); ++j ) {
all_nodes.add( clip.GetNode(i, j) );
}
}
ClipperLib::Polygon clipper_subject = tgContour::ToClipper( subject );
ClipperLib::Polygons clipper_clip = tgPolygon::ToClipper( clip );
ClipperLib::Polygons clipper_result;
@ -508,6 +520,10 @@ tgPolygon tgContour::Intersect( const tgContour& subject, const tgContour& clip
all_nodes.add( subject.GetNode(i) );
}
for ( unsigned int i = 0; i < clip.GetSize(); ++i ) {
all_nodes.add( clip.GetNode(i) );
}
ClipperLib::Polygon clipper_subject = tgContour::ToClipper( subject );
ClipperLib::Polygon clipper_clip = tgContour::ToClipper( clip );
ClipperLib::Polygons clipper_result;

View file

@ -24,6 +24,12 @@ tgPolygon tgPolygon::Union( const tgPolygon& subject, tgPolygon& clip )
}
}
for ( unsigned int i = 0; i < clip.Contours(); ++i ) {
for ( unsigned int j = 0; j < clip.ContourSize( i ); ++j ) {
all_nodes.add( clip.GetNode(i, j) );
}
}
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
ClipperLib::Polygons clipper_clip = tgPolygon::ToClipper( clip );
ClipperLib::Polygons clipper_result;
@ -100,6 +106,12 @@ tgPolygon tgPolygon::Diff( const tgPolygon& subject, tgPolygon& clip )
}
}
for ( unsigned int i = 0; i < clip.Contours(); ++i ) {
for ( unsigned int j = 0; j < clip.ContourSize( i ); ++j ) {
all_nodes.add( clip.GetNode(i, j) );
}
}
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
ClipperLib::Polygons clipper_clip = tgPolygon::ToClipper( clip );
ClipperLib::Polygons clipper_result;
@ -131,6 +143,12 @@ tgPolygon tgPolygon::Intersect( const tgPolygon& subject, const tgPolygon& clip
}
}
for ( unsigned int i = 0; i < clip.Contours(); ++i ) {
for ( unsigned int j = 0; j < clip.ContourSize( i ); ++j ) {
all_nodes.add( clip.GetNode(i, j) );
}
}
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
ClipperLib::Polygons clipper_clip = tgPolygon::ToClipper( clip );
ClipperLib::Polygons clipper_result;

View file

@ -128,6 +128,8 @@ void tgPolygon::Tesselate( const std::vector<SGGeod>& extra )
tg_insert_polygon(cdt, poly);
}
/* make conforming - still has an issue, and can't be compiled with exact_construction kernel */
// CGAL::make_conforming_Delaunay_2( cdt );
tg_mark_domains( cdt );