Tag Info

New answers tagged

1

Gdal PYthon binding works with conjuration with gdal. You need to have installed GDAL along with the binding to work. A quick skim over the errors you provided they suggest that while you installed gdal-python you haven't install the gdal by itself: A possible solution chain is: Install GDAL (http://www.gisinternals.com/sdk/) Append the installation ...


0

Arcpy use the Numpy array format (hidden to the users) as PyGGIS that uses the Python GDAL module. provider = raster.dataProvider() # path the original file filePath = str(provider.dataSourceUri()) # open the original file from osgeo import gdal raster_or = gdal.Open(filePath) # create a numpy array numpy_array = dataSet.ReadAsArray() # shape of ...


1

I am confident that an uninstall/reinstall of ArcGIS for Desktop with Python will at least get IDLE working again. Although there may be ways to avoid doing this, employing them successfully will depend on your skillset and experience, and for me, I would find an uninstall/reinstall to be the expedient.


1

Short answer - No. ArcGIS will pass parameters as as positional arguments. Longer answer - Sort of, if you use a slightly hacky technique of accepting both positional arguments or options in your script, using the parse_known_args method. Something like: import argparse def main(arg1,arg2,arg3): print arg1,arg2,arg3 parser = ...


3

You're probably getting some sort of exception being raised. Perhaps use a Queue to pass messages back to the parent process. import os, sys, time from multiprocessing import Process from multiprocessing.queues import SimpleQueue def a_subprocess(msgs, arg1, etc): try: raise Exception('Oops') msgs.put('Finished') except Exception as ...


0

Try add third parameter to paste: self.im.paste(im, box, im)


2

I suspect the issue is the GDAL 1.11 bindings you're fetching from gohlke do not match the internal GDAL inside of Arc*. Your bindings need to be compiled against ESRI's GDAL to work reliably. It's possible they can be made to work, but it is going to be a lot of headache. In short, ESRI needs to provide the gdal_i.lib stub file that GDAL generates as part ...


1

Add a new field (text) In field calculator, round the original Percent value to no decimals, and append a percent sign: format(round(!Percent!)) + "%" or the shorter, more elegant "{}%".format(round(!Percent!)) (Thanks to Paul for the improved syntax!)


0

