<div dir="ltr"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>You are not initializing QGIS in your script. Try adding this at the beginning of your script</div><div><br></div><div>from qgis.core import QgsApplication<br><br>qgs = QgsApplication([], False)<br>qgs.initQgis()</div><div><br></div><div></div><div><table cellpadding="0" cellspacing="0" style="border-spacing:0px;border-collapse:collapse;color:rgb(68,68,68);width:480px;font-size:10pt;font-family:Arial,sans-serif;line-height:normal"><tbody><tr><td valign="top" style="padding:10px 0px 12px;width:160px;vertical-align:top"><a href="https://spatialthoughts.com/" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img border="0" alt="Logo" width="141" src="https://spatialthoughts685850346.files.wordpress.com/2019/12/spatial_thoughts_logo.png" style="border:0px;vertical-align:middle;width:141px;height:auto"></a></td><td style="padding:6px 0px;width:320px"><table cellpadding="0" cellspacing="0" style="border-spacing:0px;border-collapse:collapse;background-color:transparent"><tbody><tr><td style="padding:0px;font-size:12pt;font-family:Arial,sans-serif;font-weight:bold;color:rgb(61,60,63)"><span style="color:rgb(0,175,239)">Ujaval Gandhi</span></td></tr><tr><td style="padding:0px 0px 11px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(61,60,63)"><span style="color:rgb(0,175,239)">Spatial Thoughts</span></td></tr><tr><td style="padding:0px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(155,155,155)"><span>mobile: +91-8095684687</span></td></tr><tr><td style="padding:0px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(155,155,155)"><span>email: </span><span style="color:rgb(23,147,210)"><a href="mailto:ujaval@spatialthoughts.com" target="_blank">ujaval@spatialthoughts.com</a></span></td></tr><tr><td style="padding:6px 0px 0px"><span style="display:inline-block;height:22px"><span><a href="https://www.linkedin.com/in/spatialthoughts/" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img alt="LinkedIn icon" border="0" width="23" height="23" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator/elegant-logo/ln.png" style="border:0px;vertical-align:middle;height:20px;width:20px"></a>  </span><span><a href="https://twitter.com/spatialthoughts" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img alt="Twitter icon" border="0" width="23" height="23" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator/elegant-logo/tt.png" style="border:0px;vertical-align:middle;height:20px;width:20px"></a>  </span></span></td></tr></tbody></table></td></tr><tr><td colspan="2" style="padding:8px 0px 0px;border-top:1px solid rgb(23,147,210);width:480px;font-family:Arial,sans-serif;color:rgb(155,155,155);text-align:justify"></td></tr></tbody></table><br></div></div></div></div></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 27, 2021 at 6:27 PM Prem Kumar <<a href="mailto:prem.netgis@gmail.com">prem.netgis@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Team,<div><br></div><div>Just wondering whether I'm missing something or a genuine bug, please advise below. </div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><b>Code Snippet for reproducing:</b></div><div><pre style="background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(204,120,50)">from </span>qgis.PyQt.QtCore <span style="color:rgb(204,120,50)">import </span>QVariant<br><span style="color:rgb(204,120,50)">from </span>shapely.geometry <span style="color:rgb(204,120,50)">import </span>shape<br><span style="color:rgb(204,120,50)">import </span>geojson<span style="color:rgb(204,120,50)">,</span>json<br><span style="color:rgb(204,120,50)">from </span>qgis.core <span style="color:rgb(204,120,50)">import </span>(QgsGeometry<span style="color:rgb(204,120,50)">,</span>QgsCoordinateReferenceSystem<span style="color:rgb(204,120,50)">,</span>QgsCoordinateTransform<span style="color:rgb(204,120,50)">,</span>QgsProject)<br><span style="color:rgb(204,120,50)">from </span>shapely <span style="color:rgb(204,120,50)">import </span>speedups <span style="color:rgb(204,120,50)">as </span><span style="color:rgb(152,118,170);font-style:italic">sups<br></span>sups.disable()<br><br><span style="color:rgb(152,118,170);font-style:italic">in_geometry</span>=<span style="color:rgb(106,135,89)">'[{"type": "LineString","coordinates": [[-78.85338577199997,43.85845267000008],[-78.85593885699996,43.857924291000074]]}]'<br></span><span style="color:rgb(152,118,170);font-style:italic">geomjson </span>= json.loads(<span style="color:rgb(152,118,170);font-style:italic">in_geometry</span>)<br><span style="color:rgb(152,118,170);font-style:italic">old_crs </span>= QgsCoordinateReferenceSystem(<span style="color:rgb(106,135,89)">"EPSG:4326"</span>)<br><span style="color:rgb(152,118,170);font-style:italic">new_crs </span>= QgsCoordinateReferenceSystem(<span style="color:rgb(106,135,89)">"EPSG:3857"</span>)<br><span style="color:rgb(152,118,170);font-style:italic">xtransform </span>= QgsCoordinateTransform(<span style="color:rgb(152,118,170);font-style:italic">old_crs</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(152,118,170);font-style:italic">new_crs</span><span style="color:rgb(204,120,50)">, </span>QgsProject.instance())<br><span style="color:rgb(204,120,50)">for </span><span style="color:rgb(152,118,170);font-style:italic">i</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(152,118,170);font-style:italic">g </span><span style="color:rgb(204,120,50)">in </span><span style="color:rgb(136,136,198)">enumerate</span>(<span style="color:rgb(152,118,170);font-style:italic">geomjson</span>):<br>    <span style="color:rgb(152,118,170);font-style:italic">s </span>= json.dumps(<span style="color:rgb(152,118,170);font-style:italic">g</span>)<br>    <span style="color:rgb(152,118,170);font-style:italic">g1 </span>= geojson.loads(<span style="color:rgb(152,118,170);font-style:italic">s</span>)<br>    <span style="color:rgb(152,118,170);font-style:italic">shapely_geom </span>= shape(<span style="color:rgb(152,118,170);font-style:italic">g1</span>)<br>    <span style="color:rgb(152,118,170);font-style:italic">qgs_geom</span>=QgsGeometry.fromWkt(<span style="color:rgb(152,118,170);font-style:italic">shapely_geom</span>.wkt)<br>    <span style="color:rgb(152,118,170);font-style:italic">qgs_geom</span>.transform(<span style="color:rgb(152,118,170);font-style:italic">xtransform</span>)<br>    <span style="color:rgb(136,136,198)">print </span>(<span style="color:rgb(152,118,170);font-style:italic">qgs_geom</span>)</pre></div><div><b>Output from Pycharm:</b></div><div>C:\Qgis\apps\Python37\python.exe C:/_WORK/SERVICE/test_transform.py<br><QgsGeometry: LineString (-8777918.77684544585645199 5443563.52439526654779911, -8778202.97550544328987598 5443481.85537817236036062)><br><br>Process finished with exit code 0<br></div><div><br></div><div><b>Output from Linux terminal:</b></div><div>(gisenv) admin@rd-temp-server:~/gis_service$ python3 test_transform.py<br></div><div>Application path not initialized<br>Application path not initialized<br><QgsGeometry: LineString (-78.85338600000000042 43.85845299999999725, -78.85593900000000644 43.85792399999999702)><br>(gisenv) admin@rd-temp-server:~/gis_service$<br></div><div><br></div><div>Thanks.</div><div>-Prem</div></div>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div>