[gdal-dev] PostGIS does not close a ring created by ogr2ogr
even.rouault at spatialys.com
Mon Sep 8 06:55:28 PDT 2014
Selon Jukka Rahkonen <jukka.rahkonen at mmmtike.fi>:
> Anybody interested in biting some bytes of WKB? Thorough description of the
> trouble is in Stackexchange
> User has converted a linestring from dxf format into PostGIS with ogr2ogr.
> By staring at the WKB the linestring seems to make a closing ring with first
> and last vertex having exactly same coordinates which are in binary:
> However, PostGIS claims that the ring is not closed and it can't make a
> polygon with ST_MakePolygon. ST_MakePolygon is successful if WKB is first
> converted into WKT and then back to WKB with PostGIS. There are some
> differences in the beginning of WKB created by ogr2ogr and PostGIS. GDAL
> writes this before the coordinates begin (separates with dashes from where I
> believe to be logical breaks)
> PostGIS version writes different geometry type and WKB is a few bytes
> So GDAL writes "02000020" instead of "02000000" but it also writes bytes
> "B46B0000" which do not have any equivalent it the PostGIS WKB. After these
> bytes WKB seems to be identical.
> I am curious to get an explanation for what happens.
What GDAL writes is EWKB / Extended WKB, which is a PostGIS extension to WKB,
that is nominally used when reading from/writing to PostGIS tables. See
In that instance the final "20" in "02000020" is the SRID flag 0x20000000,
indicating that the next 4 bytes, will be the SRID of the geometry. And
"B46B0000" is 0x00006BB4 = 27572, i.e. EPSG:27572, French Lambert zone II.
As far as the cause of the failure, there's a very slight difference in the
least-signficant byte of the Y component of the first and last vertex. See
(difference outlined between stars) :
Translated into text with st_astext, it is probably unnoticed.
And st_astext/st_geomfromtext return respectively OGC WKT and OGC WKB, loosing
the PostGIS embedded SRID.
> -Jukka Rahkonen-
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
Spatialys - Geospatial professional services
More information about the gdal-dev