I’ve just submitted abstract of Boost Geometry presentation for FOSS4G 2010. I’m looking forward to spreading the word and give Introduction to Boost Geometry Library at the FOSS4G conference. Fingers crossed!
Archive for the ‘gis’ Category
Boost Geometry on FOSS4G 2010?
Thursday, April 15th, 2010Where is my donut?
Sunday, March 14th, 2010I’m reading Darren’s post about The Geography of Tim Hortons. It’s interesting. It’s fun. The geospatial-enabled fast food consumption seems to be well aligned with the recent prophecies about what’s lucrative now, apart from donuts. It could be interesting to compare the Hortons’ trend with country-level version of this map. Perhaps, ST_Overlaps would return false, but ST_Intersection would likely return a pretty large geometry.
Anxiously, however, my enthusiasm is being a little bit repressed. The idea is a double edged sword and instead of navigating ourselves straight to donut heavens, we should rather start hiding such dangerous places from all publicly available maps and guides. This could be a part of health promoting geocaching campaign “Burn to Find”.
And I’m not going to put any smiles in here.
Direct costs are estimated to be £4.2 billion and Foresight have forcasted that this will more than double by 2050 if we continue as we are. — UK DoH report.
Const-correctness schizophrenia in GDAL
Thursday, March 4th, 2010Const-correctness rants are quite common topic of chats on #gdal IRC channel. Some of the pearls I’ve got printed in to my mind:
A: The lesson is I ought to get things right the first time.
B: The issue withconstmethod is that if you want to add lazy loading later, it can cause problems
C: GDAL is rather painful to use withconstcorrect code, unfortunately :(
B: The solution is obvious: don’t writeconstcorrect code
Who’s right then, A or B?
I recall another motto from #gdal channel that sounds like “when unsure, do nothing” which has the following rationale:
especially when I realize afterwards that I’ve f**cked things because I neglected to follow the motto
Remembering these recommendations, it’s pretty clear why the const-mess in GDAL has happened. I’d conclude paraphrasing the motto this way:
I’ve f**cked things because I neglected to make a decision.
Now, poor GDAL beginner deadpickle, trying to find out (it’s me the evil) why compiler complains about his not-that-bad-written code, wandered to find and ask C gurus @ comp.lang.c and got the problem explained by Malcolm who wrote:
The problem is that, when C was first developed, there was no const keyword. So strings literal, which are constant, had to be non-const for backwards compatibility. This means that lots of programmers get lazy and omit the const, even from functions which don’t modify their string arguments. (There are also some subtle problems with const which means that this isn’t always a case of pure laziness). So a sort of solution is to discard the const qualifiers. However this is perpetuating the problem in your own code.
The motto stays in contradiction to a well-known best practice of const correct sooner than later. It’s way easier and cheaper to remove const-correctness once it turns out it does not express properly the actual design and contract than to apply it to existing codebase. Sometimes, the latter is even not possible making things f**cked up twice, in existing code base and in client’s code.
GIS-Lab joins Planet OSGeo
Saturday, February 27th, 2010
Maxim Dubinin syndicated GIS-Lab blog with the Planet OSGeo aggregator.
A few words about GIS-Lab from their website:
GIS-Lab – informal non-commercial community of GIS/RS specialists, we grow ourselves and help grow others.
GIS-Lab exists since April 2002 as an independent online resource specializing in geographic information systems (GIS) and remote sensing (RS). At present, the site is primarily oriented towards Russian-speaking GIS community, however, we do our best to translate as many materials as possible into English.
The GIS-Lab is the very first blog in Russian language syndicated with the Planet OSGeo, what makes the planet yet more international geo-caffee.
SqlGeometry and POINT EMPTY in WKB
Friday, February 26th, 2010Inspired by question Paul Ramsey asked today morning on IRC, I’ve inspected what kind of Well-Known-Binary output gives SqlGeometry for EMPTY geometries of all the seven geometry types as specified in OGC SFS. The SqlGeometry class is available from SQL Server System CLR Types for .NET Framework. Here we go.
I checked Well-Known-Binary output as returned by the SqlGeometry method STAsBinary(). Here is a small test program written in C#:
using System;
using System.Linq;
using Microsoft.SqlServer.Types;
namespace SqlGeometryEmpty
{
class Test
{
static void Main(string[] args)
{
foreach (string type in
Enum.GetNames(typeof(OpenGisGeometryType)))
{
string wkt = type.ToUpper() + " EMPTY";
SqlGeometry geom = SqlGeometry.Parse(wkt);
byte[] wkb = geom.STAsBinary().Buffer;
string wkbhex = string.Join("",
wkb.Select(
b => b.ToString("X2")).ToArray());
Console.WriteLine("{0}\n{1} ({2} bytes)\n",
wkt, wkbhex, wkb.Length);
}
}
}
}
The first observation is that WKB of EMPTY geometry for all types is returned as a a slightly different binary. All the binary forms are truncated to nine bytes. The first byte indicates endianness as expected. The second chunk of four bytes indicate geometry type. It is exactly as defined in OGC specifications. The third chunk of remaining four bytes are set to Zero and seem to play a role of size specifier: number of points in LINESTRING or number of rings in POLYGON, number of points in MULTIPOINT, and so on. This makes another observation that WKB for EMPTY is reported as a collection of primitive components.
The difference in binary of WKB of EMPTY geometry I mentioned is in that the actual type of input geometry is preserved, so there seems to be no implicit translation to geometry of some other type.
So far so good but not for too long. In fact, SqlGeometry implicitly casts POINT EMPTY to MULTIPOINT EMPTY geometry with the WKB of the following form (in hex):
010400000000000000
Here is complete output of the test program above:
POINT EMPTY 010400000000000000 (9 bytes) LINESTRING EMPTY 010200000000000000 (9 bytes) POLYGON EMPTY 010300000000000000 (9 bytes) MULTIPOINT EMPTY 010400000000000000 (9 bytes) MULTILINESTRING EMPTY 010500000000000000 (9 bytes) MULTIPOLYGON EMPTY 010600000000000000 (9 bytes) GEOMETRYCOLLECTION EMPTY 010700000000000000 (9 bytes)
A word about how PostGIS behaves. PostGIS reports GEOMETRYCOLLECTION EMPTY, regardless of actual type of input EMPTY geometry. It is in hex form:
010700000000000000
Generally, there is not many choices of how to report EMPTY geometry in clear and usable way and a form of collection with size equal to Zero seems to be the most appropriate choice. POINT EMPTY reported with type set to POINT (010100000000000000) would be ambiguous as feels like truncated or invalid form of POINT(0 0), especially in programming languages like C where native dynamic allocated arrays do not carry information about their size. IOW, geometry type is not enough information to process binary form of POINT EMPTY properly.
Reporting EMPTY geometries as a collection is a useful convention that seems to work well. PostGIS behaves about it in the very consistent manner reporting one type for all empties. SqlGeometry, so SQL Server, forces programmers to write a few more lines of code to handle all the possible cases. Yet another original exotic solution from Microsoft.
Consistent API is a bless!
Update: consistent specification of interface is even better.


