Opened 10 years ago

Closed 7 years ago

#8363 closed Support Requests (worksforme)

Point-wise coordinate transformation?

Reported by: Volker Schöch <vschoech@…> Owned by: Barend Gehrels
Milestone: To Be Determined Component: geometry
Version: Boost 1.52.0 Severity: Cosmetic
Keywords: transform, iterate, foreach Cc: mkaravel

Description

I have asked this question before – about a year ago. Just checking if there is any news in this regard: I would like to be able to apply a functor to every point in a multi-polygon, e.g., in order to transform an int-based polygon into a double-base polygon. This seems to be a canonical operation, like boost::adaptors::transform on ranges, and yet as far as I know there is no algorithm for this in geometry. This is how I currently do it:

reserve( polygon.size() ); // vector of polygons
for( std::vector< _TPolygon< S >::polygon_type >::const_iterator itp=polygon.begin(); itp!=polygon.end(); ++itp ) {
       emplace_back( polygon_type() );
       back().outer().reserve( itp->outer().size() ); // vector of points describing polygon outline
       for( _TPolygon< S >::polygon_type::ring_type::const_iterator itouter=itp->outer().begin(); itouter!=itp->outer().end(); ++itouter ) {
             back().outer().emplace_back( _TPoint< T >(*itouter) );
       }
       back().inners().reserve( itp->inners().size() ); // vector of holes
       for( _TPolygon< S >::polygon_type::inner_container_type::const_iterator itinners=itp->inners().begin(); itinners!=itp->inners().end(); ++itinners ) {
             back().inners().emplace_back( polygon_type::ring_type() );
             back().inners().back().reserve( itinners->size() ); // vector of points describing a hole
             for( _TPolygon< S >::polygon_type::ring_type::const_iterator itinner=itinners->begin(); itinner!=itinners->end(); ++itinner ) {
                    back().inners().back().emplace_back( _TPoint< T >(*itinner) );
             }
       }
}

Is there an algorithm in geometry 1.52.0 that I did not find? Do you plan to add an algorithm for this task at some point?

Change History (6)

comment:1 by mkaravel, 8 years ago

Have you tried using bg::convert? I have not tested it (yet), but for the specific problem you have it might just work.

comment:2 by mkaravel, 8 years ago

Cc: mkaravel added

comment:3 by Volker Schöch <vschoech@…>, 8 years ago

Thank you very much for your comment. Indeed, I can simply replace my code by a call to boost::geometry::convert(...). I tested it for 1.57.0. The ticket can be closed.

comment:4 by mkaravel, 7 years ago

Resolution: invalid
Status: newclosed

comment:5 by mkaravel, 7 years ago

Resolution: invalid
Status: closedreopened

comment:6 by mkaravel, 7 years ago

Resolution: worksforme
Status: reopenedclosed
Note: See TracTickets for help on using tickets.