[Libpqxx-general] Polygon data type in postgres

Mark Gabriel Paylaga mpaylaga at gmail.com
Fri Jul 10 06:38:33 UTC 2009


For the meantime I'll just parse the retrieved string of points...

            typedef boost::tokenizer<boost::char_separator<char> >
            tokenizer;
            boost::char_separator<char> sep(",()");
            tokenizer tokens(str_coordinates, sep);
            for (tokenizer::iterator tok_iter = tokens.begin();
                       tok_iter != tokens.end(); ++tok_iter)
            {
                std::cout << "<" << *tok_iter << "> ";
                ++tok_iter;
                std::cout << "<" << *tok_iter << "> " << endl;
            }


On Tue, Jul 7, 2009 at 2:29 PM, Mark Gabriel Paylaga <mpaylaga at gmail.com>wrote:

>
>
> ---------- Forwarded message ----------
> From: Mark Gabriel Paylaga <mpaylaga at gmail.com>
> Date: Tue, Jul 7, 2009 at 10:12 AM
> Subject: Re: [Libpqxx-general] Polygon data type in postgres
> To: Scott Gifford <sgifford at suspectclass.com>,
> libpqxx-general at pgfoundry.org
>
>
> Hello Scott,
>
> 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?
>
> Thanks and best regards,
> mark
>
> On Mon, Jul 6, 2009 at 11:22 PM, Scott Gifford <sgifford at suspectclass.com>wrote:
>
>> Mark Gabriel Paylaga <mpaylaga at gmail.com> writes:
>>
>> > I'm trying to retrieve the points of a polygon that are stored in the
>> postgres
>> > db.
>> > The contents of the db are:
>> >  polygonid |
>> > vertices
>> >
>> -----------+---------------------------------------------------------------------
>> >          2 |
>> ((1,0),(1.5,-1),(2,-1),(2,1),(1,1),(0,0),(0,2),(3,2),(3,-2),
>> > (1,-2))
>> >          4 | ((3,3),(4,4),(5,5))
>>
>> >
>> > The vertices column is of type Polygon.
>>
>> Mark,
>>
>> I had a similar problem with accessing geo-spatial fields, and I
>> solved it by selecting the individual parts of the fields.  For
>> example, we were storing some line segments and also a time range as a
>> segment type, and I used SQL like this:
>>
>>    SELECT objid, (time[0])[0] AS etime, (time[1])[0] AS stime,
>>           (seg[0])[0] AS segupper_x, (seg[0])[1] AS segupper_y,
>>           (seg[1])[0] AS seglower_x, (seg[1])[1] AS seglower_y
>>
>> Then we could access the fields using their assigne names with normal
>> libpqxx syntax.
>>
>> Not sure if that will work for polygon or not; probably it will depend
>> on whether you know how many sides there are.
>>
>> It would definitely be nice if libpqxx offered better support for this
>> (maybe it does and I just couldn't figure it out).
>>
>> ----Scott.
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pgfoundry.org/pipermail/libpqxx-general/attachments/20090710/13b92f49/attachment.html>


More information about the Libpqxx-general mailing list