gdal集成kml庫的作法

做者:朱金燦dom

來源:http://blog.csdn.net/clever101ui

   

         最近要讀取kml文件,具體就是把kml文件看成一個矢量文件來讀取。我發現gdal是支持集成kml庫的。不過集成這個kml庫的地方有點複雜。下面做一個詳細的說明。spa

 

        首先要libkml和expat這兩個庫,具體是修改gdal源碼根目錄下的nmake.opt,將EXPAT_DIR放在LIBKML_DIR的前面(爲了確保EXPAT_LIB能被LIBKML_LIBS識別),具體修改以下:.net


# Uncomment for Expat support (required for KML, GPX and GeoRSS read support).
EXPAT_DIR = $(THIRD_PARTY)/expat_2_1_0_vc9
EXPAT_INCLUDE = -I$(EXPAT_DIR)/include
!IFDEF DEBUG
EXPAT_LIB = $(THIRD_PARTY)/expat_2_1_0_vc9/lib/libexpatD.lib
!ELSE
EXPAT_LIB = $(THIRD_PARTY)/expat_2_1_0_vc9/lib/libexpat.lib
!ENDIF

LIBKML_DIR的設置修改以下:code

# Uncomment out the following lines to enable LibKML support.
LIBKML_DIR = $(THIRD_PARTY)/libkml_1_3_0_vc9
LIBKML_INCLUDE = -I$(LIBKML_DIR)/include -I$(THIRD_PARTY)/boost_1_42_vc9/include
LIBKML_LIBRARY = $(LIBKML_DIR)/lib
LIBKML_LIBS =	$(LIBKML_LIBRARY)/libkmlbase.lib \
		$(LIBKML_LIBRARY)/libkmlconvenience.lib \
		$(LIBKML_LIBRARY)/libkmldom.lib \
		$(LIBKML_LIBRARY)/libkmlengine.lib \
		$(LIBKML_LIBRARY)/libkmlregionator.lib \
		$(LIBKML_LIBRARY)/libkmlxsd.lib \
		$(THIRD_PARTY)/minizip_vc9/lib/minizip_static.lib \
		$(EXPAT_LIB) \
		$(THIRD_PARTY)/uriparser_0_7_5_vc9/lib/uriparser.lib \
#		$(LIBKML_DIR)/third_party\zlib-1.2.3.win32/lib/minizip.lib \
		$(THIRD_PARTY)/zlib_1_2_3_vc9/lib/libzlib_vc9_1_2_3.lib

    能夠除了kml自己的庫外,還要添加minizip庫、expat庫、boost庫和zip庫。blog

 

這樣就能將kml庫集成進來。還有一點須要注意的是,我發現kml並不支持傳統的shp文件的矢量類型,所以要重載kml圖層類的GetGeomType接口(將kml類型轉換爲傳統的shp的矢量類型),這個接口的實現代碼以下:接口

OGRwkbGeometryType OGRLIBKMLLayer::GetGeomType()
{
	OGRwkbGeometryType eType = wkbUnknown;
	OGRFeature* pFeature = NULL;
	ResetReading();
	pFeature = GetNextFeature();
	if (pFeature != NULL)
	{
		OGRGeometry* pGeometry = pFeature->GetGeometryRef();
		if (pGeometry != NULL)
		{
			eType = pGeometry->getGeometryType();
		}
	}
	m_poOgrFeatureDefn->SetGeomType(eType);
	return eType;
}
相關文章
相關標籤/搜索