[Geometry] please help; using buffer() extensions
(sorry another post; someone told me to put [library name] in [] in subject... learning something new every day :) Something of a repost, but I've learned a bit more on the path to being truly confused. It appears that boost\geometry\extensions\algorithms\buffer\buffer_inserter.hpp contains some specializations for buffering other shape types? But I'm out of my depth here... is there an example? What do I need to do in order to buffer: a point? A linestring? A vector of polygons? A heterogeneous collections of shapes? Is this generalization of buffer also going to work as a "deflate" for polygons? If someone can tell me "include these headers, use these algorithms", it will help a lot! Thanks John
Hi John, On 25-2-2013 20:38, John Lilley wrote:
(sorry another post; someone told me to put [library name] in [] in subject... learning something new every day J
Something of a repost, but I've learned a bit more on the path to being truly confused. It appears that boost\geometry\extensions\algorithms\buffer\buffer_inserter.hpp contains some specializations for buffering other shape types? But I'm out of my depth here... is there an example?
Not in the examples folder or the docs, but the test contains lots of examples. Well, they all do the same thing, so what is done is this: join_miter < point_type, typename bg::point_type<GeometryOut>::type > join_strategy; typedef bg::strategy::buffer::distance_assymetric<double> distance_strategy_type; distance_strategy_type distance_strategy(distance_left, distance_right); std::vector<GeometryOut> buffered; bg::buffer_inserter<GeometryOut>(geometry, std::back_inserter(buffered), distance_strategy, join_strategy);
What do I need to do in order to buffer:
a point?
Not possible yet.
A linestring?
See above.
A vector of polygons?
If you mean a multipolygon: see above.
A heterogeneous collections of shapes?
Not possible yet.
Is this generalization of buffer also going to work as a "deflate" for polygons?
Yes, the distance may be positive and negative. A negative distance will result in a deflate.
If someone can tell me "include these headers, use these algorithms", it will help a lot!
I'll try to come with a more up to date example, now that the buffer is a hot topic again. Regards, Barend
Not in the examples folder or the docs, but the test contains lots of examples. Well, they all do the same thing, so what is done is this: join_miter < point_type, typename bg::point_type<GeometryOut>::type > join_strategy;
typedef bg::strategy::buffer::distance_assymetric<double> distance_strategy_type; distance_strategy_type distance_strategy(distance_left, distance_right); std::vector<GeometryOut> buffered; bg::buffer_inserter<GeometryOut>(geometry, std::back_inserter(buffered), distance_strategy, join_strategy);
Thanks Barend! I think I am almost there, but there is a kink that I am trying to work out. If I have coordinates expressed in degrees longitude/latitude, can I operate directly on those coordinates without first transforming them to a "flat" projection like UTM? It is easy enough to get meters/degree latitude, but longitudinal distortion is another matter. Does the distance_strategy have anything to do with this? I can accept a first-order model that assumes meters/degree-longitude is constant over the entire shape. Thanks, John
On 27-2-2013 22:13, John Lilley wrote:
Thanks Barend! I think I am almost there, but there is a kink that I am trying to work out. If I have coordinates expressed in degrees longitude/latitude, can I operate directly on those coordinates without first transforming them to a "flat" projection like UTM? It is easy enough to get meters/degree latitude, but longitudinal distortion is another matter. Does the distance_strategy have anything to do with this? I can accept a first-order model that assumes meters/degree-longitude is constant over the entire shape.
Hi John, list,
As promised today, below the example. W.r.t. coordinates, the buffer
operation uses intersections etc internally, and they are not yet ported
to latlong. So you might use it but you will indeed get distortions
then. So yes, the best is to transform first to a cartesian system...
The distance_strategy cannot fix this.
A few changes has been committed today so please update if necessary.
I mentioned that negative buffers (for deflate) are possible - that is
currently not running, I will come back to this.
But it is possible to use assymetric buffers (on linestrings). As
join-strategies you can use "join_round" (like below) and "join_miter"
(with sharp corners).
Regards, Barend
// Complete example, using Boost.Geometry extension for buffer (not yet
released), buffering a polygon:
#include
On 27-2-2013 22:13, John Lilley wrote:
Thanks Barend! I think I am almost there, but there is a kink that I am trying to work out. If I have coordinates expressed in degrees longitude/latitude, can I operate directly on those coordinates without first transforming >>them to a "flat" projection like UTM? It is easy enough to get meters/degree latitude, but longitudinal distortion is another matter. Does the distance_strategy have anything to do with this? I can accept a first-order >>model that assumes meters/degree-longitude is constant over the entire shape.
Hi John, list, As promised today, below the example. W.r.t. coordinates, the buffer operation uses intersections etc internally, and they are not yet ported to latlong. So you might use it but you will indeed get distortions then. So yes, the >best is to transform first to a cartesian system... The distance_strategy cannot fix this.
Thanks, I think that I can deal with the flattening projections.
However, I am having compiler trouble with linestring and multi_linestring:
// definitions
namespace BGNS = boost::geometry;
namespace BGBUFNS = BGNS::strategy::buffer;
typedef BGNS::model::d2::point_xy<double> BoostPoint;
typedef BGNS::model::multi_point<BoostPoint> BoostMultiPoint;
typedef BGNS::model::polygon<BoostPoint> BoostPolygon;
typedef BGNS::model::linestring<BoostPoint> BoostPolyline;
typedef BGNS::model::multi_polygon<BoostPolygon> BoostMultiPolygon;
typedef BGNS::model::multi_linestring<BoostPolyline> BoostMultiPolyline;
typedef BGBUFNS::join_miter
Hi again,
Thanks, I think that I can deal with the flattening projections.
However, I am having compiler trouble with linestring and multi_linestring:
I'm afraid multi-linestring is not yet working. I did not include In the list. Will look at that soon. Also, will give more details about chord length. Not today though. Regards, Barend Sent from iPad. Barend Gehrels www.barendgehrels.nl
int main() { typedef boost::geometry::model::d2::point_xy<double> point_type; typedef boost::geometry::model::polygon
polygon; // Polygon { polygon my_polygon; boost::geometry::read_wkt("POLYGON ((0 0,0 5,4 5,4 4,3 3,2 4,2 1,3 2,4 1,4 0,0 0))", my_polygon); boost::geometry::model::multi_polygon<polygon> my_output; boost::geometry::buffer_inserter<polygon> ( my_polygon, std::back_inserter(my_output), boost::geometry::strategy::buffer::distance_assymetric<double>(0.4, 0.4), boost::geometry::strategy::buffer::join_round
() ); std::cout << "Input polygon, area: " << boost::geometry::area(my_polygon) << std::endl; std::cout << "Output, area: " << boost::geometry::area(my_output) << std::endl;
}
return 0; }
Barend,
When I compile your example, I get errors from MSVC++ 2010. I have the latest extensions, but I am using them with the 1.52 release; will that cause problems?
John
1>------ Build started: Project: etl6_EngCore, Configuration: Debug x64 ------
1> DL_GeometryBasics.cpp
1>F:\DataManagement\RPDM\Server\libraries\boost\boost/geometry/extensions/algorithms/buffer/buffered_piece_collection.hpp(1112): warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data
1> F:\DataManagement\RPDM\Server\libraries\boost\boost/geometry/extensions/algorithms/buffer/buffered_piece_collection.hpp(1111) : while compiling class template member function 'void boost::geometry::detail::buffer::buffered_piece_collection<Ring>::start_new_ring(void)'
1> with
1> [
1> Ring=boost::geometry::model::ring
Hi John,
Barend, When I compile your example, I get errors from MSVC++ 2010. I have the latest extensions, but I am using them with the 1.52 release; will that cause problems? John
I see:
========== Build: 1 succeeded, 0 failed, 0 up-to-date,
There are some warnings, but the build seems to succeed :-) Regards, Barend
participants (2)
-
Barend Gehrels
-
John Lilley