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
43 const geom::Envelope& box() const { return m_box; }
44
45 double getWidth() const;
46
47 double getHeight() const;
48
49 double getArea() const;
50
53 void forceExit();
54
57 bool isDetermined() const;
58
60 double getTraversalLength() const;
61
63 double getCoveredFraction() const;
64
67 std::unique_ptr<geom::Geometry> getCoveredPolygons(const geom::GeometryFactory&) const;
68
72
82 bool take(const geom::CoordinateXY& c, const geom::CoordinateXY* prev_original = nullptr);
83
84 private:
85 std::vector<const std::vector<geom::CoordinateXY>*> getCoordLists() const;
86
87 enum class Location
88 {
89 INSIDE,
90 OUTSIDE,
91 BOUNDARY
92 };
93
94 geom::Envelope m_box;
95
96 std::vector<Traversal> m_traversals;
97
98 Side side(const geom::CoordinateXY& c) const;
99
100 Location location(const geom::CoordinateXY& c) const;
101
104 Traversal& traversal_in_progress();
105};
106
107}
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:70
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
bool take(const geom::CoordinateXY &c, const geom::CoordinateXY *prev_original=nullptr)
Traversal & getLastTraversal()
double getCoveredFraction() const
Return the fraction of this Cell that is covered by a polygon.
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:30