107 Commits

Author SHA1 Message Date
Matthias Kuhn
619562ec3d More dox 2019-08-02 13:12:18 +02:00
Matthias Kuhn
60f4bc56e8 Add QgsWkbTypes::curveType method 2019-08-02 09:33:47 +02:00
lbartoletti
794a8efc81 Fixes empty WKT. Fixes #20753, Fixes #19190, Fixes #20754 (#9645)
* Fixes empty WKT. Fixes #20753, Fixes #19190, Fixes #20754
2019-07-30 09:34:53 +02:00
Nyall Dawson
3174d692b1 Add a reserve method to QgsGeometryCollection
Attempts to allocate memory for at least the specified number of geometries.

If the number of geometries is known in advance, calling this function
prior to adding geometries will prevent reallocations and memory fragmentation.
2019-07-24 16:41:37 +10:00
Ismail Sunni
edd921c428 [FEATURE] Measurement tool in 3D map view (#30299)
* Add measurement tool bar.

* Add class for measure line.

* Get coordinate of clicked point.

* Add clicked point to string line.

* Store clicekd points to layer.

* Try to render the measurement line.

* Render the measurement line (with some problems).

* Store points in vector.

* Make identify and measure tool exlusive to each other.

* Add measurement dialog.

* Fix only one action must active.

* Some code suggestion from Martin.

* Revert code to show the line.

* Show segment length and the total.

* Implement close dialog means restart 3d measurement.

* Add new button.

* Add unit combo box.

* Fix shadowing private member of class.

* Add slot to combo box unit changes.

* Hide ellipsoid and cartesian radio button.

* Add measure line for QgsPoint.

* Add unit changes feature.

* Add help (pointed to 2D measurement tool).

* Add finish measurement using right click.

* Remove keypress event, it does not make sense.

* Add remove-last-point with middle button.

* Add crsChanged event.

* Remove confusing tooltip.

* Add pan (camera control) action tool for clear state of 3d map tool.

* Change 3D identify tool cursor.

* Fix distance 2D to 3D.

* Remove unclear method.

* Add unit test for measureLine3D.

* Add 3D measurement setting.

* Add header.

* Make extra 3D renderers refresh the scene when they are updated

+ update the 3D renderer every time the measurement line layer is modified

* Set Altitude clamping to absolute.

* Remove options for 3D measurement line.

* Remove help button in 3D measurement dialog.

* Merge duplicate code for handle clicked position.

* Use color for 3d measure line from 2d one.

* Remove unneeded reimplementation method.

* Remove 2D canvas reference.

* Unify update measurement layer.

Use local variable for feature and line

* Create measurement layer once.

* Use data provider to change the geometry.

* Add length3D for QgsLineString.

* Simplify distance calculation and presentation. Remove QgsDistanceArea measurement.

* Descaled z value based on the terrain vertical scale.

* Remove line when tool is deactivated.

* Enable changing the line color from setting, but after re-activation.

* Update color of measurement line after saving option.

* Remove debug message.

* Remove 3D length calculation from distancearea.

* Handle 2D case for length3D, more unit test, and docstring.

* Fix typos.

* Addressing Martin's and Nyall's review.

* Remove setMeasurement to avoid confussion.
2019-07-08 15:21:00 +02:00
Juergen E. Fischer
e9a80d6799 fix build 2019-05-12 17:19:50 +02: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
a809625be9 Add default precision value 2019-04-16 19:26:10 +02:00
Alessandro Pasotti
64fdbe3d76 Added tests and doxy 2019-04-16 15:17:25 +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
1dc447e1f2 Dox++ 2019-03-21 12:44:16 +10:00
Nyall Dawson
75697d77ed Cache validity check results
For non-point geometry subclasses (points are always valid!) we
now cache the results of a geometry validity check. Subsequent
checks utilise the cached result wherever possible.

Because QgsGeometry/QgsFeature objects are implicitly shared, this
means that we avoid a *lot* of duplicate validity checks as
features and geometries are thrown around during processing model
execution.
2019-03-01 08:06:31 +10:00
Nyall Dawson
107b48a430 Add NULLPTR macro for use in doxygen comments
For the c++ api dox this expands to "\c nullptr" (the
\c directive indicates a code literal value), and for sipify/Python
it expands to ``None`` (`` is sphinx annotation for literal values)

Makes for nicer dox for both c++ and Python!
2019-02-27 09:41:11 +10:00
Nyall Dawson
b6d66becab Sipify 2019-02-27 09:41:11 +10:00
Nyall Dawson
4e04d02293 By default, validity check should treat ring self intersections as invalid
We use the OGC definition of validity to ensure consistent results
with PostGIS, GDAL, etc

Fixes #16418, fixes #21336
2019-02-27 06:05:26 +10:00
Nyall Dawson
35f613d45e Avoid firing up a thread for blocking GEOS based validity checks
It's an unnecessary expense. Also fix duplicate code.
2019-02-27 06:05:26 +10:00
Nyall Dawson
6dbe4ee5fb Add QgsGeometry::isGeosValid option to ignore self-touching rings 2019-02-27 06:05:26 +10:00
Matthias Kuhn
09407c1258
Merge pull request #9128 from m-kuhn/todo-qgis-4
Move QGIS 3 todos to QGIS 4
2019-02-08 08:02:17 +01:00
Matthias Kuhn
2fb37042a5
Fix TODO and docstrings 2019-02-07 14:36:43 +01:00
Matthias Kuhn
32b6599df0
Merge pull request #9074 from m-kuhn/til
Deprecate QgsGeometry::set for usage in Python
2019-02-07 09:07:14 +01:00
Matthias Kuhn
2400050878
Deprecate for sip 2019-02-06 13:09:23 +01:00
Nyall Dawson
384d310233 Minor improvements to PyQGIS returns for SIP_OUT params 2019-02-05 04:55:34 +11:00
Matthias Kuhn
612576ca8e
Deprecate QgsGeometry::set for usage in Python
When a new QgsAbstractGeometry is set on a geometry object, the previous child is deleted.
If the previous object was constructed by Python, it's wrapper will still be alive for
as long as the QgsGeometry is alive. If a new QgsAbstractGeometry is constructed at the same
memory address as the old one, the wrapper will be reused with wrong type (and other)
information, leading to all kind of weird issues.

See also https://www.riverbankcomputing.com/pipermail/pyqt/2019-January/041251.html
2019-02-03 19:47:01 +01:00
Pierre-Eric Pelloux-Prayer
08634c4e6f fix style 2019-01-23 14:59:19 +01:00
Pierre-Eric Pelloux-Prayer
f1760ee56b Remove include "qgsapplication.h" from qgswkbptr.h
qgswkbptr.h is included indirectly by a large number of source files.
So this commit does the following:
  - remove #include "qgsapplication.h" from qgswkbptr.h, and copy-paste the swap_endian
    function where it's used.
  - add the missing #include "qgsapplication.h" in other files

The rationale for this change is:
  - qgswkbptr.h doesn't really needs QgsApplication, since it only used swap_endian.
    We don't need to add a fake dependency on QgsApplication on every (indirect) "includers"
    of qgswkbptr.h
 - qgsapplication.h depends on qgsconfig.h which itself changes quite often (on every git op
   at least). Before this change, a 'git commit' would trigger a rebuild of about 3500 files.
   With this change we're down to ~700.
2019-01-22 21:45:38 +01:00
lbartoletti
edadcb773f Refactoring of rectangle maptools
Adds a new geometry class QgsQuadrilateral, for 4 sided geometries.
2019-01-15 10:24:16 +11:00
Raymond Nijssen
0ba9a326ec Add API to calculate innerTangents for 2 circles 2019-01-14 05:27:19 +10:00
Nyall Dawson
938adb8c17 [api] Add PyQGIS helpers to QgsGeometry.asMultiPoint(), asMultiPolyline()
and asMultiPolygon()

- raise ValueError when these methods are called with null geometries
- raise TypeError when these methods are called with incompatible
geometry types, instead of silently returning empty lists
2019-01-11 21:31:14 +10:00
Denis Rouzaud
166e952c33 run sipify 2018-12-19 08:04:27 -04:00
Denis Rouzaud
6bb0720bb7
Merge pull request #8708 from 3nids/sipify_sip_out
[sipify] handles SIP_OUT arguments
2018-12-18 22:08:42 -04:00
Denis Rouzaud
c20b5b2f75 fix multine removal for SIP_PYARGREOMVEq 2018-12-18 21:54:38 -04:00
Denis Rouzaud
32e844f9f8 fix multiline comments on out params 2018-12-18 17:29:04 -04:00
Denis Rouzaud
edfb7e1465 run sipify 2018-12-18 17:17:25 -04:00
Nyall Dawson
514c5e2ac5 [api] Raises ValueError and TypeError exceptions when QgsGeometry.asPolygon()
is called on non-single-polygon geometries

Previously we would just return an empty list when geometries of invalid
type were used, but this is dangerous and we are safer to explicitly
raise errors preventing use of asPolygon() with incompatible geometry types.
2018-12-19 05:22:11 +10: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
Nyall Dawson
d1e9ce1f69 [api] Raises ValueError and TypeError exceptions when QgsGeometry.asPolyline()
is called on non-single-line geometries

Previously we would just return an empty list when geometries of invalid
type were used, but this is dangerous and we are safer to explicitly
raise errors preventing use of asPolyline() with incompatible geometry types.
2018-12-18 04:38:42 +10:00
Nyall Dawson
0ca9777755 [api] Raises ValueError and TypeError exceptions when QgsGeometry.asPoint()
is called on non-single-point geometries

Previously we would just return QgsPointXY(0,0) when geometries of invalid
type were used, but this is dangerous and we are safer to explicitly
raise errors preventing use of asPoint() with incompatible geometry types.
2018-12-15 07:40:33 +10:00
Nyall Dawson
44fbb89450 [API] Throw IndexError on some QgsCurvePolygon methods when invalid
interior ring index is requested
2018-12-11 09:46:22 +10:00
Nyall Dawson
e6ec1ec53e [FEATURE][API] Add iterator for QgsGeometryCollection
Iterates over the geometries in the collection, allowing this type
of code:

  gc = QgsGeometryCollection()
  gc.fromWkt('GeometryCollection( Point(1 2), Point(11 12), LineString(33 34, 44 45))')
  for part in gc:
    print(part.asWkt())
2018-12-07 05:51:27 +10:00
Nyall Dawson
e23527bf92 Use TypeHint annotation to indicate correct return type when sip code returns SIP_PYOBJECT
Provides correct return type hints to IDEs (and hopefully PyQGIS docs too!)
2018-12-07 05:51:27 +10:00
Nyall Dawson
4bba8ae64d [FEATURE][API] Add some nice PyQGIS API for working with geometry collections
- Calling removeGeometry with an invalid index will now raise an IndexError
- Calling collection[0] will return the first geometry in the collection,
collection[1] the second, etc. And negative indices return from the end
of the collection, so collection[-1] returns the last geometry in the collection.
- Geometries can be deleted by calling `del collection[1]` (deletes the
second geometry from the collection). Also supports negative indices
to count from the end of the collection.
2018-12-07 05:51:27 +10:00
Nyall Dawson
f595d53d0a Negative indices count from back of linestring 2018-11-27 09:29:13 +10:00
Nyall Dawson
1e5479964f [FEATURE][API] Add some nice PyQGIS methods and exceptions to QgsLineString
- len(QgsCurve) returns number of points in curve
- raise IndexErrors when calling pointN, xAt, yAt, zAt, mAt, setXAt, setYAt,
setMAt, setZAt with invalid vertex indices
- Add [] getter for retrieving specific vertices, eg. ls[0] returns QgsPoint(...)
- Add [] setter for setting specific (existing) vertices, e.g. ls[1] = QgsPoint(1,2)
- Add del support for removing vertices, e.g. del ls[1] removes the second vertex
2018-11-27 09:29:13 +10:00
Denis Rouzaud
d1d3a51efb
Merge pull request #8429 from lbartoletti/extendMapTool
[needs-docs][FEATURE] Trim/extend
2018-11-21 06:36:08 +01:00
Nyall Dawson
a22422c4bf [FEATURE][API] Add parts iterators to QgsGeometry
This allows easy iteration over all the parts of a geometry,
regardless of the geometry's type. E.g.

geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
  print(part.asWkt())

geometry = QgsGeometry.fromWkt( 'LineString( 0 0, 10 10 )' )
for part in geometry.parts():
  print(part.asWkt())

There are two iterators available. QgsGeometry.parts() gives
a non-const iterator, allowing the parts to be modified in place:

geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.parts():
   part.transform(ct)

For a const iteration, calling .const_parts() gives a const
iterator, which cannot edit the parts but avoids a potentially expensive
QgsGeometry detach and clone

geometry = QgsGeometry.fromWkt( 'MultiPoint( 0 0, 1 1, 2 2)' )
for part in geometry.const_parts():
   print(part.x())
2018-11-20 05:05:37 +11:00
Nyall Dawson
f5a6aef55f Raise IndexError in PyQGIS when calling geometryN on a collection
with an invalid geometry index

And add len operator to QgsGeometryCollection
2018-11-20 05:05:37 +11:00
lbartoletti
574a57f2e4 Merge branch 'extendMapTool' of github.com:lbartoletti/QGIS into extendMapTool 2018-11-13 13:39:56 +01:00
lbartoletti
a8f865917e Nyall's review 2018-11-13 09:03:26 +01:00