gdal集成kml库的做法

作者:朱金灿

来源:http://blog.csdn.net/clever101

   

         最近要读取kml文件,具体就是把kml文件当作一个矢量文件来读取。我发现gdal是支持集成kml库的。不过集成这个kml库的地方有点复杂。下面作一个详细的说明。

 

        首先要libkml和expat这两个库,具体是修改gdal源码根目录下的nmake.opt,将EXPAT_DIR放在LIBKML_DIR的前面(为了确保EXPAT_LIB能被LIBKML_LIBS识别),具体修改如下:


# 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的设置修改如下:

# 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库。

 

这样就能将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;
}

转载于:https://www.cnblogs.com/lanzhi/p/6470061.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值