Convert Figma logo to code with AI

libgeos logogeos

Geometry Engine, Open Source

1,164
352
1,164
95

Top Related Projects

1,702

PROJ - Cartographic Projections and Coordinate Transformations Library

4,773

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.

1,937

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.

10,326

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)

1,682

PostGIS spatial database extension to PostgreSQL [mirror]

Quick Overview

GEOS (Geometry Engine - Open Source) is a C++ library for computational geometry with a focus on algorithms used in geographic information systems (GIS). It provides a wide range of spatial operations and predicates, including topology operations, buffer calculations, and spatial analysis functions. GEOS is widely used in GIS software and serves as the geometry engine for many popular geospatial libraries and applications.

Pros

  • Comprehensive set of geometric algorithms and operations
  • High performance and efficiency for complex spatial calculations
  • Well-established and widely adopted in the GIS community
  • Supports various coordinate systems and geometric data types

Cons

  • Steep learning curve for beginners due to its extensive API
  • Limited documentation for some advanced features
  • C++ codebase may be challenging for developers more familiar with higher-level languages
  • Occasional inconsistencies in method naming conventions

Code Examples

  1. Creating and manipulating geometries:
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Point.h>

using namespace geos::geom;

GeometryFactory::Ptr factory = GeometryFactory::create();
Coordinate coord(10.0, 20.0);
Point* point = factory->createPoint(coord);
  1. Performing spatial operations:
#include <geos/geom/Geometry.h>
#include <geos/operation/buffer/BufferOp.h>

Geometry* buffer = point->buffer(5.0);
bool intersects = buffer->intersects(otherGeometry);
  1. Working with WKT (Well-Known Text):
#include <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>

geos::io::WKTReader reader;
Geometry* geom = reader.read("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))");

geos::io::WKTWriter writer;
std::string wkt = writer.write(geom);

Getting Started

To use GEOS in your C++ project:

  1. Install GEOS using your package manager or build from source.
  2. Include the necessary headers in your C++ file.
  3. Link against the GEOS library when compiling.

Example compilation command:

g++ -o my_program my_program.cpp -lgeos

Basic usage in C++:

#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Point.h>
#include <iostream>

int main() {
    geos::geom::GeometryFactory::Ptr factory = geos::geom::GeometryFactory::create();
    geos::geom::Point* point = factory->createPoint(geos::geom::Coordinate(1.0, 2.0));
    std::cout << "Point created: " << point->toString() << std::endl;
    return 0;
}

Competitor Comparisons

1,702

PROJ - Cartographic Projections and Coordinate Transformations Library

Pros of PROJ

  • Broader focus on coordinate transformations and projections
  • More extensive documentation and user guides
  • Active development with frequent releases

Cons of PROJ

  • Steeper learning curve for beginners
  • Less specialized in geometric operations compared to GEOS

Code Comparison

PROJ (coordinate transformation):

PJ *P;
P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "EPSG:4326", "EPSG:3857", NULL);
proj_trans(P, PJ_FWD, coord);
proj_destroy(P);

GEOS (geometric operation):

GEOSGeometry* geom1 = GEOSGeomFromWKT("POINT(0 0)");
GEOSGeometry* geom2 = GEOSGeomFromWKT("POINT(1 1)");
GEOSGeometry* buffer = GEOSBuffer(geom1, 2.0, 8);
GEOSGeometry* intersection = GEOSIntersection(buffer, geom2);

PROJ is more focused on coordinate transformations and map projections, while GEOS specializes in geometric operations and spatial analysis. PROJ offers a wider range of projection-related functionality, making it more suitable for tasks involving coordinate system conversions. GEOS, on the other hand, excels in geometric computations and spatial relationships between objects. The choice between the two depends on the specific requirements of your geospatial project.

4,773

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.

Pros of GDAL

  • Broader functionality: GDAL supports a wide range of geospatial data formats and operations, including raster and vector data processing
  • More extensive API: Offers bindings for multiple programming languages, including Python, Java, and C++
  • Active development: Regular updates and a large community of contributors

Cons of GDAL

  • Steeper learning curve: Due to its extensive functionality, GDAL can be more complex to use for beginners
  • Larger footprint: GDAL has a larger codebase and installation size compared to GEOS

Code Comparison

GDAL example (Python):

from osgeo import gdal
dataset = gdal.Open("example.tif")
band = dataset.GetRasterBand(1)
data = band.ReadAsArray()

GEOS example (C++):

#include <geos/geom/Geometry.h>
#include <geos/io/WKTReader.h>
geos::io::WKTReader reader;
std::unique_ptr<geos::geom::Geometry> geom(reader.read("POINT(0 0)"));

GDAL is more suitable for projects requiring diverse geospatial data handling, while GEOS is focused on geometric operations and may be preferable for simpler geometry-centric tasks.

1,937

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.

Pros of JTS

  • Written in Java, offering better integration with Java-based applications
  • More extensive documentation and examples available
  • Includes additional algorithms and operations not present in GEOS

Cons of JTS

  • Generally slower performance compared to GEOS
  • Limited support for non-Java environments
  • Larger memory footprint due to Java's overhead

Code Comparison

GEOS (C++):

#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>

geos::geom::GeometryFactory::Ptr factory = geos::geom::GeometryFactory::create();
geos::geom::Geometry* geom = factory->createPoint(geos::geom::Coordinate(1, 1));

JTS (Java):

import org.locationtech.jts.geom.*;

GeometryFactory factory = new GeometryFactory();
Point point = factory.createPoint(new Coordinate(1, 1));

