Hot answers tagged

3

As mentioned in the comment, you could create a model from the Processing Toolbox but if you want to create a script, you could use the following which creates the start_lat field and updates it for each layer (comments are included which hopefully will help): # Import required module to create field from PyQt4.QtCore import QVariant # For each layer in ...


3

To cut an image (tif file) by using GDAL python library, and without gdalwarp utility, you need to find row and column raster indexes of top point [p1=(minX, maxY)] and bottom point [p2=(maxX, minY)]. The formulas, based in your code, are: i1 = int((p1[0] - xOrigin) / pixelWidth) j1 = int((yOrigin - p1[1] ) / pixelHeight) i2 = int((p2[0] - xOrigin) / ...


2

You can use a combination of generate_series and window LEAD function to generate dist_from and dist_to fields and use ST_LineSubstring to cut lines at some interval (here: 1000 m). SELECT row_number() OVER() new_id, b.id, ST_LineSubstring(lin.the_geom, b.dist_from/ST_Length(lin.the_geom), LEAST(b.dist_to/ST_Length(lin.the_geom), 1)) geom FROM ( ...


2

This is one of the most common GDAL/OGR Python Gotchas: A dataset is only written to disk after it is closed. Closing a dataset happens when it goes out of scope. This can be done in a number of ways and one of the following needs to be appended to the end of your script. data_out = None data_out = "some new value" del(data_out) There are libraries ...


2

The widgets which you are referring to are leftovers from Qt3. QGIS at the moment is based on Qt4 (which exists since 2005 and has seen end of life in December 2015) and is soon to be updated to Qt5 (2016/2017). Ten years ago, when it was about moving applications from Qt3 to Qt4, a Qt3Support module has been introduced to ease the migration. However, ...


2

I completely uninstalled all the QGIS I could find on my computer and then reinstalled the 64bit version of QGIS 2.8.9 stable release. Once I had done that the plugin worked properly. I think this problem either relates to have remains of more than one verison of QGIS on the computer, or it was a 32bit issue. The plugin works perfectly and is brilliant.


2

You need to use the -dstalpha option to gdalwarp e.g.: gdalwarp -cutline INPUT.shp -crop_to_cutline -dstalpha INPUT.tif OUTPUT.tif This will add an alpha band to the output tiff which masks out the area falling outside the cutline. P.S. duplicate question


2

The general logic for setting border color is: # black polygon with red border symbol = QgsSymbolV2.defaultSymbol(layer.geometryType()) layer_style = {} layer_style['color'] = '0, 0, 0' layer_style['size'] = '2.5' layer_style['color_border'] = '255, 0, 0' symbol_layer = QgsSimpleFillSymbolLayerV2.create(layer_style)


2

There is no fault in the data or python script. QGIS's default for opening a raster dataset looks for a minimum and maximum value to provide band rendering. However, this dataset contains a single value. Within QGIS's layer properties style menu by setting both the Min and Max values of the dataset to the single dataset value and selecting "No enhancement"...


1

Seems like a typo. Python is case sensitive, also space between brackets and function not allowed. Change relabel (GIS_acre) to reLabel(GIS_acre) and try again.


1

There are now Python modules easier to use for that, as rasterio Rasterio employs GDAL to read and writes files using GeoTIFF and many other formats. Its API uses familiar Python and SciPy interfaces and idioms like context managers, iterators, and ndarrays. Therefore from Masking raster with a polygon feature in Rasterio Cookbook import rasterio ...


1

Why are you subtracting 180 from the lon values, e.g., "print lon[0]-180"? As I understand the NC file, the left edge of the data grid is 0.25, not -179.75. Which suggests you are extracting values 180 degrees away from where you think you are.


1

1) I just don't know how to convert .geojson file to .shp. This is a one of the bases of ogr Python. If you have a geometry, it is very easy to convert it to a shapefile # geojson is GeoJson Polygon from osgeo import ogr output = "geojson.shp" driver = ogr.GetDriverByName('ESRI Shapefile') if os.path.exists(output): driver.DeleteDataSource(output) ...


1

Edit: I checked the help for the calculate Value tool. It says: "Variables created in ModelBuilder can be used by this tool, but variables desired for use in the expression parameter cannot be connected to the Calculate Value tool. To use them in the expression, enclose the variable name in percent signs (%). For example, if you want to divide a variable ...


1

The Python installation of ArcGIS is not "standard" 1) you need first to install pip 2) then in theory you can install SciPy but SciPy is not a pure Python module, it needs compilation of C files and Windows has no compiler by default. You can try the Microsoft Visual C++ Compiler for Python 2.7 or a version of Christoph Gohlke Unofficial Windows ...


1

This worked for me from A note on configuring your IDE on Windows and tere is available information for Eclipse and Pydev, I just like using Pyscripter If you used the OSGeo4W Installer, you can find this under the bin folder of your OSGeo4W install. Look for something like C:\OSGeo4W\bin\qgis-unstable.bat. For using Pyscripter IDE, here’s what you have ...



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