[Qgis-user] Accessing iface from jupyter to create map from QGIS

2023-12-05 Thread noshin prachi via QGIS-User
Dear all,
I am trying to create a map from qgis. I have added a few layers and
created a layout in qgis. All I want is to create a script to get a map
from the layer on the layout that I have created in qgis. I have attached
the code. I am thinking of activating each layer at a time so that only the
activated layer will be on the layout and a map will get generated. While
trying to activate with iface.setactivelayer I am facing an error. So no
layer is added to the layout. I have added the code  and image of the
generated map.
[image: Day-1.png]

[image: image.png]

How to access the layer in qgis? how to deactivate the first layer and then
move to the next layer for the next map.

Regards,
Noshin
#!/usr/bin/env python
# coding: utf-8

# In[61]:


import os
from datetime import datetime, timedelta
from qgis.core import (
QgsGeometry,
QgsMapSettings,
QgsPrintLayout,
QgsMapSettings,
QgsMapRendererParallelJob,
QgsLayoutItemLabel,
QgsLayoutItemLegend,
QgsLayoutItemMap,
QgsLayoutItemPolygon,
QgsLayoutItemScaleBar,
QgsLayoutExporter,
QgsLayoutItem,
QgsLayoutPoint,
QgsLayoutSize,
QgsUnitTypes,
QgsProject,
QgsFillSymbol,
QgsAbstractValidityCheck,
check,
)

from qgis.PyQt.QtGui import (
QPolygonF,
QColor,
)

from qgis.PyQt.QtCore import (
QPointF,
QRectF,
QSize,
)


# In[70]:


project_path = r"C:\Users\FFWS\Desktop\Boundary_Generation_For_2D\2D Overland 
Flow Model-Boundary Generation\2D Overland Flow Model-Boundary 
Generation\bin\Debug\C2_FloodMap_SERM_V01.qgz"

project_instance = QgsProject.instance()

project_instance.read(project_path)
print(project_instance.fileName())


# In[71]:


map_layers = QgsProject.instance().mapLayersByName('V1054_SWRM_SW_2D 
PS_LR_Dike_Updt_statBaseFlood Map_Day01')[0]
iface.setActiveLayer(map_layers)


# In[64]:


projectInstance = QgsProject.instance()
layoutmanager = projectInstance.layoutManager()
layout = layoutmanager.layoutByName("SW_Day_1")


# In[65]:


map_label = QgsLayoutItemLabel(layout)


# In[67]:


firstDay ="2023-11-25 09:00:00"

dateTimeObj = datetime.strptime(firstDay, "%Y-%m-%d %I:%M:%S" )

secDay=(dateTimeObj+ timedelta(days = 1))

PreparedDayValue = secDay.strftime('%Y-%m-%d %I:%M:%S')
map_label.setText("Valid for: " +firstDay.strip('"')+ " "+"to" +" 
"+PreparedDayValue + ", Prepared on: " +  firstDay)



# In[68]:


layout.removeLayoutItem(map_label)
layout.addLayoutItem(map_label)


# In[69]:


map_label.attemptMove(QgsLayoutPoint(1.6, 0.5, QgsUnitTypes.LayoutInches))
exporter = QgsLayoutExporter(layout)
exporter.exportToImage(r"C:\Users\FFWS\Desktop\Boundary_Generation_For_2D\2D 
Overland Flow Model-Boundary Generation\2D Overland Flow Model-Boundary 
Generation\bin\Debug\Day-1.png", QgsLayoutExporter.ImageExportSettings() )


# In[ ]:




___
QGIS-User mailing list
QGIS-User@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


Re: [Qgis-user] QGIS attribute forms question

2023-12-05 Thread Aguilar Bolivar, Rosa (UT-ITC) via QGIS-User
Hi,
If I understood correctly,  You want to reuse a form given that a layer has 
more columns.
If you are using QGIS GUI you  can:
Option A. Change the data source to the layer. The form will remain. Add/edit 
the new attributes
Option B. Add the new layer and copy styles (form)  --> paste the style/form to 
the new layer

Hope this helps.

Rosa
-
Dr. Rosa Aguilar
University of Twente
Faculty of Geoinformation Science and Earth Observation
Connect with me on 
LinkedIn
https://rosaguilar.github.io
-
The essential is invisible to the eye. Saint-Exupéry

From: QGIS-User  On Behalf Of Brent Wood via 
QGIS-User
Sent: Tuesday, December 5, 2023 4:35 AM
To: 'Qgis-user@lists.osgeo.org' 
Subject: [Qgis-user] QGIS attribute forms question

Hi,

I have created some forms for data entry/edit using QGIS.

I have successfully exported them & imported them to apply in different 
computers with QGIS.

It can take several hours to create such a form where there are 80+ columns in 
the underlying database table,

I now have the situation where the underlying table needs columns added or 
removed.

QGIS will not apply a saved form to a layer unless the structure is identical.


How can I reuse a form for a layer representing a database table with (say) a 
single new column, by adding the new column to the form, rather than manually 
creating the whole form from scratch?


Thanks

Brent Wood

Principal Technician, Fisheries
NIWA
DDI:  +64 (4) 3860529
[https://www.niwa.co.nz/static/niwa-2018-horizontal-180.png]
Brent Wood
Principal Technician - GIS and Spatial Data Management
Programme Leader - Environmental Information Delivery
+64-4-386-0529

National Institute of Water & Atmospheric Research Ltd (NIWA)
301 Evans Bay Parade Hataitai Wellington New Zealand
Connect with NIWA: niwa.co.nz 
Facebook 
LinkedIn 
Twitter 
Instagram 
YouTube
To ensure compliance with legal requirements and to maintain cyber security 
standards, NIWA's IT systems are subject to ongoing monitoring, activity 
logging and auditing. This monitoring and auditing service may be provided by 
third parties. Such third parties can access information transmitted to, 
processed by and stored on NIWA's IT systems.
Note: This email is intended solely for the use of the addressee and may 
contain information that is confidential or subject to legal professional 
privilege. If you receive this email in error please immediately notify the 
sender and delete the email.
___
QGIS-User mailing list
QGIS-User@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


[Qgis-user] Accessing iface from jupyter

2023-12-05 Thread noshin prachi via QGIS-User
Dear all,
I am trying to create a map from qgis using jupyter. I have few layers that
need to be added to the map. I have tried to add iface by importing iface
 from qgis.utils import iface, plugins . But I am getting the following
error.
[image: image.png]

Please help me in this regard.

Regards,
Noshin Saiyara
___
QGIS-User mailing list
QGIS-User@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user