ERROR 6: GEOS support not enabled.
要學(xué)習(xí)GEOS庫,肯定繞不開地理方面的東西。如果需要判斷的兩個多邊形或幾何圖形,不是自己創(chuàng)建的,而是來自shapefile文件,那就得將GEOS庫和GDAL/OGR庫結(jié)合使用了。實(shí)際上只需要OGR就行了,但OGR和GDAL是放在一起的。OGR庫用來讀取和輸出shapefile(shp)文件,geos庫用來判斷空間關(guān)系。
需要注意的地方:OGR里面的幾何圖形類OGRGeometry和GOES里面的類Geometry基本上是一樣的,函數(shù)也大體相同。OGRGeometry類里面也有類似于Disjoint(),Touches(),Overlaps()這樣的函數(shù)。但是這些函數(shù)是花架子,沒有GEOS庫的支持是用不成的。如果只有OGR庫而沒有GEOS庫,運(yùn)行這些函數(shù)就會提示GEOS support not enabled.這樣的錯誤,也得不到正確的結(jié)果。
在OGR的官方文檔中,對Overlaps()函數(shù)有這樣一句話描述:This method is built on the GEOS library, check it for the definition of the geometry operation. If OGR is built without the GEOS library, this method will always fail, issuing a CPLE_NotSupported error.
大致意思就是這個函數(shù)是建立在GEOS庫的基礎(chǔ)上,沒有GEOS庫的支持,這個函數(shù)運(yùn)行會出錯。
1、編譯GEOS。參考http://www.cnblogs.com/denny402/p/4966558.html
2、編譯GDAL. 參考http://www.cnblogs.com/sansan/p/3394636.html,注意要先編譯GEOS,再編譯GDAL,不然會提示找不到geos_c_i.lib這個庫。
編譯并設(shè)置好后,就可以開始代碼測試了。
本例的數(shù)據(jù)及工具版本:
GDAL/OGR: 2.0.0
GEOS: 3.5.0
shp文件:中國國界和省界SHP文件 ,可點(diǎn)此下載
至于SHP文件的讀取,可參考?http://www.cnblogs.com/denny402/p/4959867.html
測試代碼:
#include "stdafx.h" #include <iostream> #include "ogrsf_frmts.h" using namespace std;int _tmain(int argc, _TCHAR* argv[]) {GDALAllRegister();GDALDataset *poDS;CPLSetConfigOption("SHAPE_ENCODING",""); //解決中文亂碼問題//讀取shp文件poDS = (GDALDataset*) GDALOpenEx("d:/shp/province.shp", GDAL_OF_VECTOR, NULL, NULL, NULL );if( poDS == NULL ){printf( "Open failed.\n%s" );exit( 1 );}OGRLayer *poLayer;poLayer = poDS->GetLayer(0); //讀取層poLayer->ResetReading();OGRFeature *poFeature1,*poFeature2,*poFeature3;poFeature1=poLayer->GetFeature(205); //四川省poFeature2=poLayer->GetFeature(0); //黑龍江省poFeature3=poLayer->GetFeature(66); //青海省OGRGeometry *p1=poFeature1->GetGeometryRef();OGRGeometry *p3=poFeature2->GetGeometryRef();OGRGeometry *p2=poFeature3->GetGeometryRef();cout<<p1->IsEmpty()<<endl //圖形是否為空<<p1->IsSimple()<<endl //是否是單個幾何圖形<<p1->getGeometryType()<<endl //幾何圖形的類型,polygon返回3<<p1->getGeometryName()<<endl //幾何圖形的名稱<<p1->getDimension()<<endl //圖形的維度<<p1->getCoordinateDimension()<<endl //坐標(biāo)的維度<<p1->getSpatialReference()<<endl; //空間參考if(p2->Disjoint(p1))cout<<"不相交"<<endl;else{if(p2->Touches(p1))cout<<"接觸"<<endl;else if(p2->Overlaps(p1))cout<<"部分重疊"<<endl;else if(p2->Contains(p1))cout<<"包含"<<endl;elsecout<<"unknown"<<endl;}system("pause");return 1; }總結(jié)
以上是生活随笔為你收集整理的ERROR 6: GEOS support not enabled.的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下编译GDAL
- 下一篇: WKT介绍