[postgis-users] WKB to native geometry using BULK COPY
dblasby at refractions.net
Wed Mar 24 09:38:15 PST 2004
Ryan Proulx wrote:
> Any thoughts on this yet? Or is this just a really stupid question? I am open to suggestions on how to make transfering data in and out of PostGIS easier.
> -----Original Message-----
> From: Ryan Proulx
> Sent: March 4, 2004 16:02
> To: PostGISUserGroup (E-mail)
> Subject: [postgis-users] WKB to native geometry using BULK COPY
> I am curious how I can use the COPY commands to insert literal geometry data. Currently this works with WKT by specifying the geometry as:
> However, I would like to do the same thing using WKB. Any ideas on how that might successfully be done?
> It seems I will have to get an SRID and a WKB geometry, in hex preferably, and combine the two to form a single hex literal to be inserted directly into a column of type GEOMETRY.
> When I am using single INSERT statements instead of the COPY commands I use the 'geomfromwkb' function to combine the SRID and WKB hex string, so I guess what I really need to know is how this is accomplished and likely what the native underlying geometry looks like.
Dont try to directly create a GEOMETRY object outside the database -
you're almost certainly going to give yourself nightmares!
Currently, postgis allows the "srid=<srid>;<wkt>" for input to the
"normal" creation function ("geometry_in()").
You could modify the PostGIS geometry_in() function so that it could
tell the difference between "srid=<srid>;<wkt>" and say
get SRID (-1 if not present)
grab the hex WKB portion of the input string
convert hex WKB string to an actual WKB type (WKB_in())
convert the WKB to GEOMETRY (geometry_from_wkb())
set the SRID on the new GEOMETRY (setSRID())
return the GEOMETRY;
ELSE <is WKT>
... as before ...
More information about the postgis-users