[SOLVED]Re: [postgis-users] WKB format
Paul Ramsey
pramsey at refractions.net
Fri Jul 5 15:02:53 PDT 2002
If you could share the Java code you used to do this, that would be
nice... an obvious next step would be to start to roll high-speed
postgis support into some java toolkits like geotools and openmap.
Paul
David Garnier wrote:
>
> Problem solved. Your initial idea of using binary cursors was correct, the JDBC drivers handle it just fine. I can easily convert theses bytes into native types (bytes and doubles) and access the coordinates of each Point.
>
> I haven't really checked that bytes aren't converted in String somewhere along the way, but I can retrieves 584382 bytes (yes that's half a meg) in 215 ms (I have a fast box but this is still much, much faster than using WKT). Now I'm off working on the WKBReader.
>
> Best Regards,
> David Garnier
>
> On Thu, 04 Jul 2002 14:36:13 -0700
> Paul Ramsey <pramsey at refractions.net> wrote:
>
> > Check out the Connection object the getTypeMap() function. That could be
> > one route. The other route might be via using the SQLData interfaces. I
> > have not done this myself, so I cannot be more specific or give exact
> > answers. My attempted solution was the org.postgis.* objects, which
> > depend on the ascii interfaces and are, as you have noted, not very
> > fast. I am sure a wkb solution is available, just not sure how to access
> > it.
> >
> >
> > David Garnier wrote:
> > >
> > > > OK, poking around a bit in JDBC definitions: the pgsql JDBC driver will
> > > > try and map unknown types (like wkb) into LONGVARCHAR. This is no good
> > > > for you, you want an 8bit representation. Add a custom mapping for the
> > > > wkb type which maps into LONGVARBINARY instead. Then getBytes should
> > > > work better. (http://lab.applinet.nl/postgresql-jdbc/)
> > >
> > > I think that this page says that custom mappings are not supported. This page refers to 7.1, maybe it is supported in 7.2. I see can't see how this is supposed to work, since the query will return an Hex string anyway.
> > >
> > > (My head feels dizzy from reading Postgresql source code, so maybe I just can't see the obvious).
> > >
> > > Could you be a bit more specific (source code for example) about binary cursors and libpq? Postgresql has a a FastPath API that allows the user to call procedures on the backend.
> > >
> > > Best regards,
> > > David Garnier
> > >
> > > > (My query to Dave and Chris remains.)
> > > >
> > > > Paul Ramsey wrote:
> > > > >
> > > > > Poke around some more. My guess is that this problem adheres to the JDBC
> > > > > driver in some manner. We can retrieve WKB directly from binary cursors
> > > > > with no problem via libpq. It could be that pgsql is squashing the
> > > > > results of the WKB query into 7 bits because it is not a known 8bit
> > > > > type, and the cursor is not 8bit. Can you do clean getBytes against
> > > > > bytea types using text cursors?
> > > > > Perhaps Dave/Chris could answer: why are we using a special type (wkb)
> > > > > for the wkb results instead of just a bytea?
> > > > >
> > > > > P.
> > > > >
> > > > > David Garnier wrote:
> > > > > >
> > > > > > OK, I think I get it from reading the source. PostGIS actually parses the binary data into an hexadecimal string and returns it. If I try to read my data with a getString, it looks fine, just like in plsql.
> > > > > >
> > > > > > Now, there is a way to get the real bytes? A byte array that would match the specification of the WKB format? Or are we stuck with Strings till the end of times?
> > > > > >
> > > > > > Best Regards,
> > > > > > David Garnier
> > > > > >
> > > > > > On Thu, 4 Jul 2002 21:24:18 +0200
> > > > > > David Garnier <david.garnier at etudier-online.com> wrote:
> > > > > >
> > > > > > > Hello,
> > > > > > >
> > > > > > > I'm working on this WKBReader in java, and I have some problems getting the data out of postgres. I use the following query:
> > > > > > > select asbinary(the_geom,'NDR') as wkb , astext(the_geom) as wkt from road_shapes limit 25
> > > > > > > Then I do a getBytes on wkb:
> > > > > > > From java I got this: 303130353030303030303031303030303030303130323030303030303033303030303030373532324331353433334641353943303130354130463546323630303434343034324231313533343244464235394330334132313734443032353030343434303734354643453643353746433539433032334639344132303235303034343430
> > > > > > >
> > > > > > > From plsql, I got this:
> > > > > > > 0105000000010000000102000000030000007522C15433FA59C0105A0F5F2600444042B115342DFB59C03A2174D025004440745FCE6C57FC59C023F94A2025004440
> > > > > > >
> > > > > > > I think that there is two problems: the fourth bit of the each byte is set null. That would explain why there is no values above 7.
> > > > > > >
> > > > > > > I'm thinking that this might be related to different encoding schemes between Java and postgres.
> > > > > > >
> > > > > > > I figured that I would just ask around before diving head first into the source code of postgis.
> > > > > > >
> > > > > > > Best Regards,
> > > > > > > David Garnier
> > > > > > >
> > > > > > > _______________________________________________
> > > > > > > postgis-users mailing list
> > > > > > > postgis-users at postgis.refractions.net
> > > > > > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > > > > > >
> > > > > >
> > > > > > _______________________________________________
> > > > > > postgis-users mailing list
> > > > > > postgis-users at postgis.refractions.net
> > > > > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > > > >
> > > > > --
> > > > > __
> > > > > /
> > > > > | Paul Ramsey
> > > > > | Refractions Research
> > > > > | Email: pramsey at refractions.net
> > > > > | Phone: (250) 885-0632
> > > > > \_
> > > > >
> > > > > _______________________________________________
> > > > > postgis-users mailing list
> > > > > postgis-users at postgis.refractions.net
> > > > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > > >
> > > > --
> > > > __
> > > > /
> > > > | Paul Ramsey
> > > > | Refractions Research
> > > > | Email: pramsey at refractions.net
> > > > | Phone: (250) 885-0632
> > > > \_
> > > >
> > > > _______________________________________________
> > > > postgis-users mailing list
> > > > postgis-users at postgis.refractions.net
> > > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > > >
> > >
> > > _______________________________________________
> > > postgis-users mailing list
> > > postgis-users at postgis.refractions.net
> > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
> > --
> > __
> > /
> > | Paul Ramsey
> > | Refractions Research
> > | Email: pramsey at refractions.net
> > | Phone: (250) 885-0632
> > \_
> >
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> >
--
__
/
| Paul Ramsey
| Refractions Research
| Email: pramsey at refractions.net
| Phone: (250) 885-0632
\_
More information about the postgis-users
mailing list