Tag Info

New answers tagged

0

I solved the problem... import arcpy, os, string fc = "D:\\path\\test.shp" fieldNameList = [] fields = arcpy.ListFields(fc, "*") for field in fields: if field.type in ("Double", "Integer", "Single", "SmallInteger"): fieldNameList.append(field.name) with arcpy.da.UpdateCursor(fc, fieldNameList) as cursor: for row in cursor: ...


1

You are currently passing a single string, so the cursor is looking for a single field named 'tt', 'ff', 'vv', 'rr', 'update' instead of individual fields tt, ff, vv (etc.) Your field name list can be directly used in the UpdateCursor: with arcpy.da.UpdateCursor(fc, fieldNameList) as cursor:


0

thanks for your answer, but I really want to mix vector and raster. I mean, what I need is to get the raster values in the coordinates of a vector. I have don it with arcpy and the extract point values tools: import arcpy, os, time, re from arcpy import env from arcpy.sa import * # Set environment settings ruta = env.workspace = r"X:\somepath" #ruta = ...


4

edit: I didn't quite get what you were trying to do, but this should work as a sort of cumulative function. Untested (there may be some errors with indices): import arcpy, os, string fc = "D:\\path\\exampless.shp" fields = arcpy.ListFields(fc) fieldNameList = [] for field in fields: if field.type in ("Double", "Integer", "Single", "SmallInteger"): ...


0

Which version of QGIS are you using? QGIS < 2.8 had some severe memory leaks with the zonal statistics calculations, but these should be fixed in 2.8 and above.


0

in your case qgis.utils.iface.activeLayer() return the last selected one. To obtain selected layers use the ability of the TreeView that contain the layer list. More directly: iface.layerTreeRoot().selectedLayers() more detail exploring the class QgsLayerTreeView: http://qgis.org/api/classQgsLayerTreeView.html obviously this work after legend refactoring ...


2

Not seeing your code, this may not work for you, but you can try to use the Python list selector: for row in sorted(arcpy.da.SearchCursor(fc, [f1, f2]))[:5]


0

OK, I see you revised your question a bit. This script should get you most of the way there. The script will take a list of shapefiles and if there are more than 1 found in the list, it will buffer each shapefile and do a merge. If only one is found, it will only do the buffer. Just put in your own list of shapefiles in the main function. import arcpy ...


0

The title ('Extract raster values ...') is not reflecting your code instructions because you are mixing vector and raster layers. Assuming that the answer is only for raster layers, I think that the best way to read in them (for any purpose with Python/GDAL) is by using a scanline and the unpack struct function. The code is more compact, the control is more ...


0

For the record: The reporter opened a ticket http://trac.osgeo.org/grass/ticket/2610 - the answer is that the problem has already been solved in GRASS GIS 6.4.svn. It will be published with the upcoming 6.4.5 release or a nightly/weekly snapshot is used.


0

Sorry for the code format. I posted again: import os, sys try: from osgeo import ogr, gdal from osgeo.gdalconst import * os.chdir('/home/digd/Desktop/puntos') except ImportError: import ogr, gdal from gdalconst import * os.chdir('/home/digd/Desktop/puntos') driver = ogr.GetDriverByName('ESRI Shapefile') shp = ...


2

I think your best bet will be to create a custom button that saves your map document - mxd.save() - as well as whatever operations you wish.


0

Have you thought Euclidean distance?? If you have a file with the hospital you can calculate the euclidean distance. This will give you all the distances from the point(hospital) and you can define your "zone" for telemedicine (according to your parameters).


0

Generally, you can use the network analyst extension and use the centroid of the town as the origin from the hospital then use the time or distance for your result. The one with the highest value or time would be your answer, I presume. You could also set an assumed threshold for access to a hospital, say 3km, create a buffer of the town centroids and ...


0

Try the following: def updateParameters(self, parameters): if parameters[0].value: parmeters[0].filter.list = [v.name for v in arcpy.da.ListVersions(r"\\inpyosegis05\DatabaseConnectionFiles\DataStewardsOnly\YOSEGIS_VectorYOSE_DS.sde") if v.name not in ["dbo.DEFAULT", "DS.Draft"]] return


2

You're mixing returning values from a function and assignment. You have to return the modified value, not assign it to the old variable. The correct format for the pre-logic script code would be: def mycalc(ADM2_NAME, Projects): if ADM2_NAME == "Bo": return (Projects + 1) else return Projects Although there is an even better (shorter) way of ...


-2

You are try to change the value of the input field (Projects) in line 3: return Projects += 1 change it to: return Projects+1 Furthermore change not all of your code paths return a value. change like this: else: return Projects


