47 Commits

Author SHA1 Message Date
Nyall Dawson
3a578d6712 Header update 2024-08-13 20:28:55 +10:00
Nyall Dawson
102874e6d2 Port geos simplify linestring
Add QgsAbstractGeometry::simplifyByDistance, which is a direct
port of GEOS Douglas Peucker algorithm.

This is a trivial algorithm to implement, and we benefit from
avoiding the conversion to/from GEOS geometries.
2024-06-20 05:41:37 +10:00
Nyall Dawson
9626644c7c Add option to remove redundant vertices in QgsAbstractGeometry::snappedToGrid
If opted in, then vertices which form a midpoint of a straight line segment will be removed in the output
2024-06-04 21:33:29 +10:00
Even Rouault
02caeb9db7
Header files: remove all mentions of '\since QGIS 2.' 2024-02-18 20:46:01 +01:00
Loïc Bartoletti
c6eca9361f QgsAbstrcatGeometry and childs: Add fuzzyEqual and fuzzyDistanceEqual. Replaces operator== with fuzzyEqual and uses epsilon=1E-8
The comparisons among QGIS were conducted on coordinates using a fixed epsilon:
specifically, 1e-8 for QgsPoint and the default value for qgsDoubleNear: 4 *
DBL_EPSILON.

Initially, I've standardized its use to 1e-8 universally; it's already
significantly adequate for our Cartesian cases (1e-3 should suffice for many),
potentially fitting just right for geographical contexts.

Furthermore, in response to precision concerns, we're using the fuzzyEqual
and fuzzyDistanceEqual methods. These methods enable users/developers to
compare geometries more easily and with a given precision.

The API remains intact as operator==/equals() have been shifted into fuzzyEqual
(with an epsilon of 1e-8).

