Cell.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2018-2025 ISciences, LLC
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#pragma once
#include <geos/geom/Envelope.h>
#include <geos/geom/Geometry.h>
#include <geos/operation/grid/Side.h>
#include <geos/operation/grid/Traversal.h>
namespace geos::operation::grid {
class Cell
{
public:
Cell(double xmin, double ymin, double xmax, double ymax)
: m_box{ xmin, ymin, xmax, ymax }
{
}
explicit Cell(const geom::Envelope& b)
: m_box{ b }
{
}
const geom::Envelope& box() const { return m_box; }
double getWidth() const;
double getHeight() const;
double getArea() const;
void forceExit();
bool isDetermined() const;
double getTraversalLength() const;
double getCoveredFraction() const;
std::unique_ptr<geom::Geometry> getCoveredPolygons(const geom::GeometryFactory&) const;
Traversal& getLastTraversal();
bool take(const geom::CoordinateXY& c, const geom::CoordinateXY* prev_original = nullptr);
private:
std::vector<const std::vector<geom::CoordinateXY>*> getCoordLists() const;
enum class Location
{
INSIDE,
OUTSIDE,
BOUNDARY
};
geom::Envelope m_box;
std::vector<Traversal> m_traversals;
Side side(const geom::CoordinateXY& c) const;
Location location(const geom::CoordinateXY& c) const;
Traversal& traversal_in_progress();
};
}
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::operation::grid::Cell::getCoveredPolygons
std::unique_ptr< geom::Geometry > getCoveredPolygons(const geom::GeometryFactory &) const
geos::operation::grid::Cell::take
bool take(const geom::CoordinateXY &c, const geom::CoordinateXY *prev_original=nullptr)
geos::operation::grid::Cell::getLastTraversal
Traversal & getLastTraversal()
geos::operation::grid::Cell::isDetermined
bool isDetermined() const
geos::operation::grid::Cell::forceExit
void forceExit()
geos::operation::grid::Cell::getCoveredFraction
double getCoveredFraction() const
Return the fraction of this Cell that is covered by a polygon.
geos::operation::grid::Cell::getTraversalLength
double getTraversalLength() const
Return the total length of a linear geometry within this Cell.
geos::operation::grid::Traversal
The Traversal class records the coordinates of a line that are within a grid cell,...
Definition Traversal.h:30