2

The script uses a somewhat crude method to guess which point within each polygon is furthest from any of the other points also in that polygon. For each polygon, it calculates the distance between all possible pairs of points, then finds the 5 longest distances and finds the point that was the most common in those 5 pairs. It writes these "far points" to a ...


2

Why do you think is incorrect? Supose you have this point and line: ls = LineString([(0,0),(1,1),(2,0),(3,1)]) p = Point(2,-0.2) By using ls.project(p) you'll get de distance from the beginning of the line to the nearest point. 2.828 meters, the distance of this part: I think this is what you are asking. A second option is to include, to the ...


-2

Since most answers are basically just a 'this is my favorite editor', I'll add this link to a poll on GeoNet. Out of 130 votes so far, the results are: PyScripter 51 votes PyCharm 17 Wing 10 PTVS 8 Komodo 5 NetBeans 1 PyStudio 1 Spyder 1 KDevelop 0 (Other 36) Here's the poll.


0

First use this script to print all of your layer DataSources : mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd, "*"): print lyr.dataSource Then use this code: def FindLabel([OBJECTID]): mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd, "*"): if not ...


1

A simple test shows that None should work. See Mr. Che's answer to see what else was wrong. with arcpy.da.InsertCursor(mytable, ["date"]) as cursor: cursor.insertRow([None])


2

I use PyCharm for a period and and it works great for me.


2

Nathan W is correct. But, if you still want to display a QMessageBox with autoclose behaviour. You can do it bu subclassing the QMessageBox like this: class CustomMessageBox(QMessageBox): def __init__(self, *__args): QMessageBox.__init__(self) self.timeout = 0 self.autoclose = False self.currentTime = 0 def showEvent(self, QShowEvent): ...


4

Don't use a message box for this. It is not what they are for and will make people cry. Use the message bar. iface.messageBar().pushWarning("title", "message") or iface.messageBar().pushMessage("title", "message") http://qgis.org/api/classQgsMessageBar.html


1

If you have set, mxdPath = "\\server1\d$\arcgisserver\directories\arcgissystem\arcgisinput\Unknown_Unknown\poly_test.MapServer\extracted\v101\POLY_TEST.mxd" Then you should put r before paths in python or escape BackSlashes with another backslash. option 1: mxdPath = ...


4

Without seeing your error message it is hard to be certain, and I prefer to use arcpy.CreateFolder_management() in place of os.makedirs, but try changing: os.makedirs(os.path.join(PF,row.FID)) to os.makedirs(os.path.join(PF,str(row.FID)))


3

First, I Suggest you to use SearchCursor from data access modulde for better performance. rows = arcpy.da.SearchCursor(featureclass) The problem with you code is that you are joining string with int (FID). just convert it to string. os.makedirs(os.path.join(PF,str(row.FID)))


1

You have to calculate these two values. Georeferency is a tuple with 6 numbers: X coordinate of origin (upper left corner), horizontal resolution, rotation of X axis, Y coordinate, vertical resolution, rotation of Y axis. You can use this pattern to calculate indexes: COL = (X - OX) / RX ROW = (Y - OY) / RY X, Y are coordinates of pixel OX, OY are ...


5

