Tag Info

Hot answers tagged

4

kind of figured it out as soon as I posted. Figured I should post the answer... arcpy.CalculateField_management(myFeatureLayer, field2, "!field1![0:4]", "PYTHON") suppose I should add that one can apply any standard Python string functions to !field1! and that this syntax can be used in the Field Calculator if one toggles the Python radio button to the on ...


4

Here's a script I put together. The script uses your point and your line feature class, and outputs a new line feature class of line features as desired. The basic steps: Iterate through points Create a buffer around each point Create East-West line from each point. This will be used to slice your buffer in half Create point north of each input point. This ...


4

I hacked together a solution for this and wrote a blog article a while back on a very similar topic, which I will summarize here. The script is intended to extract a river from a 4-band NAIP image using an image segmentation and classification approach. Convert image to a numpy array Perform a quick shift segmentation (Image 2) Convert segments to raster ...


3

open CalculateField tool for 'Field Name' parameter specify: DI for 'Expression' parameter specify: x(!Max_GRIDCODE!) for 'Code Block' parameter specify the code below def x(v): if v > 2: return 5 elif v > 1.5: return 4 elif v > 1: return 3 elif v > 0.5: return 2 else: return 1


3

You could look at clustering in scikit-learn. You will need to read the data into numpy arrays (I'd suggest rasterio) and from there you can manipulate the data so that each band is a variable for classification. For example, assuming you have the three bands read into python as red, green, and blue numpy arrays: import numpy as np import sklearn.cluster ...


2

This works for me and I have labeling only with 2nd word: So maybe you have few atributres without " ", and you get "out of index". def label([SSA_NAME]): x = [SSA_NAME] x1 = x.split(" ") if len(x1)>1: return x1[0] + " " + x1[1] else: return x1[0]


2

Several things to check here: Firstly, make sure that %QGIS_PATH%\apps\qgis\python\plugins\processing is added to the PYTHON_PATH environment variable. Secondly, instead of: import processing from processing import * Use: import processing from processing.core.Processing import Processing Finally, before calling any algorithms using processing, do ...


2

Geopandas plot takes a colormap parameter GeoDataFrame.plot(column=None, colormap=None, alpha=0.5, categorical=False, legend=False, axes=None) The pandas documentation mentions colormaps such as colormap='cubehelix' colormap='Greens' colormap='winter'


2

Alright great I managed to solve it, I hope this answer helps others. while True: try: YesNo = raw_input("Do you need to change a field name (Yes/No): ") except ValueError: print("Your Input is invalid") continue if YesNo == "Yes": VB = raw_input("Enter VB Expression to change Your Field: ") ##This is the expression I use: ...


2

Try simply: layer = iface.addVectorLayer("/path/to/shapefile/file.shp", "layer_name_you_like", "ogr") Here you have a nice guide for PyQGIS: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/intro.html


1

Just as a remark: QgisInterface is an abstract class and has virtual functions so it may not be instantiated, i.e. it defines an interface and not a complete implementation. But you can use QgisInterface class within a standalone application where the iface class is not available. There you can reimplement and override the main functions of the class. An ...


1

If you look at the source code for the context manager qgisapp: https://github.com/qgis/QGIS/blob/master/python/core/contextmanagers.py you'll see it is just a neat wrapper for running code inside a QgsApplication context. Following what Nathan W does with his Qgis python is usually a good idea, so I'd go with this.


1

You can listen to the extent changed event and reset it back if it goes outside of the bounds: def extentsChanged(): extent = iface.mapCanvas().extent() outofbounds = # Do your check if outofbounds: iface.mapCanvas().setExtent(newextent) iface.mapCanvas().extentsChanged.connect(extentsChanged)


1

Try script below. It is very old (2008) - one of my very 1st Python scripts, not elegant at all and can be rewritten using a fraction of code. It works, so never bothered to renew it. Script takes 4 parameters as inputs. I hope you know how to define script parameters in parameters dialog. outputFolder - folder where table based image catalog will be ...


1

You can simply use: my_sr = arcpy.SpatialReference(my_wkid) Then use my_sr however you wish. ESRI Documentation - ArcPy SpatialReference


1

You can use the OpenCV package in Python for image thresholding. This example shows not only how to perform the binary image thresholding, but also the limitations of this method. Here, I use a 1m spatial resolution NAIP image that shows a dirt road surrounded by arid vegetation. You can see that the road is extracted but there is also a significant amount ...


1

Here is an Update Cursor approach: import arcpy shp = r'C:\path\to\your\shapefile.shp' with arcpy.da.UpdateCursor(shp, ["field1", "field2"]) as cursor: for row in cursor: row[1] = row[0][:4] cursor.updateRow(row)


1

Indeed, you could create a python addin to do this for you! http://resources.arcgis.com/en/help/main/10.1/index.html#//014p00000025000000 Basically, you would be able to create a tool that could sit in your bosses tool bar. Using the tool your boss could click the map and get the data back for the area as you described. The tool would take care of all the ...


1

When you created your script tool you would have gone through that wizard to wire up your script to a tool interface. At the stage where you point it to the script python file (.py) there is a check box which is usually un-ticked which is Show command window when executing script, try ticking that on?


1

If you want this as a python script, then you could do something with an update cursor... inputData = "" #Needs to be the full path codeField = "" updateField = "" with arcpy.da.UpdateCursor(inputData, [codeField, updateField]) as updateRows: for row in updateRows: if row[0] == "TestValue1": row[1] = "NewValue" elif #... etc ...


1

The solution is to use from PyQt4.QtGui import QRegExpValidator and from PyQt4.QtCore import QRegExp then use the code: rx = QRegExp('^[1-9]\d{3}$') validator = QRegExpValidator(rx) self.boundwidgets['flatenr'].widget.setValidator(validator) See https://github.com/DMS-Aus/Roam/issues/239 for more details about the solution.



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