<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SqlGeometry and POINT EMPTY in WKB</title>
	<atom:link href="http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/feed/" rel="self" type="application/rss+xml" />
	<link>http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/</link>
	<description>mloskot&#039;s life, programming, c++, geo and adventures</description>
	<lastBuildDate>Tue, 24 Jan 2012 22:38:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: mloskot</title>
		<link>http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/comment-page-1/#comment-2621</link>
		<dc:creator>mloskot</dc:creator>
		<pubDate>Wed, 03 Mar 2010 16:07:29 +0000</pubDate>
		<guid isPermaLink="false">http://mateusz.loskot.net/?p=1914#comment-2621</guid>
		<description>Paul,

I agree with you. The geometry collection trick is far from ideal. However, with I&#039;m rather having in mind problems that may occur trying to parse truncated WKB of POINT EMPTY while having no flag indicating if it&#039;s empty or not:

&lt;pre&gt;010100000000000000&lt;/pre&gt;

I mean, this would be a serious issue for C/C++ and similar languages.</description>
		<content:encoded><![CDATA[<p>Paul,</p>
<p>I agree with you. The geometry collection trick is far from ideal. However, with I&#8217;m rather having in mind problems that may occur trying to parse truncated WKB of POINT EMPTY while having no flag indicating if it&#8217;s empty or not:</p>
<pre>010100000000000000</pre>
<p>I mean, this would be a serious issue for C/C++ and similar languages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Ramsey</title>
		<link>http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/comment-page-1/#comment-2619</link>
		<dc:creator>Paul Ramsey</dc:creator>
		<pubDate>Wed, 03 Mar 2010 01:25:59 +0000</pubDate>
		<guid isPermaLink="false">http://mateusz.loskot.net/?p=1914#comment-2619</guid>
		<description>I don&#039;t really agree that pushing all empties down into a geometry collection is so wise. Practically, it means we are making our data less expressive as we transit WKB. Typed empties exist, they are in the spec, and our functions can emit them, so we should express them. I just wish there was some way to express POINT EMPTY. Oh, and I wish the ISO SQL/MM spec didn&#039;t contradict the implementation facts on the ground.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t really agree that pushing all empties down into a geometry collection is so wise. Practically, it means we are making our data less expressive as we transit WKB. Typed empties exist, they are in the spec, and our functions can emit them, so we should express them. I just wish there was some way to express POINT EMPTY. Oh, and I wish the ISO SQL/MM spec didn&#8217;t contradict the implementation facts on the ground.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GIS-Lab Blog&#187; ????? ????? &#187; ??????? ?????? 40</title>
		<link>http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/comment-page-1/#comment-2617</link>
		<dc:creator>GIS-Lab Blog&#187; ????? ????? &#187; ??????? ?????? 40</dc:creator>
		<pubDate>Tue, 02 Mar 2010 12:09:58 +0000</pubDate>
		<guid isPermaLink="false">http://mateusz.loskot.net/?p=1914#comment-2617</guid>
		<description>[...] ??? ???????? &#171;?????? ?????????&#187; ? ???????? WKB. [...]</description>
		<content:encoded><![CDATA[<p>[...] ??? ???????? &laquo;?????? ?????????&raquo; ? ???????? WKB. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mloskot</title>
		<link>http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/comment-page-1/#comment-2612</link>
		<dc:creator>mloskot</dc:creator>
		<pubDate>Sat, 27 Feb 2010 14:19:51 +0000</pubDate>
		<guid isPermaLink="false">http://mateusz.loskot.net/?p=1914#comment-2612</guid>
		<description>Even, of course it would be a security issue if POINT EMPTY is truncated to 9 bytes, especially in languages as C or C++. And I have pointed out this problem. However, a consistent approach is needed and in my personal opinion PostGIS approach is the most reasonable. User learns that for every EMPTY geometry he can expect empty collection, so his code can become more generic, without checking a type, just checking size component and performing zero iteration over the bytes stream.

Shortly, IMO, all &lt;type&gt; EMPTY should evaluate to 

&lt;pre&gt;010700000000000000&lt;/pre&gt;

Back to OGR. It&#039;s a bad idea to report &lt;code&gt;POINT(0 0)&lt;/code&gt; for &lt;code&gt;POINT EMPTY&lt;/code&gt; and it is actually invalid as these two geometries are not equivalent. The former is non-empty valid point of both coordinates of Zero, the latter is valid geometry with no coordinates initialized. I&#039;m sure you get my point.&lt;/type&gt;</description>
		<content:encoded><![CDATA[<p>Even, of course it would be a security issue if POINT EMPTY is truncated to 9 bytes, especially in languages as C or C++. And I have pointed out this problem. However, a consistent approach is needed and in my personal opinion PostGIS approach is the most reasonable. User learns that for every EMPTY geometry he can expect empty collection, so his code can become more generic, without checking a type, just checking size component and performing zero iteration over the bytes stream.</p>
<p>Shortly, IMO, all <type> EMPTY should evaluate to </p>
<pre>010700000000000000</pre>
<p>Back to OGR. It&#8217;s a bad idea to report <code>POINT(0 0)</code> for <code>POINT EMPTY</code> and it is actually invalid as these two geometries are not equivalent. The former is non-empty valid point of both coordinates of Zero, the latter is valid geometry with no coordinates initialized. I&#8217;m sure you get my point.</type></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Even Rouault</title>
		<link>http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/comment-page-1/#comment-2611</link>
		<dc:creator>Even Rouault</dc:creator>
		<pubDate>Sat, 27 Feb 2010 13:08:50 +0000</pubDate>
		<guid isPermaLink="false">http://mateusz.loskot.net/?p=1914#comment-2611</guid>
		<description>Actually, as you suggested, accepting to truncate to 9 bytes for POINT EMPTY would not work for code that imports wkb without knowing the length of the string (which is a bad practice from a security point of view as the code cannot check for malformed wkb)

For example, OGRGeometry::importFromWkb( unsigned char *, int = -1 ) takes the length of the binary content as optionnal argument. If the size is specified (second argument &gt;=0), it can check that no read outside of the buffer is attempted. Otherwise it supposes that the passed buffer is large enough.

One could imagine to represent the wkb form of POINT EMPTY by setting one of the most significant bit of the 4 bytes used for the geometry type, as it is done to specify the Z or M form. Or add a new geometry type just meaning &quot;POINT EMPTY&quot;. Hum, another proof that emptyness is a non trivial concept ;-)</description>
		<content:encoded><![CDATA[<p>Actually, as you suggested, accepting to truncate to 9 bytes for POINT EMPTY would not work for code that imports wkb without knowing the length of the string (which is a bad practice from a security point of view as the code cannot check for malformed wkb)</p>
<p>For example, OGRGeometry::importFromWkb( unsigned char *, int = -1 ) takes the length of the binary content as optionnal argument. If the size is specified (second argument &gt;=0), it can check that no read outside of the buffer is attempted. Otherwise it supposes that the passed buffer is large enough.</p>
<p>One could imagine to represent the wkb form of POINT EMPTY by setting one of the most significant bit of the 4 bytes used for the geometry type, as it is done to specify the Z or M form. Or add a new geometry type just meaning &#8220;POINT EMPTY&#8221;. Hum, another proof that emptyness is a non trivial concept ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Even Rouault</title>
		<link>http://mateusz.loskot.net/2010/02/26/sqlgeometry-and-point-empty-in-wkb/comment-page-1/#comment-2610</link>
		<dc:creator>Even Rouault</dc:creator>
		<pubDate>Sat, 27 Feb 2010 12:48:41 +0000</pubDate>
		<guid isPermaLink="false">http://mateusz.loskot.net/?p=1914#comment-2610</guid>
		<description>As far as OGR is concerned, here&#039;s the output of :

&lt;pre&gt;from osgeo import ogr
import binascii

wktlist = [ &#039;POINT EMPTY&#039;,
            &#039;LINESTRING EMPTY&#039;,
            &#039;POLYGON EMPTY&#039;,
            &#039;MULTIPOINT EMPTY&#039;,
            &#039;MULTILINESTRING EMPTY&#039;,
            &#039;MULTIPOLYGON EMPTY&#039;,
            &#039;GEOMETRYCOLLECTION EMPTY&#039; ]

for wkt in wktlist:
    geom = ogr.CreateGeometryFromWkt(wkt)
    wkb = geom.ExportToWkb(ogr.wkbNDR)
    geom2 = ogr.CreateGeometryFromWkb(wkb)
    print wkt
    print &#039;%s (%d bytes)&#039; % (binascii.hexlify(wkb), len(wkb))
    print &#039;After importing wkb : %s&#039; % geom2.ExportToWkt()
    print



POINT EMPTY
010100000000000000000000000000000000000000 (21 bytes)
After importing wkb : POINT (0 0)

LINESTRING EMPTY
010200000000000000 (9 bytes)
After importing wkb : LINESTRING EMPTY

POLYGON EMPTY
010300000000000000 (9 bytes)
After importing wkb : POLYGON EMPTY

MULTIPOINT EMPTY
010400000000000000 (9 bytes)
After importing wkb : MULTIPOINT EMPTY

MULTILINESTRING EMPTY
010500000000000000 (9 bytes)
After importing wkb : MULTILINESTRING EMPTY

MULTIPOLYGON EMPTY
010600000000000000 (9 bytes)
After importing wkb : MULTIPOLYGON EMPTY

GEOMETRYCOLLECTION EMPTY
010700000000000000 (9 bytes)
After importing wkb : GEOMETRYCOLLECTION EMPTY&lt;/pre&gt;


So OGR behaves like SqlGeometry, except for the POINT EMPTY case where it fallbacks to exporting it as POINT (0, 0) in wkb. Truncating the wkb of POINT EMPTY to 9 bytes might make sense for the sake of consistency, but it would require an update of the OGC SF spec</description>
		<content:encoded><![CDATA[<p>As far as OGR is concerned, here&#8217;s the output of :</p>
<pre>from osgeo import ogr
import binascii

wktlist = [ 'POINT EMPTY',
            'LINESTRING EMPTY',
            'POLYGON EMPTY',
            'MULTIPOINT EMPTY',
            'MULTILINESTRING EMPTY',
            'MULTIPOLYGON EMPTY',
            'GEOMETRYCOLLECTION EMPTY' ]

for wkt in wktlist:
    geom = ogr.CreateGeometryFromWkt(wkt)
    wkb = geom.ExportToWkb(ogr.wkbNDR)
    geom2 = ogr.CreateGeometryFromWkb(wkb)
    print wkt
    print '%s (%d bytes)' % (binascii.hexlify(wkb), len(wkb))
    print 'After importing wkb : %s' % geom2.ExportToWkt()
    print

POINT EMPTY
010100000000000000000000000000000000000000 (21 bytes)
After importing wkb : POINT (0 0)

LINESTRING EMPTY
010200000000000000 (9 bytes)
After importing wkb : LINESTRING EMPTY

POLYGON EMPTY
010300000000000000 (9 bytes)
After importing wkb : POLYGON EMPTY

MULTIPOINT EMPTY
010400000000000000 (9 bytes)
After importing wkb : MULTIPOINT EMPTY

MULTILINESTRING EMPTY
010500000000000000 (9 bytes)
After importing wkb : MULTILINESTRING EMPTY

MULTIPOLYGON EMPTY
010600000000000000 (9 bytes)
After importing wkb : MULTIPOLYGON EMPTY

GEOMETRYCOLLECTION EMPTY
010700000000000000 (9 bytes)
After importing wkb : GEOMETRYCOLLECTION EMPTY</pre>
<p>So OGR behaves like SqlGeometry, except for the POINT EMPTY case where it fallbacks to exporting it as POINT (0, 0) in wkb. Truncating the wkb of POINT EMPTY to 9 bytes might make sense for the sake of consistency, but it would require an update of the OGC SF spec</p>
]]></content:encoded>
	</item>
</channel>
</rss>

