---------安装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”下。
编译64位的gdal版本gdal-1.11.1,geos注意: 注意点,
打开
vistual studio cross tools command prompt (2010)
如果没有使用这个编译器:则会报错:
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.EXE"' : return code '0x463' Stop.
修改gdal源码下nmake.opt文件:
然后运行下面的命令:
nmake /f makefile.vc nmake /f makefile.vc install nmake /f makefile.vc devinstall
最后再C:\warmerda\bld即可看到生成的库。
运行gdal源码中的makegdal_gen.bat工具,可以生成sln工程,也可以直接使用这个sln使用vs2010打开编译。
|
----------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().
---------------------计算两个向量的角度
将(x3,y3)和(x2,y2)移动距离x防线x3-x0,y方向y3-y0的距离。
- //移动pObject中所有形状点x-->dScaleMove_X,y-->dScaleMove_Y
- void MoveLineString(SHPObject * const pObject, double dScaleMove_X, double dScaleMove_Y)
- {
- int VerticesCnt= pObject->nVertices;
- for (int i = 0; i < VerticesCnt; ++i)
- {
- double & dx= pObject->padfX[i];
- double & dy= pObject->padfY[i];
- dx= dx- dScaleMove_X;
- dy= dy- dScaleMove_Y;
- }
- }
- double GetDistince(double dx1, double dy1, double dx2, double dy2)
- {
- double dDistince= sqrt( pow(dx1-dx2, 2)+ pow(dy1-dy2, 2) );
- return dDistince;
- }
- /*计算两个有向线段的夹角,其两条线段分别为:
- (x0,y0)-->(x1,y1)
- (x0,y0)-->(x2,y2)
- 其(x0,y0)为其交点
- */
- double GetThreePointsAngle(double x1, double y1, double x0, double y0, double x2, double y2)
- {
- //平面距离
- double a = GetDistince(x1, y1, x0, y0);
- double b = GetDistince(x2, y2, x0, y0);
- double c = GetDistince(x1, y1, x2, y2);
- double fHuDu = acos((a*a + b*b - c*c) / (2.0*a*b));
- double dJiaoDu= fHuDu*180/PI;
- return dJiaoDu;//fAngle>0 ? fAngle : PI;
- }
使用:
- 获取向量pstFristSlope-->pstFinalSlope和
- 向量pstRoad->iFnode-->pstRoad->iTnode
- 之间的夹角*/
- _MdbSlope_* pstFristSlope = vecMdbSlope[0];
- _MdbSlope_* pstFinalSlope = vecMdbSlope[nSlopeCnt-1];
- double pdlX[2];
- double pdlY[2];
- double pdlZ[2];
- pdlX[0] = pstFristSlope->stNode.X;
- pdlY[0] = pstFristSlope->stNode.Y;
- pdlZ[0] = 0.0;
- pdlX[1] = pstFinalSlope->stNode.X;
- pdlY[1] = pstFinalSlope->stNode.Y;
- pdlZ[1] = 0.0;
- SHPObject* pObject = SHPCreateSimpleObject(SHPT_ARC, 2, pdlX, pdlY, pdlZ);
- double dScaleMove_X= pstFristSlope->stNode.X- pstNode->dx;
- double dScaleMove_Y= pstFristSlope->stNode.Y- pstNode->dy;
- //移动pstFristSlope-->pstFinalSlope坐标到pstRoad->iFnode,
- //相应的pstFinalSlope点也会移动
- MoveLineString(pObject, dScaleMove_X, dScaleMove_Y);
- // double x1= pObject->padfX[0];
- // double y1=pObject->padfY[0];
- double x1=pstRoad->TnodeCoord.X;
- double y1=pstRoad->TnodeCoord.Y;
- double x2=pObject->padfX[1];
- double y2=pObject->padfY[1];
- SHPDestroyObject(pObject);
- double x0= pstRoad->FnodeCoord.X;
- double y0= pstRoad->FnodeCoord.Y;
- double dJiaoDu= GetThreePointsAngle(x1, y1, x0, y0, x2, y2);