0

I m trying to compare every point of MultiPoint geometry with start point and end point of LineString , there is my code below:

First method:

geos::geom::LineString* ptLine = dynamic_cast<LineString*>( ptCurrentGeomIntersection );
for( int iCurrentPoint = 0; iCurrentPoint < ptGeom->getNumPoints(); iCurrentPoint++ ){
  if(  ptLine->getStartPoint()->equals( ptGeom->getGeometryN( iCurrentPoint ) ) )
    continue;
  else if (  ptLine->getEndPoint()->equals( ptGeom->getGeometryN( iCurrentPoint ) ) )
    continue;

//other treatement...
}

Second method: I have create a point with current geometry then i compare

geos::geom::LineString* ptLine = dynamic_cast<LineString*>( ptCurrentGeomIntersection );
for( int iCurrentPoint = 0; iCurrentPoint < ptGeom->getNumPoints(); iCurrentPoint++ ){
  Point* ptCurrentPointToAdd = m_ptFactory->createPoint( *ptGeom->getGeometryN( iCurrentPoint )->getCoordinate() );
  if(  ptLine->getStartPoint()->equals( ptCurrentPointToAdd ) )
    continue;
  if (  ptLine->getEndPoint()->equals( ptCurrentPointToAdd ) )
    continue;

 //other treatement...
}

there is output of second method:

 LINESTRING (1768.8442503851 1010570.2425701290, 4228.5112185504 
 1012209.0468547827, 6688.1781867156 1013847.8511394364, 9147.8451548809
 1015486.6554240901, 11607.5121230462 1017125.4597087437, 14067.1790912114
 1018764.2639933976, 16526.8460593767 1020403.0682780512, 17667.8781414151
 1024149.1601604699, 18597.0195615059 1028233.8708438184, 19526.1609815966
 1032318.5815271670, 20455.3024016874 1036403.2922105156, 21384.4438217781
 1040488.0028938639, 22313.5852418688 1044572.7135772125, 23242.7266619596
 1048657.4242605611, 24171.8680820503 1052742.1349439095, 25101.0095021411
 1056826.8456272581,26030.1509222318 1060911.5563106067, 28501.8267239067
 1062557.9895967811, 30199.3608916138 1064013.1404002085)

MULTIPOINT (1768.8442503851 1010570.2425701290, 30199.3608916138 1064013.1404002085)

 iteration 1:
 POINT (1768.8442503851 1010570.2425701290) // startPoint of lineString
 POINT (30199.3608916138 1064013.1404002085)//EndPoint of lineString
 POINT (1768.8442503851 1010570.2425701290) //Current point of Multipoint geometry

iteration 2:
POINT (1768.8442503851 1010570.2425701290) // startPoint of lineString
POINT (30199.3608916138 1064013.1404002085)//EndPoint of lineString
POINT (30199.3608916138 1064013.1404002085)//Current point of Multipoint geometry

In the iteration 1 , we see that startPoint of lineString is equal to the current point in iteration 1 , so the program do continue and pass to the next iteration

In iteration 2 , we see also the EndPoint of lineString is equal to the current point in this iteration BUT the program did not continue

I don't know why the program did not execute continue when the coordinates of the points are the same !!!

why in the first iteration it's ok then in the second iteration it will not!

I use GEOS C++ 3.4

Any idea, any help please ? is that when I pass to version 3.6 of GEOS, will solve the problem?

  • I don't understand the documentation for `Geometry::equals`, but I observe `Point` has an `equalsExact` function which takes a tolerance. I think you need to use that instead with a non-zero tolerance. – Martin Bonner supports Monica Jan 22 '16 at 10:22
  • thank you very much for your answer, but it did not work. in fact the treatment I am trying to do after the verification of equal points:I retrieves the points that are not equal in CoordinateSéquence thereafter I create a LineString, when I posted the coordinates of points in the sequence and those of line I noticed that the point that was added does not have the same coordinates in the sequence and in the LineString.there is output below: – info_tech_dev Jan 22 '16 at 10:53
  • .there is output (just of end coordinateSequence) below: 30199.36089161384 1064013.1404002085, and there is output(just of endPoint of LineString) after creation of LineString with CoordinateSEquence: 30199.3608916138 1064013.1404002085,there is something strange – info_tech_dev Jan 22 '16 at 11:14
  • Any help please, I tried many methods but none have led to a result! – info_tech_dev Jan 25 '16 at 07:19
  • As a general rule, comparing for equality. Floating point math is not exact. Try with distance: if( ptLine->getStartPoint()->distance( ptGeom->getGeometryN( iCurrentPoint ) ) <= 0.0000000001 ) – Albertino80 Feb 27 '19 at 17:21

0 Answers0