gdal笔记


---------安装gdal

http://wiki.woodpecker.org.cn/moin/lilin/gdal-introduce#head-ddf209b471ede52abec271c974ff6e89c5daed49-----安装指南

https://pypi.python.org/pypi/GDAL/1.10.0------下载地址

:安装python版的gdal。因为官方打包的少了一个“cpl_port.h”和cpl_port.h中include ***等其它相关的头文件,还少了“gdal_i.lib”和“gdal110.dll”文件。

所以安装的时候需要先安装C++版,等安装完之后将C++打完包的目录“C:\warmerda\bld”下拷贝所需要的文件,然后复制到相对应的地方即可。

步骤如下:

注意:最好将C++版和PYTHON版的gdal的版本都下载一致,我这里使用的是GDAL的1.10.0版本。

1:先安装C++版的gdal。生成安装文件C:\warmerda。--------下载

地址“http://wiki.woodpecker.org.cn/moin/lilin/gdal-introduce#head-ddf209b471ede52abec271c974ff6e89c5daed49”

2:下载python版gdal。然后解压到“C:\Users\hongliang.lu\Desktop”。------下载地址https://pypi.python.org/pypi/GDAL/1.10.0

3:将“C:\warmerda\bld\include”下的所有文件拷贝复制到“C:\Users\hongliang.lu\Desktop\GDAL-1.10.0\GDAL-1.10.0\extensions”下;

4:将“C:\warmerda\bld\lib”下的所有文件拷贝复制到"C:\Users\hongliang.lu\Desktop\GDAL-1.10.0\GDAL-1.10.0"下;

5:cmd==>cd 到C:\Users\hongliang.lu\Desktop\GDAL-1.10.0\GDAL-1.10.0,然后键入命令"python setup.py install",

然后会在python的安装目录"C:\python275\Lib\site-packages"生成GDAL-1.10.0-py2.7-win32.egg文件夹(注意是文件夹不是文件)。

6:因为如果使用ipython导入import gdal的时候需要gdal的dll文件,所以需要将c++安装好的包的dll拷贝到python的根目录下。即

“C:\warmerda\bld\bin\gdal110.dll”拷贝到“C:\python275”下。


----------gdal,ogr教程

http://www.gdal.org/ogr/ogr_apitut.html


---------------------C++操作OGR

http://blog.csdn.net/tszhangjunqiao/article/details/16859553


----------求某一个车道标记点pLaneMark  lanemark  在道路pRoad  road的左侧还是右侧:

 

1:先求得pLaneMark距离pRoad上所有Point最近的点PointB。

2:将在pRoad上求得的PointB点所在的索引上加一,求取pRoad上PointB的下一个点PointC。

3:然后使用矢量算法,对pLaneMark,PointB,PointC这三个点求顺时针或者逆时针,即可得知pLaneMark在pRoad的左侧还是右侧。

 

判断 某一点在直线左右侧 方法判断 某一点在直线左右侧 
左右方向是相对前进方向的,只要指定了前进方向就可以知道左右(比如指定前进方向是从直线的起点到终点).判断点在直线的左侧还是右侧是计算几何里面的一个最基本算法.使用矢量来判断. 
定义:平面上的三点P1(x1,y1),P2(x2,y2),P3(x3,y3)的面积量:
S(P1,P2,P3)=|y1 y2 y3|= (x1-x3)*(y2-y3)-(y1-y3)(x2-x3) 
当P1P2P3逆时针时S为正的,当P1P2P3顺时针时S为负的。 
令矢量的起点为A,终点为B,判断的点为C, 
如果S(A,B,C)为正数,则C在矢量AB的左侧; 
如果S(A,B,C)为负数,则C在矢量AB的右侧; 
如果S(A,B,C)为0,则C在直线AB上。

 

判断方法2:

 

