UCOSP — Converting Well Known Binary to KML">UCOSP — Converting Well Known Binary to KML
Hey guys!
So, last week I set out some goals for myself to get completed this past week. I’ll re-post them here:
Have the article from Andrew read so I can be brought up to speed on some of the OGR terminology.
Have OGR built with Optimization on.
Have a sample piece of C code going that demonstrates KML.
Hopefully have the details from Chuck on what the changes are from listing the SQL functions. If this pans out, try to get a stub function going that outputs “Hello KML!”
I am proud to say I’ve achieved my goals! First thing that I did was to get the build for OGR going, so I will discuss that first.
OGR
OGR is an open source library OGR is actually a subset of the GDAL package, so in order to build GDAL, it meant having to build OGR. Here is a link to the GDAL source:
wget http://download.osgeo.org/gdal/gdal172.zip
Andrew wanted to know how large OGR would be once optimization was turned on, and so I set out to find out this info. I didn’t exactly know what it meant for optimization to be on — but I learned that it meant that it was a build of OGR that would be production ready, that minimized the amount of debug data. After doing a build of OGR, it was deemed an acceptable sized library to include in Ingres! Here were the steps I used to build OGR:
export CFLAGS=-O2
export CXXFLAGS=-O2
And the configure:
./configure –prefix=/usr/local \
> –with-threads \
> –with-ogr \
> –with-geos \
> –without-libtool \
> –with-libz=internal \
> –with-libtiff=internal \
> –with-geotiff=internal \
> –without-gif \
> –without-pg \
> –without-grass \
> –without-libgrass \
> –without-cfitsio \
> –without-pcraster \
> –without-netcdf \
> –without-png \
> –with-jpeg=internal \
> –without-gif \
> –without-ogdi \
> –without-fme \
> –without-hdf4 \
> –without-hdf5 \
> –without-jasper \
> –without-ecw \
> –without-kakadu \
> –without-mrsid \
> –without-jp2mrsid \
> –without-bsb \
> –without-grib \
> –without-mysql \
> –without-ingres \
> –without-xerces \
> –without-expat \
> –without-odbc \
> –without-curl \
> –without-sqlite3 \
> –without-dwgdirect \
> –without-idb \
> –without-sde \
> –without-perl \
> –without-php \
> –without-ruby \
> –without-python \
Once I was able to compile, build, and install it, I was able to follow some of the sample API stuff in OGR.
KML
The questions surrounding KML have been interesting, its been on and off as to which library to use to convert well known binary (WKB) into KML. The original idea was to use OGR, but then when talking to the OGR community, they said that it may not be thread safe.. We started doing research into what else we could use, maybe just directly using libkml. If we were to go this route then we would have to create the algorithm that converts WKB into something that we can enter into the libkml library. We went back to the OGR route, and with the help of Frank Warmerdam, we were able to get WKB converted into KML! My biggest challenge during this process was learning how to compile and build executables in C, using dynamic libraries, but after learning, it was really quite simple. I just haven’t done very much C
Here is the code that converted WKB into KML incase anyone wants to use this themselves:
#include “ogr_api.h”
int main()
{
OGRErr eErr;
OGRGeometryH hGeom = NULL;
char *kml = NULL;
unsigned char *wkb_buffer = “\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x007@”;
eErr = OGR_G_CreateFromWkb( wkb_buffer, NULL, &hGeom, –1 );
if( eErr == OGRERR_NONE )
{
kml = OGR_G_ExportToKML( hGeom, “???I do not know what this is” );
OGR_G_DestroyGeometry( hGeom );
printf( “kml = %s\n”, kml );
//CPLFree( kml );
}
else if( eErr == OGRERR_NOT_ENOUGH_DATA )
{
printf(“error1”);
}
else if( eErr == OGRERR_UNSUPPORTED_GEOMETRY_TYPE )
{
printf(“error2”);
}
else if( eErr == OGRERR_CORRUPT_DATA )
{
printf(“error3”);
};
}
The next step now is to implement the asKML function within the Ingres source code! Right now one of the developers Chuck is still working on reviving the instructions to do this, but once he is finished, I will be good to go!
Shawn