Skip to content

Instantly share code, notes, and snippets.

@agiudiceandrea
Last active January 7, 2021 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agiudiceandrea/7730bc05bd1ae91d4239997ea0357fd2 to your computer and use it in GitHub Desktop.
Save agiudiceandrea/7730bc05bd1ae91d4239997ea0357fd2 to your computer and use it in GitHub Desktop.
QGIS 3.10.1
GEOS 3.8.0-CAPI-1.13.1
PROJ Rel. 6.2.1, November 1st, 2019
SpatiaLite 4.3.0
from processing.tools import spatialite
db = spatialite.GeoDB(QgsDataSourceUri('dbname=\'C:/Users/Andrea/test.sqlite\' table=\'test\'(geometry) sql='))
cur=db.con.cursor()
db._exec_sql(cur, sql='select spatialite_version();')
cur.fetchone()[0]
'4.3.0'
db._exec_sql(cur, sql='select proj4_version();')
cur.fetchone()[0]
'Rel. 6.2.1, November 1st, 2019'
db._exec_sql(cur, sql='select geos_version();')
cur.fetchone()[0]
'3.8.0-CAPI-1.13.1 '
db._exec_sql(cur, sql='select lwgeom_version();')
cur.fetchone()[0]
'3'
db._exec_sql(cur, sql='select st_area(st_geomfromtext(\'POLYGON ((20.13293641 59.95688345, 26.94617837 60.47397663, 29.74782155 62.56499443, 27.45254202 68.70650340, 23.75771765 68.24937206, 25.42698984 65.27444593, 21.51545237 63.10353609, 21.40562760 61.12318104, 19.41123592 60.40477513, 20.13293641 59.95688345))\') ,true);')
cur.fetchone()[0]
251199344354.4308
db._exec_sql(cur, sql='select st_area(st_geomfromtext(\'POLYGON ((20.13293641 59.95688345, 26.94617837 60.47397663, 29.74782155 62.56499443, 27.45254202 68.70650340, 23.75771765 68.24937206, 25.42698984 65.27444593, 21.51545237 63.10353609, 21.40562760 61.12318104, 19.41123592 60.40477513, 20.13293641 59.95688345))\') ,false);')
cur.fetchone()[0]
249631004700.70947
db._exec_sql(cur, sql='select st_area(st_transform(st_geomfromtext(\'POLYGON ((20.13293641 59.95688345, 26.94617837 60.47397663, 29.74782155 62.56499443, 27.45254202 68.70650340, 23.75771765 68.24937206, 25.42698984 65.27444593, 21.51545237 63.10353609, 21.40562760 61.12318104, 19.41123592 60.40477513, 20.13293641 59.95688345))\', 4326), 32635));')
cur.fetchone()[0]
251038084443.76132
db._exec_sql(cur, sql='select st_area(st_geomfromtext(\'POLYGON ((20.13293641 59.95688345, 26.94617837 60.47397663, 29.74782155 62.56499443, 27.45254202 68.70650340, 23.75771765 68.24937206, 25.42698984 65.27444593, 21.51545237 63.10353609, 21.40562760 61.12318104, 19.41123592 60.40477513, 20.13293641 59.95688345))\'));')
cur.fetchone()[0]
45.25847152075945
db._exec_sql(cur, sql='select st_perimeter(st_geomfromtext(\'POLYGON ((20.13293641 59.95688345, 26.94617837 60.47397663, 29.74782155 62.56499443, 27.45254202 68.70650340, 23.75771765 68.24937206, 25.42698984 65.27444593, 21.51545237 63.10353609, 21.40562760 61.12318104, 19.41123592 60.40477513, 20.13293641 59.95688345))\') ,true);')
cur.fetchone()[0]
2578086.2023619814
geom=QgsGeometry.fromWkt("POLYGON ((20.13293641 59.95688345, 26.94617837 60.47397663, 29.74782155 62.56499443, 27.45254202 68.70650340, 23.75771765 68.24937206, 25.42698984 65.27444593, 21.51545237 63.10353609, 21.40562760 61.12318104, 19.41123592 60.40477513, 20.13293641 59.95688345))")
d = QgsDistanceArea()
d.measureArea(geom)
45.258471520759485
d = QgsDistanceArea()
d.setEllipsoid('WGS84')
True
d.measureArea(geom)
249566957499.7546
d.measurePerimeter(geom)
2578086.202361983
from shapely import wkt
from pyproj import Geod
pyproj info:
pyproj: 2.4.1
PROJ: 6.2.1
poly = wkt.loads('POLYGON ((20.13293641 59.95688345, 26.94617837 60.47397663, 29.74782155 62.56499443, 27.45254202 68.70650340, 23.75771765 68.24937206, 25.42698984 65.27444593, 21.51545237 63.10353609, 21.40562760 61.12318104, 19.41123592 60.40477513, 20.13293641 59.95688345))')
geod = Geod(ellps="WGS84")
abs(geod.geometry_area_perimeter(poly)[0])
251199344354.4309
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment