New answers tagged

4

You need to use Explode lines tool to explode the converted line feature into individual lines: Search for Explode lines in the processing toolbox and you will find it. I am using QGIS 3.4.


1

Double check the geometry type returned by your line object in QGIS 3.8. The xAt() method belongs to the QgsLineString class and won't work with a QgsMultiLineString object. You can easily access the x coordinate of the first vertex of your line features like this: layer = iface.activeLayer() print(layer.name()) all_features = layer.getFeatures() for ...


2

Try specifying the CRS when you construct your QgsVectorLayer object e.g. v_layer = QgsVectorLayer('LineString?crs=epsg:4326', 'line', 'memory') Unfortunately, you don't show us what objects you are passing to your drawLine() function as the line_start and line_end arguments, however running the code below which directly creates QgsPoint() objects for the ...


2

The Change Data Source Plugin https://plugins.qgis.org/plugins/changeDataSource/ will give you a list of all the layers in the file and their locations.


1

The curved surface of the spheroid is unfailingly deformed when taken to the plane. The planimetric area is not equal to the ellipsoidal area. The differences, moreover, are not constant in a projection that is not equivalent, such as UTM. You can calculate both, ellipsoidal or planar, areas. If you want to know the planimetric area of a geometry ...


0

A meticulous syntax must be respected, especially escaped quotes, and an id (integer) and a geom must appear in the query. Here is a full example with st_intersects : uri = QgsDataSourceUri() uri.setConnection("localhost", "5432", "myBase", "myUser", "myPassword") sql = 'SELECT a.idA, a.geom, a.name FROM public.tableA a INNER JOIN public.tableB b ON ...


1

i am not really sure i understand your question, but it seems i had a similar problem: a large qgis project with different print layouts each representing a different print frame of a collection of 4 maps. layouts would overlap for about one inch, and i had to manually move the labels so that they would not be cut by any layout border. i have solved this ...


0

Neither QGIS nor GDALWarp support raster snapping. This inherently makes raster operations far more difficult when computing rasters from different sources against each other.


4

The following instruction is in French so that a non-English-speaking user can set QGIS to French. Pour avoir QGIS en français, tu dois avoir les paramètres suivants dans l'onglet Préférences. Redémarrage QGIS une fois que tu as effectué les changements. In order to get QGIS in french, you must have the following parameters in the Settings. Restart ...


3

Good question!,you can find the provider in the "about" dialog. or if you want use python, you can obtain the initial providers list. @germán-carrillo suggestion QgsProviderRegistry.instance().providerList() which returns for the above list from the "about" diolog the following values: ['DB2', 'WFS', 'arcgisfeatureserver', 'arcgismapserver', '...


5

I have tested the plugin and it is working fine in my machine. One common way to download (SRTM among other) data is searching it in Earth Explorer site. All the information about how to use the site is in their Help page. If you want to download just that image, you can do it from the Download link provided in the following page: https://...


2

With researches, i made this acceptable answer, without any loop. I assign QgsProcessingFeedback() to QProgressBar() and get a dynamic progression bar when processing is running : # Progression bar qgis.utils.iface.messageBar().clearWidgets() progressMessageBar = qgis.utils.iface.messageBar() progressbar = QProgressBar() progressMessageBar.pushWidget(...


2

You can directly produce features of concentric buffers as polygons by using linspace method from numpy python module. As you have in your attributes table 1440 features, I know that, in your case, polygon sides number is 360 for each one of your concentric buffers. Algorithm for extracting points for each polygon features is easily inferred; as it can be ...


4

According to ubuntugis documentation. "A convenient new command is available for adding Launchpad PPA (Personal Package Archive) repositories via the command line: add-apt-repository." For the stable PPA: sudo add-apt-repository ppa:ubuntugis/ppa Add this PPA and remove from /etc/apt/sources.list the sentences: deb https://qgis.org/ubuntugis/ bionic main ...


4

Do not use "Set CRS" within layer properties. This does not reproject your data. You only define the CRS there. Means: you can tell QGIS the layer is in a different CRS in which it actually is not. Do use "Export layer as..." and choose your desired CRS over there. This does actually reproject your data. You need to save your data into a new file. This new ...


0

go to the expression editor. delete your filter expression and replace it with "id".


0

Check out this answer from several years ago - you will need to use the GRASS toolset, but using v.clean correctly should still give you the result you require. Is there an open source tool to planarize graphs?


1

You would need Ordnance Survey MasterMap Topography Layer: https://www.ordnancesurvey.co.uk/business-government/products/mastermap-topography Which is a very expensive product, but provides split buildings. OpenStreetMap may be split terraces in some locations but would be unreliable.


1

# Your layer named dimensioning layer_dimensioning = QgsProject.instance().mapLayersByName("dimensioning")[0] # Provider in order to access your layer features provider_layer_dimensioning = layer_dimensioning.dataProvider() result = processing.run("qgis:explodelines", {'INPUT':temp_lines,'OUTPUT':'memory:'})["OUTPUT"] # Start edition layer_dimensioning....


1

See my answer here: QGIS changing the attribute input fields order Open the attribute table. Right click the column headings in the attribute table. Select "Organize columns" in drop down menu. Then, just drag the heading to the position you want it to be in (See image of the "organize table columns" box below). Click OK. Headings should have rearranged the ...


2

So after comments are in... Is it true that QGIS 3.10 does not work correctly with ArcGIS web services (MapServer)? No, it's not true. Your example service is expecting the bboxSR and imageSR parameters, but they are not required. How to fix this behavior? The service (not QGIS) has to be modified to change it's expectation for non-required ...


1

The error is not in the scripts themselves but in the structure created. Having a folder called myplugin and a file also called myplugin. QGIS cannot distinguish between them when reloading. When changing the script name, the reload worked correctly. myplugin ├── _init__.py ├── myplugin_main.py ├── myplugin_algorithm.py └── ...


4

You are using the wrong quotes. Try '' instead of "". E.g. if( floor("area") = 0, '',floor("area")||'m²') Double quotes " refer to fields. In your case to the field " " (whitepsace), which most likely does not exist. Single quotes ' refer to strings. If you want it to be just empty, there is no need to add a whitespace. Another suggestion / alternative: ...


1

This is my answer: layer = iface.activeLayer() feature = layer.getFeatures() d = QgsDistanceArea() d.setSourceCrs(layer.crs(), QgsProject.instance().transformContext()) d.setEllipsoid(QgsProject.instance().ellipsoid()) for feat in feature: print((d.convertLengthMeasurement(d.measureLength(feat.geometry()),1))*1000)


1

You may also use the Snap geometries to layer processing tool: This algorithm snaps the geometries in a layer. Snapping can be done either to the geometries from another layer, or to geometries within the same layer.


1

As @KadirSahbaz suggested I added import processing at the beginning. The code below works. from qgis import processing from qgis.processing import alg from qgis.core import QgsFeature, QgsWkbTypes, QgsField, QgsFields, QgsPointXY, QgsGeometry, \ QgsCoordinateReferenceSystem, QgsProcessingMultiStepFeedback, QgsVectorFileWriter, QgsVectorLayer, \ ...


1

It looks like your issue lies in the way you've tried to format your output and write it to your file. First, instead of opening the file in binary writing ('wb') mode, try standard writing mode ('w'). Once you've done that, there's no need to encode your output string - just use output_file.write(msgout). Note that this doesn't explicitly specify an ...


2

['blnFl'] is a list which includes one string item. A list which includes an item returns always True in if clause. Add next line before if ['blnFl'] is True: blnFl = self.parameterAsBool(parameters, "blnFl", context) And change if ['blnFl'] is True: as if blnFl is True: blnFl = self.parameterAsBool(parameters, "blnFl", context) if blnFl is True: ......


1

If you use just QgsDistanceArea.measureLength(feat), you get an error: first argument of unbound method must have type 'QgsDistanceArea'. That means you need to create an object of QgsDistanceArea d = QgsDistanceArea() Then you need to set ellipsoid. Use QgsEllipsoidUtils::acronyms() to get a list of all known ellipsoid acronyms. If you don't set ellipsoid,...


1

One way could be, d = QgsDistanceArea() d.setEllipsoid('WGS84') layer = iface.activeLayer() feature = layer.getFeatures() for feat in feature: print( d.convertAreaMeasurement( d.measureLength(feat.geometry()), 1 ) )


10

In the Layer pannel, there is an icon in form of an eye : Manage Map Themes (documentation) : By clicking on it, you can see the option for display / mask the selected layers. You can also go to the Settings menu > Shortcuts, find these options (one for display selected, one for mask selected) and affect the shortcut you want. PyQGIS code : Copy and ...


1

Firstly, you can extract selected polygons to memory, secondly convert them to lines, then explode the lines. This script works in QGIS 3.8, but it doesn't in QGIS 3.4.13: import processing layer = iface.activeLayer() selected = processing.run("native:saveselectedfeatures", {'INPUT':layer, 'OUTPUT':'TEMPORARY_OUTPUT'})["OUTPUT"] temp_lines = ...


1

Quite a bit more searching later, and I believe the answer is no. However I'm most of the way through implementing the above algorithm, and I believe it will work as written.


2

Try using something like the following where it is based on the new processing syntax. Create a Vector Layer input parameter in your modeler, set it so that it is not mandatory (i.e. it will be optional) and then use this as the input to the script. The script should check if the input is empty where it will create a dummy shapefile otherwise would use the ...


2

The error really is in field_name. This field should be given a fixed name and not an expression, and your expression can generate an empty name inclusive. Try this: 'FIELD_NAME': 'AREA', EDIT Now I understand your purpose, this is not a solution to the error presented, but a solution to the use that is in the question you mentioned: """ Model exported ...


5

You can turn off the whole Marker line if it is too short using built in data driven symbology. For example my data: I want to remove the arrows from the smaller islands. These are all line features, so looking at the length of the line is good. I am working in British National Grid, so my units are in meters. So to switch off the markers from all lines ...


1

Replace the last line of your code with the last line of the following code. fet = QgsFeature() pt = QgsPointXY(92.5,22.5) points.append(pt) pt = QgsPointXY(93.5,22.5) points.append(pt) pt = QgsPointXY(93.5,23.5) points.append(pt) fet.setGeometry(QgsGeometry.fromMultiPolygonXY([[points]]))


1

Select all the features you want to have a different color. Use the Field Calculator to add a new field. Check the box for "selected features only". Fill in a field name, and fill in a value in the expression area (in my example below, I called the field "category" and filled it with the value 1. Now the point layer has a new field called "category". The ...


2

Would extent() work? canvas = iface.mapCanvas() extent = canvas.extent() print(extent) Taking it one step further you can break the QgsRectangle object into its components: xmax = extent.xMaximum() ymax = extent.yMaximum() xmin = extent.xMinimum() ymin = extent.yMinimum()


1

You need to set a data-defined property. Unfortunately, the only such property you can set at the symbol level is the width. So, to set a data defined color, you must use the setDataDefinedProperty method of the QgsSymbolLayer In your case, you have only one symbol layer, so get it using symbol.symbolLayers()[0] layer = iface.addVectorLayer("/Users/usr/...


3

When the topology checker highlights a feature in red, it means that feature violates one of the rules. Since your only rule is "must not overlap," when a polygon is red it means that polygon overlaps with another polygon. It's up to you to find the exact place where it overlaps. I suggest using the Clip tool (from the Vector menu > Geoprocessing tools) ...


1

You don't need iface to zoom to a layer. It's sufficient to set the map canvas extent as the layer extent. ... canvas.setExtent(vlayer.extent()) project.write(project_path)


1

After further investigation it appears this is happening because my OS UI is set to dark mode. This is strange because QGIS 3.6 and lower is not effected by the computer UI theme. Seems to be a bug.


2

The error is related with (0.5)*(extent.width). You try to multiply a float (0.5) by a method (extent.width). width doesn't call the method. To call a method, you have to use parentheses. So it has to be extent.width(). Also center.x and center.y have to be center.x() and center.y(). You used all in original code correctly, but missed in the next one. Try ...


0

The problem may be with the fact that you have different versions of qgis installed, I had the same issue when trying to run Qgis 3 while having my python environment set for Qgis 2.18. I solved it by running these commands before launching qgis 3: setx PYTHONHOME "C:\OSGeo4W64\apps\Python37" setx PYTHONPATH "C:\OSGeo4W64\apps\Python37\lib;C:\OSGeo4W64\...


1

Yes, use the following expression to connect the boolean input to the tool: If(@blnCreateField, 'FieldName', '') For clarity, @blnCreateField returns either True or False depending if the checkbox for the parameter was checked or not. So the if statement checks if the first condition is true and, if it is, then return 'FieldName' else return nothing.


1

Search for Rearrange Bands in your processing toolbox. It will appear within GDAL Raster Conversion Tools. Select your multiband input raster and specify the bands you would like to "extract" within "Selected band(s)". Do further settings if you wish like choosing data type or the new order of your selected bands and run the tool. The newly created raster ...


3

The following minimal example is in a somewhat similar format to the post you linked to which should work for QGIS 3: # Interpolate points using QgsTinInterpolator pathToFile = "path/to/input.shp" layer = QgsVectorLayer(pathToFile, 'input','ogr') layer_data = QgsInterpolator.LayerData() layer_data.source = layer layer_data.zCoordInterpolation = False index ...


2

To refresh all layers, you can use the following command : iface.mapCanvas().refreshAllLayers() In your case : self.iface.mapCanvas().refreshAllLayers() The following script work (I write out of a function) : from qgis.utils import iface layer_edit = [ 'Enveloppe concave', 'Sortie SQL','Channel'] for layers in QgsProject.instance().mapLayers().values()...


0

I found the solution! Till now I used the QT-Designer without the custom widgets for QGIS. With the help of this post: No custom widgets in Qt Designer for QGIS 3 I got the custom widgets for QGIS3 in QT Designer and there is the widget "QgsDateTimeEdit" wich makes what I want!


Top 50 recent answers are included