To consolidate the code between fuzzyEqual and fuzzyDistanceEqual, helper
functions, fuzzyHelpers, have been introduced following the logic of the
respective segments to be executed.
2024-01-12 07:10:37 +10:00
Jean Felder
d7bdfe000c geometry: Remove duplicated 2d boundingbox logic 2023-09-02 12:38:44 +10:00
bdm-oslandia
40089e6230 qgsabstractgeometry: Add support for box3d intersection 2023-09-02 12:38:44 +10:00
bdm-oslandia
5774acf8d0 qgsabstractgeometry: Add boundingBox3D logic
With this change `QgsAbstractGeometry::calculateBoundingBox()` is now
computed from `QgsAbstractGeometry::calculateBoundingBox3D()`.
2023-09-02 12:38:44 +10:00
Julien Cabieces
22d2a32e22 Fixes #50742 : keep ZM coordinates when simplifying geometry 2023-02-01 18:54:07 +01:00
Juergen E. Fischer
c6008b7ee1 fix MSVC build: reverts fee62e4, dff05dd and e3a77b9484c effectivly
reverting 3fb0f66 (followup #45348)

Using --no-public-is-protected (default on Windows) also works on Linux
and fixes #45331 too
2021-10-21 23:03:48 +02:00
nirvn
ef84e48a09 Run sipify_all.sh 2021-10-12 16:34:05 +10:00
Denis Rouzaud
ec16736306 run sipify 2021-10-12 16:34:05 +10:00
Nyall Dawson
e733b517b3 Split QgsVertexId out to own file, promote type to enum class 2021-10-12 14:54:26 +10:00
Nyall Dawson
e6b39077a2
Promote QgsCoordinateTransform::TransformDirection to enum class, move to Qgis
This enum was forcing an include of qgscoordinatetransform.h within the
widely used qgsabstractgeometry.h header, causing an absolute explosion
of includes of a bunch of very heavy header classes all across QGIS. By
removing the forced include we can avoid a ton of unwanted includes
and make wider use of forward declarations...
2021-09-22 16:40:49 +10:00
Nyall Dawson
01e3e1dddc [api] Move QgsGeometry enums to Qgis, promote to enum classes 2021-08-04 09:54:32 +10:00
Olivier Dalang
527042ee1d [convert to curve] style
# Conflicts:
#	src/app/vertextool/qgsvertextool.cpp
2021-06-19 06:24:13 +10:00
Nyall Dawson
0d768faa43 Add QgsAbstractGeometry::simplifiedTypeRef
Returns a reference to the simplest lossless representation of this geometry,
e.g. if the geometry is a multipart geometry type with a single member geometry,
a reference to that part will be returned.

This method employs the following logic:

- For multipart geometries containing a single part only a direct reference to that part will be returned.
- For compound curve geometries containing a single curve only a direct reference to that curve will be returned.

This method returns a reference only, and does not involve any geometry cloning.
2021-05-24 10:11:37 +10:00
Nyall Dawson
1c11a91811 Add QgsGeometry::normalize()
A port of the equivalent method from GEOS, but with added support
for curved geometries and M values

Reorganizes the geometry into a normalized form (or "canonical" form).

Polygon rings will be rearranged so that their starting vertex is
the lower left and ring orientation follows the right hand rule, collections
are ordered by geometry type, and other normalization techniques are applied.
The resultant geometry will be geometrically equivalent to the original geometry.
2021-04-29 05:33:25 +10:00
Nyall Dawson
e3a73a1ac5 Add method to "scroll" the vertices of a closed curve geometry,
so that a particular vertex is the first one
2021-04-29 05:33:25 +10:00
Nyall Dawson
417d444429 Add api to condense compound curves by merging adjacent parts of the
same type to single parts
2021-04-28 11:15:17 +10:00
Nyall Dawson
9c53fb8635 Add QgsAbstractGeometry::compareTo( QgsAbstractGeometry*)
Allows for comparison of geometry objects, e.g. to allow for stable
sorting of them.

Ported from the GEOS equivalent method, but with addition of support
for M values and curved geometry types
2021-04-27 21:13:22 +10:00
Nyall Dawson
729792d981 Add QgsCurve::indexOf to retrieve index of a specified QgsPoint
within the curve
2021-04-27 11:26:49 +10:00
Denis Rouzaud
ba8a445850 run sipify 2021-03-22 21:13:52 +01:00
Nyall Dawson
7c410120e3 Super-optimised version of geometry bounding box intersects test
Apply some fancy logic to make this test as cheap as possible
to run
2021-03-12 05:46:14 +10:00
Nyall Dawson
afccd31720 Add method to add a linestring to compound curves where we extend
the existing final part if it's a linestring and the newly added
curve is also a linestring, instead of adding a whole new curve
2021-03-05 04:28:31 +10:00
Nyall Dawson
6f4b32f658 Create class QgsAbstractGeometryTransformer, which can be used
to transform the vertices of a QgsAbstractGeometry

E.g.

        class Transformer(QgsAbstractGeometryTransformer):

            def transformPoint(self, x, y, z, m):
                return True, x * 2, y + 1, z, m

        transformer = Transformer()
        g = QgsGeometry.fromWkt('LineString(3 0, 10 0, 10 10)')
        g.get().transform(transformer)
        print(g.asWkt()) # 'LineString (6 1, 20 1, 20 11)'
2021-02-08 12:12:53 +10:00
Loïc Bartoletti
0f292cfb36
[API] Improve isValid method for curve type 2020-12-02 06:32:54 +10:00
Even Rouault
7ac4b51885 Add QgsGeometry::wkbSize() 2020-10-19 09:25:10 +10:00
Nyall Dawson
fe5615ea44 Hold the GIL for more geometry related methods 2020-09-18 11:50:27 +10:00
Nyall Dawson
f496173bd7 Fix messy doxygen blocks which mess with sipify script
Fixes #38291
2020-08-20 17:01:35 +10:00
Denis Rouzaud
044a05d828 run sipify 2020-06-19 08:47:23 +10:00
Nyall Dawson
d3a54eed6f Add flags to control geometry to WKB export behavior
With initial flag to force conversion of triangle types to polygons
2020-06-11 05:32:26 +10:00
Alessandro Pasotti
bbd836f4d3 Update tests for geometry classes 2019-05-02 13:52:46 +02:00
Alessandro Pasotti
63711510b6 Dear Qt, I love you but ...
... you are too slow and QJson API is so ugly.

Now using this wonderful json lib:
https://github.com/nlohmann/json

Results in release mode (QJson tests are not shown but
QJson was even slower than string concat).

PASS   : TestQgsJsonUtils::testExportAttributesJson(Use json)
RESULT : TestQgsJsonUtils::testExportAttributesJson():"Use json":
     0.0022 msecs per iteration (total: 75, iterations: 32768)
PASS   : TestQgsJsonUtils::testExportAttributesJson(Use old string concat)
RESULT : TestQgsJsonUtils::testExportAttributesJson():"Use old string concat":
     0.0032 msecs per iteration (total: 54, iterations: 16384)
PASS   : TestQgsJsonUtils::testExportFeatureJson(Use json)
RESULT : TestQgsJsonUtils::testExportFeatureJson():"Use json":
     0.011 msecs per iteration (total: 96, iterations: 8192)
PASS   : TestQgsJsonUtils::testExportFeatureJson(Use old string concat)
RESULT : TestQgsJsonUtils::testExportFeatureJson():"Use old string concat":
     0.015 msecs per iteration (total: 64, iterations: 4096)
PASS   : TestQgsJsonUtils::testExportGeomToJson(Use json)
RESULT : TestQgsJsonUtils::testExportGeomToJson():"Use json":
     0.76 msecs per iteration (total: 98, iterations: 128)
PASS   : TestQgsJsonUtils::testExportGeomToJson(Use old string concat)
RESULT : TestQgsJsonUtils::testExportGeomToJson():"Use old string concat":
     0.85 msecs per iteration (total: 55, iterations: 64)
PASS   : TestQgsJsonUtils::cleanupTestCase()
2019-04-18 17:04:30 +02:00
Alessandro Pasotti
be8822ed8b Precision and 3d 2019-04-16 14:00:59 +02:00
Alessandro Pasotti
6967a21882 toJsonV2 2019-04-16 14:00:59 +02:00
Nyall Dawson
7d648e5b51 Improve Python __repr__ handling for null geometries
Also avoid massive long __repr__ strings for complex geometries,
as these can flood the Python console (and first aid plugin),
and aren't useful for debugging anyway.

Refs #14640
2018-12-18 18:11:22 +10:00
Even Rouault
7e81226b51 Replace toUtf8().data() by toUtf8().constData()
All your uses of toUtf8().data() actually just need a const char*
So use constData() that is semantically more correct, and documented
to be faster.

From http://doc.qt.io/qt-5/qbytearray.html#data
"For read-only access, constData() is faster because it never
causes a deep copy to occur."
2018-10-07 07:23:42 +10:00
Nyall Dawson
c6a91dab09 [FEATURE] Use native interpolate point method instead of GEOS method
Because:
- Exactly follows curves and doesn't require segmentizing input geometry
- Also interpolates z/m values if they are present in input geometry
- Is faster
2018-08-15 14:01:59 +10:00
Nyall Dawson
513bcb68e4 [FEATURE] New geometry API call to return a curve substring
Returns a new curve representing a substring of a curve, from
a start distance and end distance.

If z or m values are present, the output z and m will be interpolated using
the existing vertices' z or m values.

Handles curved geometries without loss.
2018-08-15 14:01:59 +10:00
Denis Rouzaud
ff1988f11d Python __repr__ test output 2018-06-19 13:55:53 -04:00
Denis Rouzaud
763dfd2998 use SIP to define Python __repr__ rather than injections
because it's a bit more clever!
2018-06-19 07:58:26 -04:00
Denis Rouzaud
cc3e29bcc2 add __repr__ for more geometry classes and add test 2018-06-19 07:02:17 -04:00
Nyall Dawson
f092c7edb7 Add method to filter vertices for geometries in place, by providing a custom filter function 2018-05-30 05:01:40 +10:00
Nyall Dawson
f8bc97030b Remove extra space added before first line of docstring 2018-05-28 08:22:11 +10:00
Nyall Dawson
6165e4c8d6 Add some SIP_THROW( QgsCsException ) annotations
Incomplete, but allows proper QgsCsException catching
for these methods
2018-05-23 07:55:30 +10:00
Denis Rouzaud
7df2593caf move auto generated sip file in dedicated folder 2018-05-14 10:23:37 -04:00