[Qgis-community-team] Issue regarding spatial data reading in Python API

Tim Sutton tim at kartoza.com
Tue Aug 13 05:39:32 PDT 2019


Hi

See https://www.qgis.org/en/site/getinvolved/mailinglists.html for the mailing lists.

Your approach does not use QGIS API but Qt API. That means you need to read Qt specific documentation (and engage with the Qt community for support).

If you want to do it in QGIS you would normally create a layer (with or without geometry) and then iterate over the features. Please see the cookbook here:

https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html

Which contains worked examples.

Regards

Tim

> On 13 Aug 2019, at 13:22, Gopal Mantri <gopal.mantri at tcs.com> wrote:
> 
> Hi Tim,
> We cannot provide the exact code due to organizational policies. But the logic looks somewhat like this.
> We are facing issue in selecting the spatial columns of the spatial table.
> Also please provide the qgis-developer mailing list id.
>  
> from qgis.PyQt.QtSql import QSqlDatabase, QSqlQuery
>  
> if not QSqlDatabase.isDriverAvailable('QOCISPATIAL'):
>     print ('Oracle driver not available')
>  
> db = QSqlDatabase.addDatabase("QOCISPATIAL")
>  
> db.setDatabaseName('Hostname' + '/' + 'database')
>  
> db.setDatabaseName(‘hostname’+ ':' + str('port') + '/' + 'database')
>  
> db.setUserName(‘username)
> db.setPassword('password')
>  
> if not db.open():
>     print ('Could not open connection.')
>  
> q = QSqlQuery(db)
> q.exec_('SELECT * FROM tablename’)
> while(q.next()):
>     print(str(q.value(0)))
>  
> db.close()
>  
> Thanks & Regards,
> Gopal Krishna Mantri
> Phone:- 020-67259194
> <image001.jpg>
>  
> From: Tim Sutton [mailto:tim at kartoza.com <mailto:tim at kartoza.com>] 
> Sent: Tuesday, August 13, 2019 5:10 PM
> To: Gopal Mantri <gopal.mantri at tcs.com <mailto:gopal.mantri at tcs.com>>
> Cc: qgis-community-team at lists.osgeo.org <mailto:qgis-community-team at lists.osgeo.org>; Anupriya Mall <anupriya.mall at tcs.com <mailto:anupriya.mall at tcs.com>>
> Subject: Re: [Qgis-community-team] Issue regarding spatial data reading in Python API
>  
> "External email. Open with Caution"
> 
> Can you direct your query to the qgis-developer mailing list rather please - and do supply specific code examples of what you have already tried. If you ask generic questions you will likely get generic answers.
>  
> Also make sure to consult the cookbook before asking your question:
>  
> https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/ <https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/>
>  
> Regards
>  
> Tim
> 
> 
> On 13 Aug 2019, at 07:16, Gopal Mantri <gopal.mantri at tcs.com <mailto:gopal.mantri at tcs.com>> wrote:
>  
> Hello team,
> I want to create maps through python API in QGIS with Oracle database containing spatial data.
> I am able to connect the database. But, I am facing issue in reading the spatial points.
> Can I get help in how to read spatial data and create map through Python API?
>  
> Thanks & Regards,
> Gopal Krishna Mantri
> Phone:- 020-67259194
> <image001.jpg>
>  
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain 
> confidential or privileged information. If you are 
> not the intended recipient, any dissemination, use, 
> review, distribution, printing or copying of the 
> information contained in this e-mail message 
> and/or attachments to it are strictly prohibited. If 
> you have received this communication in error, 
> please notify us by reply e-mail or telephone and 
> immediately and permanently delete the message 
> and any attachments. Thank you
>  
> _______________________________________________
> Qgis-community-team mailing list for organizing community resources such as documentation, translation etc..
> Qgis-community-team at lists.osgeo.org <mailto:Qgis-community-team at lists.osgeo.org>
> https://lists.osgeo.org/mailman/listinfo/qgis-community-team <https://lists.osgeo.org/mailman/listinfo/qgis-community-team>
>  
>>  
> 
> <image002.jpg>
> 
> 
> 
> 
> 
>  
> Tim Sutton
>  
> Co-founder: Kartoza
> Ex Project chair: QGIS.org <http://qgis.org/>
>  
> Visit http://kartoza.com <http://kartoza.com/> to find out about open source:
>  
> Desktop GIS programming services
> Geospatial web development
> GIS Training
> Consulting Services
>  
> Skype: timlinux 
> IRC: timlinux on #qgis at freenode.net <http://freenode.net/>
>  
> I'd love to connect. Here's my calendar link <https://calendly.com/timlinux> to make finding time easy.

—









Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com <http://kartoza.com/> to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net

I'd love to connect. Here's my calendar link <https://calendly.com/timlinux> to make finding time easy.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-community-team/attachments/20190813/1af253ac/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KartozaNewLogoThumbnail.jpg
Type: image/jpeg
Size: 6122 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-community-team/attachments/20190813/1af253ac/attachment-0001.jpg>


More information about the Qgis-community-team mailing list