Tag Info

Hot answers tagged

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: ...


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 ...


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.


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)


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> ]


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.


1

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


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.


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 ...


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 = ...


1

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


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 ...


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 ...


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 ...


1

By using the new Layer tree (aka legend or Toc) added by Martin Dobias since QGIS v.2.4, you can load a raster layer to any position of the ToC following these steps: Get a reference of the layer tree root = QgsProject.instance().layerTreeRoot() Create the raster layer object from PyQt4.QtCore import QFileInfo fileName = "/path/to/raster/file.tif" ...



Only top voted, non community-wiki answers of a minimum length are eligible