Tag Info

Hot answers tagged

5

You have to insert a list, you're inserting a single value. for uv in uniqueList: cursor.insertRow(uv) should be for uv in uniqueList: cursor.insertRow([uv])


4

You are trying to put a string into the insertRow method, but that method expects a list or tuple. The insertrow method first counts the items in the list or tuple to see if the item count matches the row field count, but since a string item count is most likely 0 it always fails to match up with the field count of the row (i.e., 1). So instead try ...


4

The error is due to the fact that you're using a tuple (returned from your cursor) as your input for your MakeFeatureLayer_management. This function requires a feature class or layer as its input. If you're wanting to know where your layers lie in relationship to a polygon, I suggest using a spatial join as opposed to a cursor. It is faster, and a good ...


4

Here's what you need to do, with comments: # Reference the MXD containing your layers. # If you're doing this in the Python Window of the MXD, # use the "CURRENT" keyword instead of providing a path # to the MXD you already have open. mxd = arcpy.mapping.MapDocument(r"C:\Users\Daimon Nurse\Desktop\Zonetrial.mxd") # mxd = ...


3

Using rasterio: import rasterio with rasterio.open('sample.tif') as r: ar = r.read() The ar array has 3-dimensions [band, row, col]


3

Not very elegant but this should work: output = Dir + "\\" + (fc[:2]+"_"+fc.split("_")[1][:-4])[:13] By the way, not sure if there was an indentation issue when you pasted the code in GIS.SE, but the for loop should be something like: # Loop for fc in fcList: output = Dir + "\\" + (fc[:2]+"_"+fc.split("_")[1][:-4])[:13] # Process: Polygon to ...


3

As you can see in the QGIS API docs, when you call getFeatures() with no arguments, QGIS gets a QgsFeatureRequest() by default. That is, QgsFeatureRequest() is the default value for the first argument of getFeatures(). You can choose whether or not passing it, the result is the same. Also from the docs, by calling QgsFeatureRequest() you: construct ...


3

Have a look at this bit of code as your fieldB is of type string it does not need to do any type conversion. This bit of python goes in the code block: def numonly(s): if s.isdigit(): return s else: return ""


3

Not sure I am understanding the workflow correctly but like Beck said I think this is does the trick. Foo is the original shapefile you are deleting all the features from, Bar is the layer you are copying features from. import arcpy # Data foo = r'C:\Path\to\layer\that\will\be\blank.shp' bar = r'C:\Path\to\layer\that\gets\copied.shp' # Delete Features ...


3

Yes, using the SetGeoTransform method. The Geographic Transform defines the origin of the raster in the upper left hand corner, as well as the cell size and the rotation in the x and y direction for the cells in this format: geo_transform = (x top left, x cell size, x rotation, y top left, y rotation, negative y cell size) Or in the example you've ...


3

A couple things to note: Your code block is currently taking two arguments, but you really only need to take one. AKA_STREET_TEST1 is the result you want, not something that Calc() will consider when calculating. So your expression should be Calc(!STREET1!) -- because you want the function Calc to do something using the information from field STREET1, and ...


2

It sounds like you've got the right idea but you're testing if STREET1 is perfectly equal to "AVENUE". Because STREET1 has the road number in it though, it will never be equal. Therefore, you would need to see if it contains AVENUE, not just is equal to AVENUE. If you use the python find() function on a string and it doesn't contain the value you're ...


2

you could use the find() function def Calc(street): if street.upper().find("AVENUE") >=0: return street.upper().replace("AVENUE","AVE") Calc(!street!) Note that Python is case sensitive, so I added upper() to take all cases into account


2

Try this if you are updating existing field and @radouxju method for populating new field: def Calc(STREET1): return STREET1.replace('AVENUE','AVE')


2

I prefer the latest builds from Gisinternals. Note that the link has recently moved to http://download.gisinternals.com/. It gives you always the latest Windows builds of GDAL and PROJ. The binaries linked on the PROJ page are version 4.46, and quite outdated. The current version of PROJ is 4.8.0 PyProj might be a benefit if you do things programmatically, ...


2

