81 Commits

Author SHA1 Message Date
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
lbartoletti
abcf2aa4cf init trim/extend feature 2018-11-13 09:03:26 +01:00
Nyall Dawson
ba17b130f8 Move forceRHR to QgsGeometry, avoid duplicate code 2018-11-09 19:06:48 +10:00
Nyall Dawson
27e1ef5c1c Add method to QgsCurvePolygon to force RHR, ensuring standard ring orientation 2018-11-09 19:06:48 +10:00
Nyall Dawson
c22364d45e Add method to determine orientation of closed curves 2018-11-09 19:06:48 +10:00
Nyall Dawson
7be2925649 Remove QgsGeometry bool operator
This is too dangerous -- it gets silently casted to numeric values
instead of throwing compilation errors
2018-11-05 08:39:10 +10:00
Matthias Kuhn
0da210df52
Add QgsRectangle::snappedToGrid
Snaps a rectangle to a grid.
2018-10-26 07:58:27 +02:00
Denis Rouzaud
5577d83a75 mark method as const 2018-10-25 13:49:26 -04:00
Denis Rouzaud
80d0c33f5b add QgsRectangle::scaled which returns the scaled rectangle
facilitates one-lines
2018-10-25 13:37:07 -04:00
Denis Rouzaud
32d4bcc425
add Python __repr__ method to QgsGeometry.Error (#8198) 2018-10-15 06:53:09 -08:00
Denis Rouzaud
ef1efebda4 forward declaration of QgsPoint 2018-10-09 11:48:33 -08:00
Nathan Woodrow
f928c2e545
[FIX] - Respect selection order in attribute table copy. (#8048)
Only copy fields shown in view for current table.
2018-10-08 12:07:28 +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
Denis Rouzaud
9fa8c356dd
make QgsWkbTypes a Q_GADGET and declare GeometryType as Q_ENUM (#8024)
* make QgsWkbTypes a Q_GADGET and declare GeometryType as Q_ENUM

* include QObject

* remove extra include

* move QgsWkbTypes to moc headers

* run sip_include
2018-10-05 10:25:35 -08:00
Nyall Dawson
f1ced30ee2 Fix dox 2018-09-28 13:17:12 +10:00
Nyall Dawson
39d148612b Optimise conversion of geometry from OGR -> QGIS
Avoid conversion to/from WKB at OGR/QGIS side, and just directly
utilise OGR geometry API to construct QGIS geometries.

Shaves ~10% off rendering time for a large point layer (GPKG)
2018-09-28 13:17:12 +10:00
Matthias Kuhn
7f63d41b44
Merge pull request #7822 from m-kuhn/constCorrectQgsGeometryError
Const correctness for QgsGeometry::Error
2018-09-07 15:00:40 +02:00
Matthias Kuhn
e637fd5e66 Add doxymentation 2018-09-07 13:19:52 +02:00
Matthias Kuhn
8ba442f14a Const correctness for QgsGeometry::Error 2018-09-07 10:58:13 +02:00
Juergen E. Fischer
a823046b5f followup spelling fixes 2018-09-07 00:33:13 +02:00
Denis Rouzaud
ea2ab53482 fix QgsGeometry API doc for 3.x for get/set methods 2018-08-23 06:38:58 +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
Nyall Dawson
5b0bdbd4d9 Add QgsGeometryUtils method to interpolate a point on an arc given a distance 2018-08-15 14:01:59 +10:00
Nyall Dawson
56fd4e3b16 Add QgsGeometryUtils method for interpolating point between two points, with z/m handling 2018-08-15 14:01:59 +10:00
Nyall Dawson
d09faf42be Add method to transform vertices of QgsGeometry/QgsAbstractGeometry
in place using a custom lambda function
2018-07-30 12:11:17 +10:00
Nyall Dawson
20e62b4c5f Fix typo, failing test 2018-07-26 09:37:19 +10:00