It's been years since I used C++ and so I'm very rusty. I'm trying to test out the Geos library, but I'm unable to get a simple Hello World example to compile
https://libgeos.org/usage/download/
This is what I tried:
- I downloaded and extracted the files
- Created a new C++ project in Visual Studio
- Added the headers folder into the Visual Studio Include Directories for the project.
Then I tried to use the library in my main.cpp:
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/LinearRing.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
#include <iostream>
#include <memory>
geos::geom::Polygon * MakeBox(double xmin, double ymin, double xmax, double ymax) {
std::unique_ptr<geos::geom::PrecisionModel> pm(new geos::geom::PrecisionModel());
geos::geom::GeometryFactory::unique_ptr factory = geos::geom::GeometryFactory::create(pm.get(), -1);
geos::geom::CoordinateSequence* temp = factory->getCoordinateSequenceFactory()->create((std::size_t)0, 0);
temp->add(geos::geom::Coordinate(xmin, ymin));
temp->add(geos::geom::Coordinate(xmin, ymax));
temp->add(geos::geom::Coordinate(xmax, ymax));
temp->add(geos::geom::Coordinate(xmax, ymin));
//Must close the linear ring or we will get an error:
//"Points of LinearRing do not form a closed linestring"
temp->add(geos::geom::Coordinate(xmin, ymin));
geos::geom::LinearRing* shell = factory->createLinearRing(temp);
//NULL in this case could instead be a collection of one or more holes
//in the interior of the polygon
return factory->createPolygon(shell, NULL);
}
int main() {
geos::geom::Polygon* box = MakeBox(0, 0, 10, 10);
std::cout << box->getArea() << std::endl;
delete box; //Important to avoid memory leaks
}
I'm getting multiple errors, but they all seem to indicate that the library is not loaded correctly
Severity Code Description Project File Line Suppression State Error (active) E0135 class "geos::geom::GeometryFactory" has no member "unique_ptr" TestGeos C:\TestGeos\TestGeos.cpp 15
What am I missing in order to use the library?