Tag Info

Hot answers tagged

6

Use arcpy.env.overwriteOutput. arcpy.env.overwriteOutput = True # Execute ZonalStatisticsAsTable outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, outTable, "NODATA", "MEAN")


5

Try adjusting your code, your /n should be \n: arcpy.CalculateField_management("path/to/my/layer","field","RemoveBad( !field!)","PYTHON_9.3","def RemoveBad(x):\n x = x.replace(\"<=\", \" Less Than or Equal To \" )\n x = x.replace(\">=\", \" Greater Than or Equal To \")\n x = x.replace(\"<\", \" Less Than \")\n x = x.replace(\">\", \" ...


5

You can place all the feature classes within a single dataset then use model builder to clip all at once and output to a new dataset:


5

In you case (only one tool), you can simply right click on the clip tool in your toolbox, and launch it as a "batch". See the ArcGIS help for more details


4

Try converting your rasters to numpy arrays and then check to see if they have the same shape and elements with array_equal. If they are the same, the result should be True: import arcpy, numpy raster1 = r'C:\path\to\raster.tif' raster2 = r'C:\path\to\raster.tif' r1 = arcpy.RasterToNumPyArray(raster1) r2 = arcpy.RasterToNumPyArray(raster2) d = ...


4

You can use a simple block of code either directly from Python window in ArcGIS or as a Python script or as a custom script tool. Below is a sample code for a script tool. Just add your vector layers into a map document (.mxd) and specify the clip layer and the output geodatabase. import arcpy arcpy.env.overwriteOutput = True clip_layer = ...


4

I found the solution on an ESRI blog. The idea is to convert the raster to a raster object and then access the specific NoData value with .noDataValue. import arcpy arcpy.env.workspace = r'C:\temp' rasterList = arcpy.ListRasters() for raster in rasterList: rasterObj = arcpy.Raster(raster) noData = rasterObj.noDataValue print "NoData Value: ...


4

You need to specify that this function requires the geometry with the kwarg usesgeometry=True. If you don't, you may get a geometry but there is no guarantee (as you realized). This works starting from QGIS 2.4 from qgis.utils import qgsfunction from qgis.core import QGis @qgsfunction(0, "Python", usesgeometry=True) def test(values, feature, parent): ...


3

Same question received an answer from geoserver-users mailing list http://thread.gmane.org/gmane.comp.gis.geoserver.user/43129/focus=43205 The advice was to search for available featuretypes with REST as in the example curl -v -u admin:geoserver -XGET -H "Accept: text/xml" http:// ...


3

I would use a search cursor to find out if there are any rows in a table with empty string (i.e., ""). fc = r"C:\ArcGIS\Default.gdb\Parcels" with arcpy.da.SearchCursor(fc,"RouteName") as scur: for field in scur: if field[0] == "": #dissolve on one field else: #dissolve on another field


3

per comments - it seems the raster band properties contain a read-only no data property. import arcpy desc=arcpy.Describe('rasterName') print desc.noDataValue resulted in a value of -3.40282346639e+38 on a single bad ESRI binary grid that i had lying around. thanks!


3

first you need a double == for your test, simple = is for assignment, not testing second you forgot the indentation and a semi-colon def MyCalc(Kultur,DG): if (Kultur == DG): return 1 else: return 2 third, DG must be identified as a string MyCalc(!Kultur!,'DG') it would go the same way with numeric values (you don't need quotes ...


2

I found this gudie by Anita Graser a couple of days ago, and it looks like just what you need: http://anitagraser.com/2014/05/31/a-guide-to-googlemaps-like-maps-with-osm-in-qgis/ Using that method you can define the lat-long box that you are interested in and apply it to .pbf file downloaded from the Geofabrik site.


2

To copy shapefiles from multiple folders into a single geodatabase, you could do this: import arcpy import os ws = #path to input folder dst = #path to output geodatabase for dirpath, dirnames, filenames in arcpy.da.Walk(ws,datatype="FeatureClass"): for file in filenames: print file filepath = os.path.join(dirpath,file) outpath = ...


2

You could try popping from your csvdict list after using a row to rename a raster: for layer in arcpy.mapping.ListLayers(mxd): for i in range(len(csvdict)): if layer.name == csvdict[i][0]: layer.name = csvdict[i][1] csvdict.pop(i) break


2

The output from the GetCount method is not fully correct, so your if statement is not going down the correct path. Use the .GetOutput method: count = arcpy.GetCount_management("A_Squares") ACount = int(count.getOutput(0)) if ACount == 0: print "empty cursor" else: for row in cursor: #...etc


1

The easiest way is to subtract one raster from the other, if the result is 0, then both images are the same. Also you can see the histogram or plot by color the result.


1

I would suggest that you build your raster attribute table for each image, then you can compare the tables. This is not a complete check (like computing the difference between the two), but the probability that your images are different with the same histogram values is very very small. Also it gives you the number of unique values without NoData (from the ...


1

It may not be completely necessary to delete the row object, but if you just define it first you should be golden. cursor = arcpy.SearchCursor("whatever") row = None # Define it here for row in iter(cursor.next, None): # ... del cursor del row


1

I noticed I could define the extent in the properties of the layer, export to layer file and then to .tif in ArcMap, so figured there would be a layer python command to make this in memory. Use "gp.MakeRasterLayer_managment" to make a temporary raster layer with the extent set to be the desired file extent. export the layer with gp.CopyRaster_management to ...


1

I would advice using a library for using REST from python, eg requests http://docs.python-requests.org/en/latest/index.html r = requests.get('http://localhost:8080/geoserver/rest/workspaces/myworkspace/datastores/mydatastore/featuretypes?list=available', auth=('admin', 'geoserver')) then use r.text or r.json


1

it is recommended to use subprocess.call() cmd must be a list, so you should write it like : cmdlist= ["curl", "-v", "-u", "admin:geoserver", "-XGET" ,"-H", "Accept: text/xml", "http//jdkjdf"] note that you can use .split(" ") to create the list based on your variable cmd


1

I would generate a list from the rt_long_nm field with a list comprehension and use that for the logic check. The list comprehension searches for all values except for None and adds those to a list. If the length of the list equals 0, perform some action, else perform another action. import arcpy OutShapesFCname = r'C:\path\to\fc' vals = [row[0] for row ...


1

layer = cat.get_layer("yourlayer") if layer.enabled: print "Layer is published" else: print "Layer is not published" Layers provide these settings: enabled is a Boolean flag which may be set to False to stop serving a layer without deleting it. If this is set to True then the layer will be served. Refer to this webpage.


1

The .loc files generated by an address locator are plain text files. Therefore, you can modify any settings that are specified in the .loc file without the need for an arcpy function. For example, to change the minimum match score from the default to 70%: locator_fn = 'my_address_locator.loc' locator_file = open(locator_fn,'a') # open for appending ...


1

The simplest solution I have found thanks to GISGe's hint is modifying only the updateParameter() method in validationtool class, adding this code. if self.params[0].value: self.params[4].value = "output" This will generate a string with the default workspace with basename, "output". I dont have to modify the python script at all. Thanks to all!!!


1

You should use arcpy.Describe() and/or the os.path Python module. For example: import arcpy, os input = arcpy.GetParameterAsText(0) output_workspace = arcpy.Describe(input).path # the file path, or geodatabase for geodatabase datasets suffix = 1 output_name = arcpy.Describe(input).baseName + "_" + suffix # the file base name + a suffix ...


1

Not sure what you mean. The only options are to "derive" a parameter, ie. when you select a featureclass as a first parameter, one of the derived parameters could be a list of fields for the second input parameter. Alternately, you can provide defaults for any parameter so that when a tool is opened, it will appear as the default option.


1

socket.gethostname() returns the name you (or your administrator) have given your computer. This must be english letters (ASCII). Try to change your computers name to only include english letters.


1

Here is a way to set a primitive progress bar. Design is based on example you can found within the PyQgis Dev. Cookbook (see section 11.2) Example is designed to work with features of a QgsVectorLayer but it shows the main steps you could adapt for your process algo. The key to your problem is to find a way to evaluate the progression of your algo within ...



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