You are missing date2 in dictIN: Change it: dictIN= [{'field1':"test1",'date1':'01-02-2015','date2':''},\ {'field1':"test2",'date1':'01-02-2015','date2':'01-02-2015'},\ {'field1':"test3",'date1':'','date2':''},\ {'field1':"test4",'date1':'01-02-2015','date2':''}] Full code is: dictIN= [{'field1':"test1",'date1':'01-02-2015','date2':''},\ ...


0

If the cursor on your input_table ever returns no records from the query then I think it will either error or lead to numbers_facilities not being set. Perhaps use Get Count to test whether the query will return no records before opening a cursor using it.


1

First, let it be known there are a number of ways someone could go about accomplishing roughly the same goal in this case. For me personally, especially for someone less experienced with arcpy, it would likely be simplest to do roughly the following workflow Convert the CSV file to Table in GDB Join the Table to Point Feature Class Make Feature Layer ...


1

This situation is always confusing. There are two types of 'Layers' in arcpy. The feature layer, which you are creating, isn't the type you can add to a map. The other is the layer generated from the mapping module. This is the one you want. Instead of MakeFeatureLayer, try this: NewLayer = arcpy.mapping.Layer(r"W:\Source.lyr") Then you can perform ...


2

The tool works well. I modified slightly the code for producing only 3 raster (10, 20 and 30 Pixel Size) with a point shapefile with 5 features. import processing RasterPixelSize = (10.0,20.0,30.0) i=1 for rps in RasterPixelSize: processing.runalg("gdalogr:rasterize",\ "/home/zeito/pyqgis_data/point.shp",\ "id",None,1,rps,rps,6, ...


1

You should check, longName property of the layer to see whether it has backslashes or not: Here is the snippet: import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.isGroupLayer == True: if lyr.longName.find('\\') == -1: print lyr.longName I hope it helps


2

I got your model running using a shape file instead of a spatialite db. Can you try a shape file first, to see if it's work. Then perhaps it would be easier, to identify any Spatialite problems. I also added my model code, so you can check against your model. I got another Python error than you using Spatialite: Algorithm testModel starting... Prepare ...


1

Having trouble adding a comment from my phone, so posting here... I would recommend that you become familiar with JSON, if not already. I would develop your service to return a JSON object that contains key/value pairs that hold the results of your calculation. That JSON object can be easily parsed in your javascript, placed into existing html or used to ...


4

This is the precise use case for a geoprocessing service. Write your script and add it to a geoprocessing toolbox on the server as a script tool. You can test it on the server while developing the script by hard coding the parameters. Once you're comfortable with your code, replace those hard coded parameters with arcpy.GetParameterAsText(), add to a ...


1

You can overwrite the close function of your UI as well, that the plugin is reloaded every time you close it. def closeEvent(self, event): qgis.utils.reloadPlugin('YourPluginName') This will reload the plugin completely and will empty all your boxes. In this way you don't have to care about clearing the boxes because the plugin will always load only ...


1

Both underdark‚ô¶'s and gcarrillo's replies provide valid answers. How exactly the issue should be handled however depends on the use case, and if necessary, options should be provided.


0

Thanks for your answer. I figured out what the issue was. If I use the script within my pre-code block, I need to define the variable %name%. This is what I wrote in my pre-code block script: def my_funcrtion(): import arcpy my_name = "%name%" fc = "C:/" + my_name + "/Dropbox/featureclass"


0

Thanks for your input and ideas. I have solved it by giving the same field name ("SJ_count") in my input feature classes X1, X2, X3. After the join I altered the field name using the in-line variable substution string (count_name) given with the iterator as my addition. So my new field name became "SJ_count_%count_field%). An example of a field name woud ...


2

You are probably setting a connection between a SIGNAL (button clicked) and a SLOT (your method showTable) every time your plugin is open (run() method?) and you are not disconnecting such SIGNAL/SLOT when your plugin is closed. This leads to a new call to showTable() every time you open your plugin, because there's a new connection calling it. A couple of ...


2

I didn't find the option from the API, but you could mimic such behavior this way: I assume there are selected features already, so get their Ids: lyr = iface.activeLayer() selIds = lyr.selectedFeaturesIds() You said you have an expression, let's say: expr = QgsExpression( "\"NMG\" = 'CALI'" ) Now, get feature Ids that match your expression: it = ...


1

In my opinion you should empty the combo box before populating it. The rationale behind that is that the layer might have changed so it's not a good idea to set a flag and ignore everything that might happen afterwards.


1

I suggest you to write a proxy class in managed C++ if this is an option for your. Realistically, you might need to perform the kind of operation that takes longer in .NET or Arcpy(large iterations of small operations).You have the choice to write a proxy class in Managed C++ where you can place ArcObjects code that heavily uses the interop layer. Once ...


0

Add this to PATH variable (replace "C:\Program Files\QGIS Valmiera" with QGIS install location): C:\Program Files\QGIS Valmiera\bin;C:\Program Files\QGIS Valmiera\apps\qgis\bin and this to PYTHONPATH variable: C:\Program Files\QGIS Valmiera\apps\qgis\python; C:\Program Files\QGIS Valmiera\apps\qgis\python\plugins; C:\Program Files\QGIS ...


0

I figured this out on my own after testing some rearranging of import statements. In my case, rasterio needed to be imported after shapely. For example: import shapely import rasterio


3

You are missing a very little detail: the fact that in Python you can pull elements from a list starting at the back. The last element of a list corresponds to index -1. For example: location = "Cedar Wood Park" locationChoppped = location.split(" ") print locationChoppped[-1] would return: Park, and: location = "Highland Grove Hyper Megalopolis" ...


1

I've used filled elevation model (with streams removed) to replicate your coefficients: Keeping in mind that water usually runs downhill :), it is reasonable to expect that all the values in output should be less or equal to the value at start point. I've checked results using difference [Filled]-[ScriptOutput] and found that script (see below) failed ...



Top 50 recent answers are included