<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mateusz Loskot &#187; wkb</title>
	<atom:link href="http://mateusz.loskot.net/tag/wkb/feed/" rel="self" type="application/rss+xml" />
	<link>http://mateusz.loskot.net</link>
	<description>mloskot&#039;s life, programming, c++, geo and adventures</description>
	<lastBuildDate>Tue, 10 Jan 2012 22:03:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Update on SqlGeometry and POINT EMPTY in WKB</title>
		<link>http://mateusz.loskot.net/2011/10/22/update-on-sqlgeometry-and-point-empty-in-wkb/</link>
		<comments>http://mateusz.loskot.net/2011/10/22/update-on-sqlgeometry-and-point-empty-in-wkb/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 22:41:46 +0000</pubDate>
		<dc:creator>mloskot</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[dbms]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[geospatial]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[ogc]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[spatial]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[wkb]]></category>

		<guid isPermaLink="false">http://mateusz.loskot.net/?p=2221</guid>
		<description><![CDATA[Long time ago I discussed about how SqlGeometry handles POINT EMPTY in WKB format. The SqlGeometry states the definition of OGC GEOMETRY type for Microsoft SQL Server. Shortly, the message was that SqlGeometry implicitly casts POINT EMPTY to MULTIPOINT EMPTY &#8230; <a href="http://mateusz.loskot.net/2011/10/22/update-on-sqlgeometry-and-point-empty-in-wkb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Long time ago I discussed about how <a href="http://mateusz.loskot.net/?p=1914">SqlGeometry handles POINT EMPTY in </a><a href="http://en.wikipedia.org/wiki/Well-known_text">WKB</a> format. The <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.types.sqlgeometry%28SQL.105%29.aspx">SqlGeometry</a> states the definition of OGC <code>GEOMETRY</code> type for Microsoft SQL Server. Shortly, the message was that SqlGeometry implicitly casts <code>POINT EMPTY</code> to <code>MULTIPOINT EMPTY</code> geometry when generating WKB output. <a href="http://www.postgis.org">PostGIS</a> casts as well, but does it in a consistent way, in my opinion, outputting <code>GEOMETRYCOLLECTION</code>.</p>
<p>Following those findings, I assumed it is not quite correct, or I didn&#8217;t like the inconsistency, and I had reported it to <a href="http://connect.microsoft.com/">Microsoft Connect</a> as a bug: <a href="http://connect.microsoft.com/SQLServer/feedback/details/537018/sqlgeometry-reports-invalid-type-of-wkb-of-point-empty">SqlGeometry reports invalid type of WKB of POINT EMPTY</a>.</p>
<p>Recently, I have received a couple of comments from Microsoft to my report. The comments are attached to the report linked above, but I paste them below for completeness and archive:</p>
<blockquote><p>Our development team for the spatial data types tells me that it is not possible to use a single value for the WKB format of any spatial data type. For the POINT EMPTY, the WKB format does not allow empty points, so we are outputting a MULTIPOINT with zero elements.<br />
In a MULTIPOINT EMPTY, we are stripping out empty points.</p></blockquote>
<p>The reasoning is technically correct. It&#8217;s just Microsoft <em>does it differently</em>. However, as second comment suggests, the current behaviour may change in future:</p>
<blockquote><p>But we might consider changing it to get consistent behavior.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mateusz.loskot.net/2011/10/22/update-on-sqlgeometry-and-point-empty-in-wkb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WKB hex decoder in C++</title>
		<link>http://mateusz.loskot.net/2008/08/21/wkb-hex-decoder-in-c/</link>
		<comments>http://mateusz.loskot.net/2008/08/21/wkb-hex-decoder-in-c/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 15:53:56 +0000</pubDate>
		<dc:creator>mloskot</dc:creator>
				<category><![CDATA[life]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[bytes]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[decode]]></category>
		<category><![CDATA[fdo]]></category>
		<category><![CDATA[fgf]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[ogc]]></category>
		<category><![CDATA[postgis]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[wkb]]></category>

		<guid isPermaLink="false">http://mateusz.loskot.net/?p=270</guid>
		<description><![CDATA[In PostGIS world, I often need to construct geometry from Well-Known-Binary (WKB) or PostGIS EWKB stream encoded as hex stream. It&#8217;s easy to do if I have access to PostgreSQL/PostGIS client which accepts SQL queries: SELECT ST_AsText( ST_GeomFromWKB( decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'), &#8230; <a href="http://mateusz.loskot.net/2008/08/21/wkb-hex-decoder-in-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.postgis.org/">PostGIS</a> world, I often need to construct geometry from Well-Known-Binary (WKB) or <a href="http://www.postgis.org/documentation/manual-1.3/ch04.html">PostGIS EWKB</a> stream encoded as hex stream. It&#8217;s easy to do if I have access to PostgreSQL/PostGIS client which accepts SQL queries:</p>
<pre><code>SELECT
   ST_AsText(
      ST_GeomFromWKB(
         decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'),
         4326))</code></pre>
</p>
<p>I often need to do the same directly in C++ code &#8211; parse hex encoded binary stream to raw stream of bytes. Here is simple hex decoder I use:</p>
<pre><code>#include &lt;sstream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
typedef std::vector&lt;unsigned char&gt; ewkb_t;

// bytes [out] - buffer for binary output
void hex_to_bytes(std::string const&#038; hexstr, ewkb_t&#038; bytes)
{
    bytes.clear();
    for(std::string::size_type i = 0; i < hexstr.size() / 2; ++i)
    {
        std::istringstream iss(hexstr.substr(i * 2, 2));
        unsigned int n;
        iss >> std::hex >> n;
        bytes.push_back(static_cast&lt;unsigned char&gt;(n));
    }
}
</code></pre>
</p>
<p>For example, I use it to build <a href="http://trac.osgeo.org/fdo/browser/trunk/Providers/PostGIS/Src/Provider/PgGeometry.h">FDO geometry objects</a> using another utility <a href="http://trac.osgeo.org/fdo/browser/trunk/Providers/PostGIS/Src/Provider/PgGeometry.cpp?rev=3904#L284">CreateGeometryFromExtendedWkb</a> defined in FDO provider for PostGIS:</p>
<pre><code>// POINT (1.234 5.678)
std::string ewkbhex("01010000005839B4C876BEF33F83C0CAA145B61640");
ewkb_t ewkb;
hex_to_bytes(ewkbhex, ewkb);
if (!ewkb.empty())
{
   FdoPtr&lt;fdoigeometry> g = CreateGeometryFromExtendedWkb(ewkb);
   // ... use geometry
}</code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://mateusz.loskot.net/2008/08/21/wkb-hex-decoder-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

