Selon Jukka Rahkonen <[email protected]>: > Hi, > > Anybody interested in biting some bytes of WKB? Thorough description of the > trouble is in Stackexchange > http://gis.stackexchange.com/questions/113029/polygon-from-line-creation-problem > > Summary: > 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: > D89E591A2DD4284123D92354DF65F440 > 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) > 01-02000020-B46B0000-7D000000 > > PostGIS version writes different geometry type and WKB is a few bytes > shorter: > 01-02000000-7D000000 > > 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.
Jukka, 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 http://postgis.net/docs/using_postgis_dbmanagement.html#EWKB_EWKT 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) : D89E591A2DD428412*3*D92354DF65F440 D89E591A2DD428412*1*D92354DF65F440 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. Even > > -Jukka Rahkonen- > > > > > > > _______________________________________________ > gdal-dev mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/gdal-dev > -- Spatialys - Geospatial professional services http://www.spatialys.com _______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
