GEOS 3.15.0dev
Cell.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2018-2025 ISciences, LLC
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/geom/Envelope.h>
18#include <geos/geom/Geometry.h>
19
20#include <geos/operation/grid/Side.h>
21#include <geos/operation/grid/Traversal.h>
22
23namespace geos::operation::grid {
24
29class Cell
30{
31
32 public:
33 Cell(double xmin, double ymin, double xmax, double ymax)
34 : m_box{ xmin, ymin, xmax, ymax }
35 {
36 }
37
38 explicit Cell(const geom::Envelope& b)
39 : m_box{ b }
40 {
41 }
42
44 void getEdgePoints(Side s, std::vector<geom::CoordinateXY>& points) const;
45
46 const geom::Envelope& box() const { return m_box; }
47
48 double getWidth() const;
49
50 double getHeight() const;
51
52 double getArea() const;
53
56 void forceExit();
57
60 bool isDetermined() const;
61
63 double getTraversalLength() const;
64
66 double getCoveredFraction() const;
67
70 std::unique_ptr<geom::Geometry> getCoveredPolygons(const geom::GeometryFactory&) const;
71
75
90 bool take(const geom::CoordinateXY& c, const geom::CoordinateXY* prev_original, bool exitOnBoundary, const void* parentage);
91
92 private:
93 std::vector<const Traversal*> getTraversals() const;
94
95 enum class Location
96 {
97 INSIDE,
98 OUTSIDE,
99 BOUNDARY
100 };
101
102 geom::Envelope m_box;
103
104 std::vector<Traversal> m_traversals;
105
106 Side getSide(const geom::CoordinateXY& c) const;
107
108 Location getLocation(const geom::CoordinateXY& c) const;
109
112 Traversal& traversal_in_progress();
113};
114
115}
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:71
The Cell class stores information about the spatial extent of a Grid cell and any cases where a line ...
Definition Cell.h:30
std::unique_ptr< geom::Geometry > getCoveredPolygons(const geom::GeometryFactory &) const
Traversal & getLastTraversal()
double getCoveredFraction() const
Return the fraction of this Cell that is covered by a polygon.
void getEdgePoints(Side s, std::vector< geom::CoordinateXY > &points) const
Get all points that fall on the specified side of this cell.
bool take(const geom::CoordinateXY &c, const geom::CoordinateXY *prev_original, bool exitOnBoundary, const void *parentage)
double getTraversalLength() const
Return the total length of a linear geometry within this Cell.
The Traversal class records the coordinates of a line that are within a grid cell,...
Definition Traversal.h:31