Tag Info

New answers tagged

0

Hey moderator that deleted my last post on the same topic, please leave this one up. This is completely relevant because I don't believe the answers above still work and I'm not the only one that's struggling here. Either I'm crazy, or the two bits of code no longer work. I've copied these and tweaked them for my use and for the life of me I can't get a tif ...


0

1) you don't need to export a shapefile. With the Python module GDAL (osgeo) you can read directly the layer from the GRASS folders hierarchy (look at GRASS 6 terminology) from osgeo import ogr # open the Grass layer shape1 ds = ogr.Open('/Users/grassdata/geol/MNT/vector/shape1/head') layer = ds.GetLayer(0) ... 2) If you want to read the shapefile, you ...


2

As asked by the OP, I put this in answer. The problem wasn't with the method used, as ogr.Geometry.Union() is the appropriate one but with the second polygon which was not closed. It can be done with : tri2.CloseRings() or by repeating the first point : tri2.AddPoint(1,1) If there is many features to dissolve (like the entire layer) it can be done with ...


0

Reposting Kersten's comment as an answer so I can accept it as solution: fiona.open returns an iterator so it will only return one element at a time in memory. The documentation has some examples on storing iterator results in memory, e.g. lists My solution was to create a list from the source: newsource = list(source)


1

After having investigated the QGIS code, I'd decided that custom code needs to be created to store and load composer configurations. The QGIS desktop app does it all with custom classes and not the common library, so a standalone app written in python is going to have to do the same for the time being. relevant files: src/app/composer/qgscomposer.cpp ...


0

Uhmm no, I was trying to do a better explanation of my question. Anyway, I eventually could do it using numpy and GDAL. I needed to get the pixels values within some polygons, so I convert the polygons to rasters and then I could easily perform different masks and calcs. I find this process really easy with arcpy, but no idea of how to do this with other ...


1

You will need to call the method QgsComposer.readXML(node) with the XML node representing the composer you want to load. The QGIS desktop app does it this way: create a slot method that takes a parameter loadComposers(doc) Search for doc.elementsByTagName("Composer") Iterate over all found xml_nodes and Create a new QgsComposer Call ...


1

This looks like a bug in the plugin. I would suggest to open an issue report. Please note that gis.se is not a bugtracker and it is unlikely that this post here will help to fix this issue. For further possibilities to proceed, please have a look at this answer.


1

