The principle of an article has been introduced, this article directly to the program practice
#include"Geos.h"Geometryfactory Factory;//Create a loop, the difference between the line is that the loop is closed. That is, the first point coincides with the last one.linearring* creategeosring (DoubleXDoubleYDoubleoffset) {Coordinatearraysequencefactory CSF; Coordinatesequence* cs = csf.create (6,2); CS->setat (Coordinate (x, y),0); CS->setat (Coordinate (x,y+offset),1); CS->setat (Coordinate (x+offset,y+offset),2); CS->setat (Coordinate (x+2*offset,y+2*offset),3); CS->setat (Coordinate (x+2*offset,y),4); CS->setat (Coordinate (x, y),5);//equal to the first pointLinearring *lr=factory.createlinearring (CS); returnLR;}//Create a polygon, if there is no hole inside the polygon is actually the same as the looppolygon* Creategeospolygon (DoubleXDoubleYDoubleoffset) {linearring*lr=creategeosring (X,y,offset); Polygon*poly=factory.createpolygon (Lr,null);//if there is no hole in the middle of the polygon, the second parameter is set to null returnPoly;}intMain () {Polygon*p1=creategeospolygon ( A, A,5);//Create a first polygon for(intI=0; i<= -; i++) {cout<<i<<": "; Polygon*p2=creategeospolygon (0,0, i);//Create a second polygonIntersectionmatrix *im=p2->relate (p1); cout<<*im<<" ";//return De-9im Cross matrix if(p2->disjoint (p1)) cout<<"do not intersect"<<Endl; Else { if(p2->touches (p1)) cout<<"Contact"<<Endl; Else if(p2->overlaps (p1)) cout<<"partially overlapping"<<Endl; Else if(p2->covers (p1)) cout<<"cover"<<Endl; Elsecout<<*im<<Endl; }} system ("Pause"); return 1;}
The results are as follows:
GEOS study four: geometric relation judgment