void DecomposeOGRGeometry(OGRGeometry * pGeometry, 
						  vector<OGRPoint *> & vtPoint, 
						  vector<OGRLineString *> & vtLineString, 
						  vector<OGRPolygon *> & vtPolygon)
{
	if(!pGeometry)
	{
		return ;
	}
	
	int i=0;
	OGRwkbGeometryType geometryType = pGeometry->getGeometryType();
	switch (geometryType)
	{
	case wkbGeometryCollection:
		{
			/// 遍历每一个Geometry
			OGRGeometryCollection * pGeometryCollection = (OGRGeometryCollection *)pGeometry;
			for (i = 0; pGeometryCollection->getNumGeometries() > i; ++i)
			{
				OGRGeometry * pGeo = pGeometryCollection->getGeometryRef(i);
				DecomposeOGRGeometry(pGeo, vtPoint, vtLineString, vtPolygon);
			}
		}
		break;
	case wkbMultiLineString:
		{
			/// 遍历每一个LineString
			OGRMultiLineString * pMultiLineString = (OGRMultiLineString *)pGeometry;
			for (i = 0; pMultiLineString->getNumGeometries() > i; ++i)
			{
				OGRGeometry * pGeo = pMultiLineString->getGeometryRef(i);
				vtLineString.push_back((OGRLineString *)pGeo);
			}
		}
		break;
	case wkbLineString:
		{
			vtLineString.push_back((OGRLineString *)pGeometry);
		}
		break;
	case wkbMultiPoint:
		{
			/// 遍历每一个Point
			OGRMultiPoint * pMultiPoint = (OGRMultiPoint *)pGeometry;
			for (i = 0; pMultiPoint->getNumGeometries() > i; ++i)
			{
				OGRGeometry * pGeo = pMultiPoint->getGeometryRef(i);
				vtPoint.push_back((OGRPoint *)pGeo);
			}
		}
		break;
	case wkbPoint:
		{
			vtPoint.push_back((OGRPoint *)pGeometry);
		}
		break;
	case wkbMultiPolygon:
		{
			/// 遍历每一个Polygon
			OGRMultiPolygon * pMultiPolygon = (OGRMultiPolygon *)pGeometry;
			for (i = 0; pMultiPolygon->getNumGeometries() > i; ++i)
			{
				OGRGeometry * pGeo = pMultiPolygon->getGeometryRef(i);
				vtPolygon.push_back((OGRPolygon *)pGeo);
			}
		}
		break;
	case wkbPolygon:
		{
			vtPolygon.push_back((OGRPolygon *)pGeometry);
		}
		break;
	default:
		{
			break;
		}
	}
	
	return ;
}

 

 

 

//判断point1和point2是否在道路的同一侧
bool CRoad::IsOnSameSide(OGRPoint *point1, OGRPoint *point2)
{
	bool bEnable= false;
	OGRLineString lineString;
	lineString.addPoint(point1);
	lineString.addPoint(point2);
	OGRGeometry *pRoadGeo = this->GetGeometry();
	//获取相交
	OGRGeometry * pInterGeo = lineString.Intersection(pRoadGeo);
	if(pInterGeo)
	{
		vector<OGRPoint *> vtPoint;
		vector<OGRLineString *> vtLineString;
		vector<OGRPolygon *> vtPolygon;	
		DecomposeOGRGeometry(pInterGeo, vtPoint, vtLineString, vtPolygon );
		if ((vtPoint.size()%2)==0)//如果相交点的数量为偶数,则在同一侧,否则不在同一侧
			bEnable= true;
		else
			bEnable= false;
	}
	else
	{
		bEnable=true;
	}
	return bEnable;
}


---------在使用OGRGeometry::Intersects的时候会出现失败的情况,这可能是因为在编译gdal的时候只编译的ogr库,没有编译geos库导致的。

可以参开如下官网的描述:


OGRBoolean OGRGeometry::Intersects	(	OGRGeometry * 	poOtherGeom	 ) 	 const [virtual]
Do these features intersect?

Determines whether two geometries intersect. If GEOS is enabled, then this is done in rigerous fashion otherwise TRUE is returned if the envelopes (bounding boxes) of the two features overlap.

The poOtherGeom argument may be safely NULL, but in this case the method will always return TRUE. That is, a NULL geometry is treated as being everywhere.

This method is the same as the C function OGR_G_Intersects().

Parameters:
poOtherGeom 	the other geometry to test against.
Returns:
TRUE if the geometries intersect, otherwise FALSE.
References getEnvelope().

--------------------------------OGR可以打开CSV文件和通过简单的SQL进行筛选
使用OGRLayer::SetAttributeFilter即可http://www.gdal.org/ogr/classOGRLayer.html#acb2c6cc5fa3577df5be538284c1b0dde

对layer对象使用SetAttributeFilter之后过滤到的结果集,对同一个layer对象再次使用SetAttributeFilter则可能出现错误的情况,最好使用SetAttributeFilter(None),将

layer置为原始数据,然后进行SetAttributeFilter才行。

--------------------------坐标旋转一定角度公式:http://www.cnblogs.com/ywxgod/archive/2010/08/06/1793609.html

将(x,y)旋转angle角度得到(x1,y1):

x1=cos(angle)*x-sin(angle)*y;

y1=cos(angle)*y+sin(angle)*x;

-------------------------PointOnSurface使用:

函数PointOnSurface需要和IsPointOnSurface联合使用,先判断Point是否在面上,否则会报错:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

 

 

 

 



 

posted @ 2013-11-28 16:36  bielidefeng  阅读(939)  评论(0编辑  收藏  举报