You can do that from the QGIS Python console in this way: Copy the next function, taken (and slightly adapted) from the Processing framework source code, into the QGIS Python console: from processing.core.Processing import Processing from processing.gui.AlgorithmDialog import AlgorithmDialog def runAlgorithm(alg): """ Borrowed from CommanderWindow.py, ...


0

Besides GDAL/Fiona you can alternatively use PyCRS, a package written in pure Python specifically for defining and converting between and projection formats. So in your case: import pycrs wktstring = ...


0

QGIS provides a simple API to get this information. You need to get the index of the field in question and then query the layer for unique values. idx = vectorLayer.fieldNameIndex('fieldName') values = vectorLayer.uniqueValues( idx )


2

Using QgsMessageLog you can do variable interpolation in strings using the usual python % operator: >>> QgsMessageLog.logMessage("hello") >>> x=99 >>> QgsMessageLog.logMessage("x is %s" % x) shows me "x is 99" in the message window.


2

From documentation: pushMessage(const QString &title, const QString &text, MessageLevel level=INFO, int duration=0) So, first and second agruments are strings. If you have some variables in your plugin, and you want to pass them into this function, you have to convert them to strings. For example we have a variable which contains coordinates and ...


1

I've tried your code, but it not work. It can't find selected feature. So, I make an edit from your code. This is the edited code: def selectFeature(self, point, button): pntGeom = QgsGeometry.fromPoint(point) pntBuff = pntGeom.buffer((self.canvas.mapUnitsPerPixel() * 2), 0) rect = pntBuff.boundingBox() cLayer = ...


1

in your plugin init() you can add a listener to iface.initializationCompleted signal http://qgis.org/api/classQgisInterface.html#a6f1cc8be7d4e0b4c76c2806b78b3d8b0 then do what you want regards


0

As of version 1.8, GeoDjango does support raster data handled by GDAL. https://docs.djangoproject.com/en/1.8/ref/contrib/gis/gdal/


0

You can use the following script (save it in Processing Toolbox > Scripts > Tools > Create new script) in the graphical modeler to copy the first row of attributes and apply it to each feature in the input layer. (Unfortunately I was unable to add a filter for your required fields so hopefully others can provide a solution which completely answers your ...


2

To simplify matters, I'll assume your excel spreadsheet is really a csv file with no headers and is formed like: field_name,alias: import arcpy, csv csvfile = "<path to file>" FC = "<path to feature class>" #List of tuples name_alias = [rows for rows in csv.reader(open(csvfile))] errors = [] for name,alias in name_alias: try: ...


1

Great methods already posted! There are also tools from the Processing Toolbox which you could call from your script (this is assuming you are running scripts inside QGIS): Count points in polygon Counts points in polygon (weighted) Count unique points in polygon Taking the first tool, you could call it using: import processing Result = ...


1

It is a pure Python question: in your script you initialize the list at each iteration t = [1,2,3,4] for i in t: l = [] l.append(i) print l [4] while l = [] for i in t: l.append(i) print l [1,2,3,4] or with list comprehensions l = [i for i in t] So, your script becomes: l = [i.attributes() for i in layer.getFeatures()]


1

In this order: l = [] for i in layer.getFeatures(): l.append(i.attributes()) In your code you have list which is created and overwritten each time.


1

the most simple way is to use "Join attribute by location". You can do it from the menu (data managment > Join by location), or with Python ("qgis:joinbylocation") with the option "take summary of intersecting features", computing the sum of a field with "1" at each point.


3

I rewrote my answer from a parallel question counting points in current atlas feature: How to count points within the current Print composer atlas feature in QGIS 2.8? Build a new function in the expression editor: from qgis.core import * from qgis.gui import * from qgis.utils import iface @qgsfunction(args="auto", group='Custom') def ...


2

Not sure if there's another way, but this is how I've implemented it. You need these three functions (make sure you import the required QGIS and Qt4 classes before): def createMapTips( self ): """ Create MapTips on the map """ self.timerMapTips = QTimer( self.canvas ) self.mapTip = QgsMapTip() self.connect( self.canvas, SIGNAL( ...


1

I assume your polygon is a qgsfeature : http://qgis.org/api/classQgsFeature.html I didn't test it but I guess it would work : len(polygon.geometry().asPolygon()) polygon.geometry() gives a qgsgeometry class. qgsgeometry.asPolygon() gives a list of the point of your polygon. Edit : You want the points inside the polygon? You have points in an other ...


1

I have never worked with QGIS's python API, so my answer is a wild guess. But it looks like QGIS is using GEOS geometry objects similar to django. So this could work in QGIS too: len(geom.coords)


0

I faced similar situation recently and in my case opening ArcMap didn't solve the error. Later I found out that it has to got to do with Business Analyst Licensing. One more thing is you need to checkout the license for BA extension in Script something like this.. arcpy.CheckOutExtension("Business") In my case it was supposed to be some BA premium license ...


1

I have run into a similar problem in the past. ArcGIS was importing columns as interger and truncating leading zeros. ArcGIS uses its own method of determining column types. I had to specifically tell ArcGIS that the attribute column was to be text by using a schema.ini file. This is the article I used to get started.


0

I think that if you erase the old python.dll file from system32 and syswow64 folders, (keep a copy of these files to revert the proces just in case) and then install again python from the installation dvd, this could fix your problem. I took the python.dll file from the other computer were Argis+python were working fine, but if you don't have another ...


0

I found a solution which I hope it will work for you. I have tried everything written in this post and python still was not working into my arcgis; giving the message 000574 error Python is not installed. I have Win7 64 bit, and I was using Arcgis 9 then, installed Arcgis 10 and then, upgraded to 10.2 last three years, and in my last installation Python ...


-1

To answer this question nowadays (since ArcGIS 10.1 SP1) I would recommend the answer from @djq in conjunction with using arcpy.da.Walk to walk the folder structure: Generate data names in a directory/database structure by walking the tree top-down or bottom-up. Each directory/workspace yields a tuple of three: directory path, directory names, and ...


0

In the meantime I created a small python-based library that can create simple static images. You can find it on github: https://github.com/komoot/staticmap


4

No - in_memory workspaces are only similar to and not identical to geodatabase workspaces. They support feature classes but not feature datasets. This is documented on the Using in-memory workspace help page: Feature datasets or folders cannot be created in the in-memory workspace.


4

Try in your script: from qgis.utils import iface #your code here iface.actionExit().trigger() It works for me. Editing Note: Based in Conley Owens'comment, I changed slightly my script to do "something useful" (where the line that import iface was commented). #from qgis.utils import iface import os os.system('clear') print "Hello" ...


2

This should be all you need: feats = self.layer.getFeatures() self.layer.startEditing() for feat in feats: score = scores[i] feat['F_SCORE'] = score layer.updateFeature(feat) self.layer.commitChanges() You are mixing update via the layer vs at the provider. Generally you should only update via the layer as it provides rollback and error ...


1

My solution is to set up a startup script that sets of the path based on the python environment you are using. This method has the (huge) advantage that you don't need admin access to write .pth files in python installations. This script is setup to use both 32 bit and 64 bit Anaconda and ArcGIS/arcpy. # Startup script to link Anaconda python ...


1

You can install just ArcPy by installing ArcEngine, but this comes with all of the libraries and dependencies that come with Engine. The luxury of this is that Engine is cheaper to install and it can also be run on Linux.


4

Arcpy must be installed with one of Esri's applications like ArcGIS Desktop, Arcgis Server, ArcEngine. With Arcpy, there are dependencies on arcgis binaries (dlls). You can find those dependencies and with some hacking achieve what you are looking. However this is against the terms of use of esri software.


2

The function overview is from rasterios command line interface rio. What you are looking for is the function build_overviews inside the standard I/O class of rasterio. How to use that? I have absolutely no idea since I never needed it so far. Luckily rasterio includes an extensive test suite which also includes one called test_overviews.py. If you look at ...


1

It requires ArcGIS, but see my detailed response here in another GIS StackExchange thread regarding building networks and simplifying data while maintaining the topological structure: Building Large Network Datasets from OpenStreetMap in ArcGIS?


2

If your interested in using a microservice that you can run yourself, instead of a library check out https://github.com/trailbehind/StaticMapService/. You can install background layers into it, then post GeoJSON and get back map images. You mentioned facebook preview images, and that's exactly what I wrote it for. The image url points at a public web server, ...


1

You can find some hints in the open source code of the JOSM editor, that program has a way-simplify-feature inside. Or have a look at that JOSM plugin named RemoveRedundantPoints


1

This sounds like a fun problem. I would consider: Read the land boundary shp file using one of these recipes: How to install Fiona to read Shapefile attributes with OSGeo4W?. It would probably be good to read it into a Shapely geometry. I like using ogr to read shapefiles: import ogr import shapely driver = ogr.GetDriverByName('ESRI Shapefile') ...


0

@geowurster's request on stack trace made me do one more debugging round. The raster's dimensions were 5033x5665 pixels, and I found that it crashes while writing the tile including pixels (0-63)x(4992-5055). I assigned the dimensions to the new raster in the wrong order, so it tried to write outside the raster. I switched the shape indexes and it works: ...


2

http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html If you looked here, there is "?" between name of file and "delimiter". Hope it helps.


1

Yes. But the publishing process will NOT copy the dll. You'll get an analyzer error. You'll need to register the DLL directory with the datastore so ArcGIS Server doesn't try to copy it. See this link, it should be the error you get when trying to publish. You'll probably want to use a replicated data store entry as it sounds like you are not working on ...


2

Just to add to @PolyGeo's answer that I also could not find any official documentation regarding multiprocessing (if it even exists!). But there is also another method, described in this blog, which uses multithreading in QGIS which might be useful. Main difference between the two methods are (more of which is discussed here): Multiprocessing allows ...


1

As mentioned by TsvGis, you'll probably need to embed the font in the document. You appear to be using reportlab for this, check the FAQ on their site, they have an example of how to embed fonts - section 2.6.2 Be aware that there might be licensing issues on some commercial fonts (they may not embed properly). If this is the case there are plenty of ...


4

you may explore these modules: https://github.com/qgis/QGIS/tree/master/python/plugins/processing/gui you should import with: from processing.gui import <what you want> and gui use can be read directly from the processing plugin code regards



Top 50 recent answers are included