You can also use the format function of python if you have problems to format the string with %s. Python Format String Syntax Your uri would look something like: uri = "file:///D:/MLB Stadiums/Test_R2/Player_Files/Espinosa_2014.csv? delimiter={delimiter}s&xField={field3}&yField={field4}".format(delimiter=",", ...


0

It's having problems with the letter s, because your code specifies that as a delimiter (delimiter=%ss is getting interpreted as "," and "s"). Try delimiter=%s.


1

Related to answer I gave to a similar question (determine min and max elevation ... within my current extent), I wonder if this would work: import arcpy # this sets extent to current display, you can instead set it to ROI polygon arcpy.env.extent = arcpy.mapping.MapDocument.activeView.Extent # for a multi-band raster, pay attention to the band index (last ...


0

I think simply this will do with VBScript, using your example of 10 fields to choose from by index (0-9): int(10*rnd) ...and with a Python codeblock using numpy: import numpy.random as R def getRandom(numFlds): return int(R.random()*numFlds) The above Python block would be called by (again using a 10 field example): getRandom(10) Extending ...


0

I found this article: Integrating external programs within ModelBuilder, it is older and initially looks like it is off topic, but if you look at this: , you can see that it explicitly sets the path to the R script. When your geoprocessing script runs on the server, it runs in a scratch folder within the jobs directory. Depending on the publishing ...


2

You could still use zonal statistics with the minimum option. It produces a raster would could be used for further processing Zonal Statistics


3

Another solution would be to use the Copy Raster tool: arcpy.CopyRaster_management(in_raster, out_rasterdataset) Where you add the file extension to out_rasterdataset


1

The Raster to Other Format tool should do what you need. RasterToOtherFormat_conversion (Input_Rasters, Output_Workspace, {Raster_Format})


0

I've just written this for a similar task. It's for 10.2 but I think it will still work: def unique_values(table, field): with arcpy.da.SearchCursor(table, [field]) as cursor: dict = sorted({x[0] for x in cursor}) print type(dict) #testing to find type for i in range(len(dict)): whereD = dict[i] fname = whereD[0:5] + "_" + whereD[-4:] #just to ...


5

Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field: with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor: for row in cursor: print row[0], type(row[0]) 2014-07-18 06:03:05 <type 'datetime.datetime'> 2014-07-17 00:00:00 <type ...


1

I've attempted to remove the errors from your code. You had "\\" but you started the string with an r so I think python was actually seeing "\\\\" instead of "\". Also you import a toolbox at the beginning of the script then add another within the loop which has the same name, that makes no sense so I have commented it out. But may be wanted to use that one ...


0

The Cartogram plugin is not compatible with QGIS 2.x since it is not being maintained anymore. The only way to get it work is to get a developer to update it.


2

Apologies guys, The answer is fairly straight forward. I had not defined the name of the data frame properly in line 30. Where I had stated "layers" I should have put "Land Drainage GIS".


2

You keep on redefining s1 as an empty list for each iteration. Try this instead: s1 = [] for row in rows: s1.append(row.getValue("Count")) print sum(s1) Or: counter = 0 for row in rows: counter += row.getValue("Count") print counter For bonus points, arcpy.da, utilizing a generator expression: print sum(row[0] for row in ...


0

use the dir() function dir(intersection) ['AddGeometry', 'AddGeometryDirectly', 'AddPoint', 'AddPoint_2D', 'Area', 'AssignSpatialReference', 'Boundary', 'Buffer', 'Centroid', 'Clone', 'CloseRings', 'Contains', 'ConvexHull', 'Crosses', 'Destroy', 'Difference', 'Disjoint', 'Distance', 'Empty', 'Equal', 'Equals', 'ExportToGML', 'ExportToJson', 'ExportToKML', ...


0

found the problem: the files were still busy from the check if it contains geometries. ds=None lyr=None Setting both variables = None before actually deleting the file solves the problem.


1

here is an alternative to your solution #store field values in a new list newlist=[] with arcpy.da.SearchCursor(fc, ("valueField")) as scursor: for row in scursor: newlist.append(row[0]) #find the boundaries between classes newlist.sort() limits=[0] for j in range(newlist): if (newlist[j+1]-newlist[j])>2.5: ...


2

I think it will be more ArcPythonic to use the Select (Analysis) tool in place of MakeFeatureLayer, SelectLayerByAttributes and CopyFeatures. def unique_values(table, field): with arcpy.da.SearchCursor(table, [field]) as cursor: dict = sorted({x[0] for x in cursor}) print type(dict) for i in range(len(dict)): whereD = ...


3

If you do decide to use Make Feature Layer, note that it allows you to specify a where clause: MakeFeatureLayer_management (in_features, out_layer, {where_clause}... I haven't tested to see whether this improves performance, but you could potentially save some time by running the query while creating the layer, thus omitting the Select By Attributes. You ...


2

this tool SplitLayerByAttributes already does what you need. and a similar thread on this topic is How can I iterate Selection by Attributes?.


3

You could use the multiprocessing module. The code below creates a separate process to run the ImportCAD_conversion tool in, waits for it to complete and terminates it if the timeout is exceeded. Note the use of the if __name__ == '__main__': syntax, which is required on Windows. import os, arcpy, arcgisscripting, time, sys gp = arcgisscripting.create() ...


1

If you are adding additional pages outside of ArcGIS and will be packaging your pages together later, one possible and easy solution would be to add 2 to the PageNumber attribute in your table in ArcGIS. You could easily accomplish this in field calculator with: !YourField! + 2 And then you could add dynamic text from teh data driven pages toolbar >> ...


4

try this: ctotal = sum([row[0] for row in arcpy.da.SearchCursor("inputtable",["columnX","PercentColumn"])])#column total with arcpy.da.UpdateCursor("inputtable",["columnX","PercentColumn"]) as cursor: for row in cursor: row[1] = (row[0]/float(ctotal))*100 cursor.updateRow(row)


2

I have FOUND the ANSWER infc = arcpy.GetParameterAsText(0) repnum = arcpy.GetParameterAsText(1) gRows = arcpy.da.SearchCursor(infc, "Shape@") for row in gRows: origpoly = row del gRows aRows = arcpy.da.InsertCursor(infc, "Shape@") for x in xrange(0, int(repnum)): aRows.insertRow(origpoly) del aRows


1

it would be easier to combine with arcpy.da.InsertCursor. Note that in your code the row[1] value is the shape field. EDIT: as you found out, the main problem came from the use of 2 cursors together (and my first suggestion to use an edit session did not solve that). polygons_shape="C:\\temp\\FinalLayers.gdb\\FinalLayers\\Polygons" ...


0

Perhaps it would suffice for you to simply save the map canvas as an image after zooming to the extent of interest. Making use of mapCanvas() doesn't add too many lines of code and would export a simple PNG. From the python console, this code would produce a simple screen capture of the area oriented around a selected feature, all active layers, and any ...


0

I found the solution and got this working for QGIS 2.0. The PyQt setLineEdit method allows a line edit in proximity take ownership over the combo box. Having added "autre" to the combo box, if this item is chosen the combo box turns into a line edit. To solve my issue of data quality control, I added a block against validation if the user does not change the ...


1

Cursors can read data from the DBFs and then write that data to a "master" table that holds all the information. Note: This is going to end up making an extremely large table or feature if you have 1000 fields. I'd also suggest testing it with a much smaller subset (e.g., two) of DBF files first, to make sure the script is working correctly for your data. ...


0

I moved the connection of my pushButtons to my initGui function, and the issue is fixed: def initGui(self): ... self.dlg.ui.maintTable.itemSelectionChanged.connect(self.updateData) self.dlg.ui.existTable.itemSelectionChanged.connect(self.checkData)


1

To turn your array into a polyline you need to use arcpy.polyline, but I suspect that what you're really having an issue with is inserting features into a feature class, for this I recommend an insert cursor - they come in two flavors arcpy and arcpy.da. I generally use the arcpy (old method) but am coming to like the arcpy.da method. To use an insert ...


1

So the file names would then be fields in the output table? Seems like you would need to add a field to each table (let's call it "FILE_NAME"), merge all the tables together, then use the ArcGIS PivotTable tool (pivot on the FILE_NAME field). If you have 1000 tables, would you then have 1000+ fields? Not sure if this would be the best table structure... ...


0

That image is kind of hard for me to read, but I'd say that your custom toolbox is not part of arcpy. The error is trying to say the same thing. Adding a toolbox to ArcTools doesn't make it part of arcpy. You'd have to import it separately. Unfortunately, I've never done that in the way you're set up here, so may not be able to help. Generally, if your tools ...


1

After your newest updates to the question, this should work: def change(OldFor_Com, Area_Ha): if OldFor_Com == "OTHH": return Area_Ha / 40.0 elif OldFor_Com == "OHWH": return Area_Ha / 30.0 elif OldFor_Com == "OOFH": return Area_Ha / 375.0 elif OldFor_Com == "OSFH": return Area_Ha / 375.0 elif OldFor_Com ...


0

Going off of your latest edit and ew_GIS try this: Expression: change(!OldFor_Com!, !Area_Ha!) Code Block: def change(OldFor_Com, area): if OldFor_Com == "OTHH": return area / 40 elif OldFor_Com == "OHWH": return area / 30 elif OldFor_Com in ("OOFH", "OSFH", "OOFH"): return area / 375 elif OldFor_Com == "PINE": return area / 10 ...


1

When you read a shapefile in networkx with read_shp networkx simplifies the line to a start and end, though it keeps all the attributes, and a WKT and WKB representation of the feature for when you export the data again. To get the subset of the graph g based on the shortest path you can simply get the subraph: result_graph = ...


0

Besides the syntax errors with the ! marks, your first "if" statement is indented incorrectly


2

You need to send your area field into your calculation as a parameter. Expression: change(!OldFor_Com!, !shape.area@hectares!) Code Block: def change(OldFor_Com, area): if OldFor_Com == "OTHH": return area / 40 elif OldFor_Com == "OHWH": return area / 30


1

Your exclamation marks need to be wrapped around the field name: def change(OldFor_Com): if OldFor_Com == "OTHH": return !shape.area@Hectares! / 40 elif OldFor_Com == "OHWH": return !shape.area@Hectares! / 30 Also, make sure Python is the defined Parser.


5

It has already been created. Try SplitLayerByAttributes


0

One way this can be done is in a python script. You'd need to ask for the name of the field you are interested in (in your case it would be the county code) and extract unique values from its rows with a SearchCursor. You could save the data to a list and then iterate through the list and use a where clause with arcpy.Select and output each separate ...


1

Usually, the field in a VAT is Count and it's case sensitive. Try: Rows = arcpy.SearchCursor("sti-9") for row in Rows: count = row.getValue("Count") print count del row, Rows For Arcgis 10.1+ with arpcy.da.SearchCursor("sti-9", ("Count")) as cursor: for row in cursor: count = row[0] print count


1

Your logic is correct. This help guide may help you out in the future for using python in the field calculator. There are already valid pythonic answers above I'll post another option, in VB (sometime's it is simplier than python). In field calculator choose "show codeblock" for "Q2" under "Pre-logic script code" write: In VB: if [Q1] = "a" then result ...



Top 50 recent answers are included