I would use regular expressions for this. You can use this in an arcpy script to update the field by setting the m.group(index) to be the field value. It is of str type. import re reload (re) r = re.compile("([0-9]+)([a-zA-Z]+)([0-9]+)") m = r.match("123ab1234") if m: print m.group(1) print m.group(2) print m.group(3) else: print "no ...


2

This is a known issue. The current version of scipy (actually numpy) is not compatible with python distribution that comes with ArcGIS, although theoretically they should. The core reason is that scipy is not pure Python (for speed) and hence it matters which API against which things have been compiled. I had that issue and I never found a compatible ...


1

To split a string into a list of numbers you can use regex in this way as well: import re s = re.split('[a-z]+', '123ab987') print s ['123', '324'] and for your , problem you can use this regex: s=re.split('[a-z|,]+', '123bc324,1,3,4') print s ['123', '324', '1', '3', '4'] but you have to be a bit carefull. Because if the first/last character is also ...


1

I've tested the attributeValueChanged SIGNAL in a created-from-scratch test plugin using QGIS v.2.6.1 You can connect the SIGNAL to your slot this way (I did it in my run() method): def run(self): self.lyr = self.iface.mapCanvas().layers()[0] self.lyr.attributeValueChanged.connect(self.mySlot) And then, you have two options to write your slot ...


1

So the event that works IS attributeValueChanged. I simply needed to add some arguments to my function, as mentioned by another user. This works now: def myFunction(self): self.myLayer.attributeValueChanged.connect(self.myOtherFunction) def myOtherFunction(self, fid, idx): self.myLayer.dostuff self.dlg.show()


1

As per this question I think you (or your IT staff) need to run the autorun.exe application, it will launch the startup window (otherwise known as the Quick Start Guide) of the 10.2 installation for Desktop. From here you can install the 64-bit BGP. I realize that this refers to 10.2 not 10.2.2 but I think it is the same process. Just a side ...


1

The gdal.Dataset class also has a ReadAsArray method which will read multiband rasters into an ndarray. For example: >>> ds=gdal.Open('multiband.tif') >>> print ds.RasterCount, ds.RasterYSize, ds.RasterXSize 4 256 256 >>> nda=ds.ReadAsArray() >>> print nda.shape (4, 256, 256) Note: the code in your question is not ...


1

Right, I've tested your script and, as you say it doesn't throw anything (not even errors) when I run it. Try instead this script, it works for me on Linux, emulating your scenario (moving processing folder to my script folder): # Prepare the environment import sys from qgis.core import QgsApplication from PyQt4.QtGui import QApplication app = ...


1

I would use below code-- If you have access to "Data Access Module" import arcpy,os,sys pattern = 'fish_46.shp' folder = 'C:\Users\USER_NAME\Desktop\delete'## root folder field = 'Id' ## your field where calculation to be applied files_process = [] for root,dirs,files in os.walk('C:\Users\USER_NAME\Desktop\delete'): for filenames in files: if ...


1

Code works fine with single quote on my machine. I think it is something to do with gdb naming, (& character?). See if slightly modified code will help to track what's wrong # Import arcpy module import arcpy, traceback, os, sys try: def showPyMessage(): arcpy.AddMessage(str(time.ctime()) + " - " + message) ## arcpy.env.workspace = ...


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 top of the ToC following these steps: Get a reference of the layer tree root = QgsProject.instance().layerTreeRoot() Create the layer object from PyQt4.QtCore import QFileInfo fileName = "/path/to/raster/file.tif" fileInfo = ...


1

What you need is exactly what Load Them All plugin does. It can load several vector or raster files at once from a base directory you set. Additionally, the plugin can: Load rasters of a particular format (e.g., only .tif) Create groups in the ToC to reflect your folders in the hard disk. Groups can be nested. Turn off loaded layers. Load layers based on ...


1

Pythonic way of what Brad Neson and help for GISKid too.. import arcpy arcpy.env.overwriteOutput=True fc= r"C:\Users\USER_NAME\Documents\ArcGIS\CWS.shp" ## path to your input feature class output = r"C:\Users\USER_NAME\Documents\ArcGIS\CWS_Unique.shp" ## path to your output feature class ...



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