GEOS 3.15.0dev
GridIntersection.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 <memory>
18
19#include <geos/geom/Geometry.h>
20#include <geos/operation/grid/Grid.h>
21#include <geos/operation/grid/Matrix.h>
22
23namespace geos::geom {
24 class Geometry;
25 class LineString;
26}
27
28namespace geos::operation::grid {
29
30class Cell;
31
40class GEOS_DLL GridIntersection
41{
42
43 public:
48 GridIntersection(const Grid<bounded_extent>& raster_grid, const geom::Geometry& g, std::shared_ptr<Matrix<float>> cov = nullptr);
49
54 GridIntersection(const Grid<bounded_extent>& raster_grid, const geom::Envelope& box, std::shared_ptr<Matrix<float>> cov = nullptr);
55
59 std::shared_ptr<Matrix<float>> getResults() { return m_results; }
60
64 static std::unique_ptr<geom::Geometry> subdividePolygon(const Grid<bounded_extent>& p_grid, const geom::Geometry& g, bool includeExterior);
65
66 static std::shared_ptr<Matrix<float>>
67 getIntersectionFractions(const Grid<bounded_extent>& raster_grid, const geom::Geometry& g);
68
69 static std::shared_ptr<Matrix<float>>
70 getIntersectionFractions(const Grid<bounded_extent>& raster_grid, const geom::Envelope& box);
71
82 static geom::Envelope
83 processingRegion(const geom::Envelope& raster_extent, const geom::Geometry& geometry);
84
85 private:
86 void process(const geom::Geometry& g);
87
88 void processLine(const geom::LineString& ls, bool exterior_ring);
89
90 void processRectangularRing(const geom::Envelope& box, bool exterior_ring);
91
92 void addRingResults(size_t i0, size_t j0, const Matrix<float>& areas, bool exterior_ring);
93
94 void setAreal(bool areal);
95
96 static Matrix<float> collectAreas(const Matrix<std::unique_ptr<Cell>>& cells,
97 const Grid<bounded_extent>& finite_ring_grid,
98 const geom::Geometry& g);
99
100 Grid<infinite_extent> m_geometry_grid;
101 std::shared_ptr<Matrix<float>> m_results;
102 bool m_first_geom;
103 bool m_areal;
104};
105
106}
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
Definition LineString.h:66
The GridIntersection class computes and stores information about intersection of a Grid and a Geometr...
Definition GridIntersection.h:41
GridIntersection(const Grid< bounded_extent > &raster_grid, const geom::Envelope &box, std::shared_ptr< Matrix< float > > cov=nullptr)
Compute the fraction of each cell in a rectangular grid that is covered by an Envelope....
static geom::Envelope processingRegion(const geom::Envelope &raster_extent, const geom::Geometry &geometry)
Determines the bounding box of the raster-vector intersection. Considers the bounding boxes of indivi...
static std::unique_ptr< geom::Geometry > subdividePolygon(const Grid< bounded_extent > &p_grid, const geom::Geometry &g, bool includeExterior)
Partition a polygonal geometry by a grid.
GridIntersection(const Grid< bounded_extent > &raster_grid, const geom::Geometry &g, std::shared_ptr< Matrix< float > > cov=nullptr)
Compute the fraction of each cell in a rectangular grid that is covered by a Geometry....
std::shared_ptr< Matrix< float > > getResults()
Return the intersection result matrix.
Definition GridIntersection.h:59
Definition Angle.h:26