Hello,

 

Thanks for quick reply, here I am attaching the sample code we have created for 
interaction function

 

Thanks,

Ritesh

 

From: geos-devel <geos-devel-boun...@lists.osgeo.org> On Behalf Of Martin Davis
Sent: 23 July 2019 22:54
To: GEOS Development List <geos-devel@lists.osgeo.org>
Subject: Re: [geos-devel] Inconsistent result of "intersection" function

 

It would be easier to see what is going on if you post some code that 
reproduces the problem.

 

 

On Tue, Jul 23, 2019 at 3:35 AM <rites...@intech-dmls.in 
<mailto:rites...@intech-dmls.in> > wrote:

Hi,

We are created polygon and line. After performing the intersection function we 
are getting different values. 

This is the sample code we have implemented using GEOS API (GEOS 3.7.2) .

       Rect = c1.createPolygon(10.78, 10.34, 18.89, 16.64);

      

      line = c1.makeLine(10.78 , 12.34 ,18.89 , 12.34);

 

      point = Rect->intersection (line)

 

1. If given line lies on the polygon we are getting the Expected result.

 

Input: Polygon(10.78, 10.34, 18.89, 16.64);

Input:  makeLine (10.78 , 12.34 ,18.89 , 12.34)

Current  Output from intersection API :  (10.78 , 12.34) (18.89 , 12.34)

Expected Output :  (10.78 , 12.34) (18.89 , 12.34)

 

2.  If given line lies away the polygon we are getting the different result.

Input:  makeLine (8.78 , 12.34 ,20.89 , 12.34)

Current  Output from intersection API:    (11 , 12.3.4) (19 , 12.34)

Expected Output :  (10.78 , 12.34) (18.89 , 12.34)

 

Can you please suggest why this behaviour diffrence is there in API output.

Please let me know any additional information needed from my side.

 

Thanks,

Ritesh

_______________________________________________
geos-devel mailing list
geos-devel@lists.osgeo.org <mailto:geos-devel@lists.osgeo.org> 
https://lists.osgeo.org/mailman/listinfo/geos-devel

#include "createGeometry.h"
#include<iostream>
#include <vector>
#include<geos/geom/Geometry.h>

using namespace std;
using namespace geos::geom;

int main()
{
        createGeometry c1;

        Polygon* boundGeom;

        Geometry* Rect;
        Geometry* line;
        Geometry* point;

        boundGeom = c1.createPolygon(10.78, 10.34, 18.89, 16.64);
        Rect = boundGeom;

        line = c1.makeLine(10.78, 12.34, 18.89, 12.34);

        point = Rect->intersection(line);

        cout <<"Polygon coordinates : \n" << *Rect->getCoordinates() << endl;
        cout <<"Line Coordinates : " << *line->getCoordinates() << endl;
        cout <<"Intersection point : " << *point->getCoordinates() << endl;

        return 0;
}
//header file are used in this program 
#include "createGeometry.h"
#include <iostream>
#include <geos/geom/LinearRing.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/CoordinateArraySequence.h>
#include<geos/geom/Point.h>
#include<geos/geom/Geometry.h>
#include <geos/util/IllegalArgumentException.h>



using namespace std;
using namespace geos::util;
using namespace geos::geom;


createGeometry::createGeometry() //Using constructor we are initializing the 
Precision model
{
        vector<Geometry*>* geoms = new vector<Geometry*>;
        //Creating the Vector object for Geometry
        PrecisionModel* pm = new PrecisionModel(2.0, 0, 0);
        // Define a precision model using 0,0 as the reference origin
        // and 2.0 as coordinates scale.
        global_factory = GeometryFactory::create(pm, -1);
        // Initialize global factory with defined PrecisionModel
        // and a SRID of -1 (undefined).
}

Polygon* createGeometry::createPolygon(double xmin, double ymin, double xmax, 
double ymax)
{
        CoordinateSequence* temp = 
global_factory->getCoordinateSequenceFactory()->create((size_t)0, 0);
        temp->add(Coordinate(xmin, ymin));
        temp->add(Coordinate(xmax, ymin));
        temp->add(Coordinate(xmax, ymax));
        temp->add(Coordinate(xmin, ymax));

        temp->add(Coordinate(xmin, ymin));

        LinearRing* shell = global_factory->createLinearRing(temp);
        return global_factory->createPolygon(shell, NULL);
}

LineString* createGeometry::makeLine(double xmin, double ymin, double xmax, 
double ymax)
{
        unique_ptr<PrecisionModel> pm(new PrecisionModel());
        CoordinateSequence* temp = 
global_factory->getCoordinateSequenceFactory()->create((size_t)0, 0);

        temp->add(Coordinate(xmin, ymin));
        temp->add(Coordinate(xmax, ymax));

        LineString* shell = global_factory->createLineString(temp);

        return shell;
}


createGeometry::~createGeometry()//Deconstructor Definition 
{
        //Automatically deallocate the memory of class object
}
#pragma once
//header file are used in this program 
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Polygon.h>
#include<iostream>
#include <vector>
#include<geos/geom/Geometry.h>
#include <geos/geom/LinearRing.h>


using namespace geos::geom;
using namespace std;

//This class Contains Function and member variable for creating the Geometry 
model
class createGeometry
{
        //Class variable declaration
        //creating the object for GeometryFactory 
        GeometryFactory::Ptr global_factory;


public: //Class function declaration
        createGeometry(); //Creating Constructor 

        ~createGeometry(); //Creating Deconstructor

        Polygon* createPolygon(double xmin, double ymin, double xmax, double 
ymax);
        //This function is used to draw the Boundary Polygon for the given 
values

        LineString* makeLine(double xmin, double ymin, double xmax, double 
ymax);
        //This function used to draw the line by passing the coordinate values

};

_______________________________________________
geos-devel mailing list
geos-devel@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/geos-devel

Reply via email to