You are not initializing QGIS in your script. Try adding this at the beginning of your script
from qgis.core import QgsApplication qgs = QgsApplication([], False) qgs.initQgis() [image: Logo] <https://spatialthoughts.com/> Ujaval Gandhi Spatial Thoughts mobile: +91-8095684687 email: uja...@spatialthoughts.com [image: LinkedIn icon] <https://www.linkedin.com/in/spatialthoughts/> [image: Twitter icon] <https://twitter.com/spatialthoughts> On Thu, May 27, 2021 at 6:27 PM Prem Kumar <prem.net...@gmail.com> wrote: > Hi Team, > > Just wondering whether I'm missing something or a genuine bug, please > advise below. > > All I am trying is, to take the geometry object in json format whose CRS > is in WGS84 (EPSG:4326) and transform the geometry to EPSG:3857 CRS and > eventually use it in further processing because rest of the processing is > in EPSG:3857 CRS. > > I have written below code and it works like a charm on Windows 10 but it > doesn't transform the geometry on Linux. Please advise if there is anything > wrong or missing to add. > *Code Snippet for reproducing:* > > from qgis.PyQt.QtCore import QVariant > from shapely.geometry import shape > import geojson,json > from qgis.core import > (QgsGeometry,QgsCoordinateReferenceSystem,QgsCoordinateTransform,QgsProject) > from shapely import speedups as sups > sups.disable() > > in_geometry='[{"type": "LineString","coordinates": > [[-78.85338577199997,43.85845267000008],[-78.85593885699996,43.857924291000074]]}]' > geomjson = json.loads(in_geometry) > old_crs = QgsCoordinateReferenceSystem("EPSG:4326") > new_crs = QgsCoordinateReferenceSystem("EPSG:3857") > xtransform = QgsCoordinateTransform(old_crs, new_crs, QgsProject.instance()) > for i, g in enumerate(geomjson): > s = json.dumps(g) > g1 = geojson.loads(s) > shapely_geom = shape(g1) > qgs_geom=QgsGeometry.fromWkt(shapely_geom.wkt) > qgs_geom.transform(xtransform) > print (qgs_geom) > > *Output from Pycharm:* > C:\Qgis\apps\Python37\python.exe C:/_WORK/SERVICE/test_transform.py > <QgsGeometry: LineString (-8777918.77684544585645199 > 5443563.52439526654779911, -8778202.97550544328987598 > 5443481.85537817236036062)> > > Process finished with exit code 0 > > *Output from Linux terminal:* > (gisenv) admin@rd-temp-server:~/gis_service$ python3 test_transform.py > Application path not initialized > Application path not initialized > <QgsGeometry: LineString (-78.85338600000000042 43.85845299999999725, > -78.85593900000000644 43.85792399999999702)> > (gisenv) admin@rd-temp-server:~/gis_service$ > > Thanks. > -Prem > _______________________________________________ > QGIS-Developer mailing list > QGIS-Developer@lists.osgeo.org > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer >
_______________________________________________ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer