Tag Info

New answers tagged

1

By using the new Layer tree (aka legend or Toc) added by Martin Dobias since QGIS v.2.4, you can load a layer to the bottom of the ToC following these steps: Get a reference of the layer tree root = QgsProject.instance().layerTreeRoot() Create the layer object mylayer = QgsVectorLayer("/Path/to/your/data.shp", "my layer", "ogr") Add the layer to the QGIS ...


0

Try the Unique_values_saver plugin for QGIS. It allows you to save one vector layer for each unique value from a specific field. For instance, for a layer with world countries and regions, I've generated 10 vector layers, each one corresponding to a different region. If you really need the way to do it in Python, just have a look at the source code of ...


2

You may use the addGroup function like this: MyFirstGroup = iface.legendInterface().addGroup('Group No. 1') MySecondGroup = iface.legendInterface().addGroup('Group No. 2', true, MyFirstGroup)


0

I guess your problem is rather How to remove an old version of QGIS completely before re-installing. Mixing ubuntugis and qgis debian packages might lead to unexpected behaviour. On updating from QGIS 2.6.0 to 2.6.1 I noticed that some ubuntugis packages (qgis, python-qgis and one other) were not upgraded, but manually forcing the install did the trick.


0

With the new layer list widget (aka legend, ToC or layer tree) added by Martin Dobias since QGIS v.2.4, you can follow this procedure from the QGIS Python console in order to add layers to a specific group (you won't need group indices anymore): Get the reference of the layer tree. root = QgsProject.instance().layerTreeRoot() Find the desired group. ...


3

You need ST_Difference which returns the the geometry of a feature that does not intersect with another feature. In your case something like this: SELECT l.id, ST_Difference(l.geom, p.wkb_geometry) As diff_geom FROM lines l, polygons p Modify for your actual table and field names.


1

Use the QuickMultiAttributeEdit plugin. This is the work flow: Load a vector layer. Select some features. Press F12 (or click the plugin button). Select the field you want to edit and set the new value for selected features. Click OK and save the edits.


0

You should really update QGIS to v.>=2.4. Martin Dobias refactored the QGIS layer list widget (aka legend or ToC), enabling developers to manipulate legend objects from the QGIS API. Martin has recently posted a couple of articles on how to use the new legend API from Python: http://www.lutraconsulting.co.uk/blog/2014/07/06/qgis-layer-tree-api-part-1/ ...


0

Ok, I think I figured it out. Apparently the map canvas has its own CRS and on the fly projection for layers which use a different CRS is disabled by default. Enabling OTF projection with my_canvas.setCrsTransformEnabled(True) did the trick. (my_canvas being the QgsMapCanvas in my Qt window). my_canvas and my_layer actually both had the EPSG:4326 CRS ...


1

The setAlignment() method accepts the enumarator QgsComposerScaleBar::Alignment. So you should change your code as following: item.setAlignment(QgsComposerScaleBar.Right) Hope this helps.


4

You need to open it as a QgsVectorLayer layer = QgsVectorLayer('/path/to/shapefile_folder/test.shp', 'test', 'ogr') QgsVectorLayer objects have a method called geometryType. If you call that method for your newly created layer : >>> print layer.geometryType() 2 Where 0 is points, 1 is lines and 2 is polygons


3

I guess the "proper" way is to use QGIS' API which I'd hope would expose that. But I don't know how to do that. An alternative is to look without the shapefile itself. The basics of the specification are on Wikipedia: https://en.wikipedia.org/wiki/Shapefile#Shapefile_shape_format_.28.shp.29 What you want is: bytes 32–35 of the main header which dictates ...


1

I cannot tell you but perhaps pyTuio may be of some use to you. It is defined as "A Python library that understands the TUIO protocol" and describes the installation and a basic use. Hopefully others can provide some insight.


0

Still no success to turn that option on. I figured out that it is a global option, and found in QGis api the setShowingAllLabels method in the QgsPalLabeling class. This is obviously the one I am looking for, but I couldn't manage to make it work : pal = self.iface.mapCanvas().mapRenderer().labelingEngine() pal.setShowingAllLabels(True) ...


0

It's definitely possible. While QgsComposition takes only a single QgsMapSettings instance, it is not used for defining the extent of map items. Instead, use QgsComposerMap.setNewExtent for each map item to individually alter their visible extent.


1

I have no experience in C++ and am just learning to write QGIS plugins so this answer may be questionable... Looking at the c++ source ( http://qgis.org/api/qgsproject_8cpp_source.html ) for the "write" method, I noticed the following code in the middle of the write and thought it might be relevant to your problem: 1091 // let map canvas and legend write ...


0

If you're after the signal you define it like this: layer.editingStarted.connect(yourfunction)


0

From the comments it looked like the asker of this question was able to resolve their problem by reading a blog posting entitled A Quick Guide to Getting Started With PyQGIS on Windows. In that blog the advice offered seemed to be: We only changed the last line, adding the start statement with the path to the IDE (PyCharm). If you save this to ...


1

It needs to be set in the "layerOptions" parameter. This parameter takes a list of strings of the format "OPTION=VALUE", corresponding to OGR layer options for the vector format. So, for coordinate precision, try setting this parameter to: ['COORDINATE_PRECISION=3'] (or whatever your desired precision is). Additional valid parameters are listed on the OGR ...


0

Even without programming, I think it should be possible to achieve this using the idea presented in http://nathanw.net/2014/09/23/qgis-atlas-on-non-geometry-tables/: use the Atlas functionality to loop through a coverage layer containing values for the rule-based rendering of e.g. your contours. I imagine you will want to compare one of the contour ...


1

The following is a way to do what you want : ## define datasource asset_wps = QgsVectorLayer("path/your/asset/datasource", 'Assets', 'ogr') proposed_conductor = QgsVectorLayer("path/your/conductor/datasource", 'Proposed Conductor', 'ogr') ## your "where" clauses where_clause1 = "ASSET_TYPE = 'Secondary Ped' OR ASSET_TYPE = 'XFMR'" where_clause2 = ...


2

With QgsCoordinateReferenceSystem you can also get the WKT(well known text) as QString (using toWkt() ). You can then parse your WKT to extract the properties of your ellipsoid <spheroid> ::= SPHEROID ["<name>", <semi major axis>, <inverse flattening> ]


0

For making in-memory features check out: Memory Provider For select layer by location check out Sextante selection methods: QGIS-SEXTANTE cookbook


0

Thanks for the idea, I tried it, but with limited speed up. Isn't there a way for a direct memory access? I load the same data with python in Paraview which takes 10sec for 600 000 triangles. QGIS takes >1h ... And, not only changing attributes, but also shift painting triangles or shifting geometry.


1

I just noticed that you missed to set the QGIS installation path, so no provider may be loaded properly and probably this is the root of the problem. Try to change your script as follow: def main(): ## second argument (GUI Enabled) may be False ## if you do not need of GUI stuff QgsApplication([], False) ## installation path for Linux: ...


1

THe short answer is: I can;t see a way. However, changing attributes on a feature is time consuming at times (I have have a hard time figuring out why it happens). Thus, this should speed up your code a bit: pr.addAttributes( [QgsField(aName, QVariant.Double) ] ) attrs={} #------ # Add Values to Triangle Features in Values ...


0

loaded plugins and their instance are available in the dict qgis.utils.plugins you can manage load and unload with other methods in qgis.utils (do help(qgis.utils) in pythonconsole to show static methods available) this is only the base to solve you problem, you should manage check if running or not using some method in your plugin, or you can check if ...


1

similar to .area(), you can use .length() . For a polygon it yields the perimeter. perimeter=feature.geometry().length()


5

First case: insert new polyline You have to define the Polyline like so: pLine = [QgsPoint(1,1), QgsPoint(2,1), QgsPoint(2,2)] it is a list-of-QgsPoint. After you can put more QgsPoint into the list by append to insert the element at the end of the list: pLine.append(QgsPoint(3,2)) or inserting some vertex point at a specific location of the list: ...


0

I'm not sure but maybe you have to disconnect the signal layersWillBeRemoved from the default slot removeMapLayers.


0

thanks for the answers. The problem was that I had to set both 'resp' and 'rast1' variables to None after each iteration in the for loop, so my code end up like this entries = [] rasters = os.listdir("C://test/Rasters/") for i in range(0, len(rasters)): raster = "C://test/Rasters/"+rasters[i] resp = QgsRasterLayer(raster) rast1 = ...


0

The issue is likely that 'resp' goes out of scope and is deleted when the for loop ends. Then when you try to use it in the calc = QgsRasterCalculator... line QGIS crashes. Try initializing 'resp' outside of your loop first. Something like: ... resp = None for i in range(0, len(rasters)): ... should do it.



Top 50 recent answers are included