Both libraries provide similar functionality for creating and manipulating geometric objects. GEOS, being C++-based, offers better performance and broader language bindings, while JTS provides a more Java-friendly API with extensive documentation. The choice between them often depends on the specific project requirements and the primary development language.

10,326

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)

Pros of QGIS

  • Comprehensive GIS software with a full-featured GUI
  • Extensive plugin ecosystem for additional functionality
  • Supports a wide range of data formats and geospatial operations

Cons of QGIS

  • Larger codebase and more complex architecture
  • Steeper learning curve for developers
  • Higher resource requirements for installation and usage

Code Comparison

GEOS (C++):

#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>

geos::geom::GeometryFactory::Ptr factory = geos::geom::GeometryFactory::create();
geos::geom::Geometry* point = factory->createPoint(geos::geom::Coordinate(1, 1));

QGIS (Python):

from qgis.core import QgsGeometry, QgsPointXY

point = QgsGeometry.fromPointXY(QgsPointXY(1, 1))

Summary

GEOS is a lightweight C++ library for geometric operations, while QGIS is a full-featured GIS application with a GUI. GEOS focuses on core geometry algorithms, whereas QGIS provides a complete GIS ecosystem with visualization, analysis, and data management capabilities. GEOS is more suitable for integration into other software, while QGIS is better for end-users working directly with geospatial data.

1,682

PostGIS spatial database extension to PostgreSQL [mirror]

Pros of PostGIS

  • Integrates directly with PostgreSQL, providing spatial database capabilities
  • Offers a wider range of geospatial functions and analysis tools
  • Supports raster data and topology models

Cons of PostGIS

  • Requires PostgreSQL installation and setup
  • Higher learning curve due to more complex functionality
  • Potentially slower for simple geometric operations

Code Comparison

GEOS (C++):

#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>

auto factory = geos::geom::GeometryFactory::create();
auto point = factory->createPoint(geos::geom::Coordinate(1, 1));

PostGIS (SQL):

CREATE TABLE points (id SERIAL PRIMARY KEY, geom GEOMETRY(Point, 4326));
INSERT INTO points (geom) VALUES (ST_SetSRID(ST_MakePoint(1, 1), 4326));

Summary

GEOS is a lightweight C++ library for geometric operations, while PostGIS is a comprehensive spatial database extension for PostgreSQL. PostGIS offers more advanced geospatial functionality but requires a PostgreSQL setup. GEOS is simpler to use for basic geometric operations but lacks the full spatial database capabilities of PostGIS.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

GEOS -- Geometry Engine, Open Source

GEOS is a C++ library for performing operations on two-dimensional vector geometries. It is primarily a port of the JTS Topology Suite Java library. It provides many of the algorithms used by PostGIS, the Shapely package for Python, the sf package for R, and others.

More information is available the project homepage.

The official Git repository is at GitHub.

Build Status

CIStatusCIStatusCIStatus
GitHubgithubBessiebessieDebbiedebbie
GitLab CIgitlab-ciBessie32bessie32Winniewinnie
BerrieberrieDroniedronie
Berrie64berrie64

Community Resources

Build/Install

See the INSTALL file.

Reference Docs

See also the C API tutorial and the C++ API tutorial. There are code examples in the code repository.

Client Applications

Using the C interface

GEOS promises long-term stability of the C API. In general, successive releases of the C API may add new functions but will not remove or change existing types or function signatures. The C library uses the C++ interface, but the C library follows normal ABI-change-sensitive versioning, so programs that link only against the C library should work without relinking when GEOS is upgraded. For this reason, it is recommended to use the C API for software that is intended to be dynamically linked to a system install of GEOS.

The geos-config program can be used to determine appropriate compiler and linker flags for building against the C library:

CFLAGS += `geos-config --cflags`
LDFLAGS += `geos-config --ldflags` -lgeos_c

All functionality of the C API is available through the geos_c.h header file.

Documentation for the C API is provided via comments in the geos_c.h header file. C API usage examples can be found in the GEOS unit tests and in the source code of software that uses GEOS, such as PostGIS and the sf package for R.

Using the C++ interface

The C++ interface to GEOS provides a more natural API for C++ programs, as well as additional functionality that has not been exposed in the C API. However, developers who decide to use the C++ interface should be aware that GEOS does not promise API or ABI stability of the C++ API between releases. Breaking changes in the C++ API/ABI are not typically announced or included in the NEWS file.

The C++ library name will change on every minor release.

The geos-config program can be used to determine appropriate compiler and linker flags for building against the C++ library:

CFLAGS += `geos-config --cflags`
LDFLAGS += `geos-config --ldflags` -lgeos

A compiler warning may be issued when building against the C++ library. To remove the compiler warning, define USE_UNSTABLE_GEOS_CPP_API somewhere in the program.

Commonly-used functionality of GEOS is available in the geos.h header file. Less-common functionality can be accessed by including headers for individual classes, e.g. #include <geos/algorithm/distance/DiscreteHausdorffDistance.h>.

#include <geos.h>

C++ usage examples can be found in examples.

Using other languages

GEOS has bindings in many languages, see the bindings page.

Documentation

API documentation can be generated using Doxygen. Documentation is not included in the default build. To build the documentation, run:

cmake -DBUILD_DOCUMENTATION=YES
cmake --build . --target docs

Style

To format your code into the desired style, use the astyle version included in source tree:

tools/astyle.sh <yourfile.cpp>

Testing

See documentation in tests/README.md.

Tools