[Libpqxx-general] Polygon data type in postgres
Jeroen T. Vermeulen
jtv at xs4all.nl
Sun Jul 12 07:21:19 UTC 2009
On Tue, July 7, 2009 09:12, Mark Gabriel Paylaga wrote:
> Thanks for the suggestion. Unfortunately the number of sides of
> the polygon varies so we can't hardcode it like that when doing the
> select...
> If anyone has experience with the postgres polygons using libpqxx, you may
> want
> to share how you retrieved the points?
The best way would be to create a custom data type.
1. Create a C++ class for polygons, or find an existing standard type that
fits the bill.
2. Specialize the string_traits template, found in
include/pqxx/strconv.hxx, for your C++ type. This is where you implement
conversions between your C++ type and the string representation that
postgres uses for polygons.
3. Now use the various templated member functions to read fields, just
like you would for integers or varchars or whatever, but with your polygon
type as the target type. You can also use to_string() to include it in
query text or tablewriter data.
4. Publish your code. :-)
Jeroen
More information about the Libpqxx-general
mailing list