Tag Info

Hot answers tagged

6

Here's a go at it. Use Python as the parser and check show Codeblock. Enter this in the top Pre-Logic Script Code box: def getints(field): integers = [] for char in field: try: value = int(char) integers.append(str(value)) except ValueError: break return "".join(integers) And put ...


4

Apparently RefName never equals your comparison strings. All constant strings includes German characters ä or ü, but you don't use the "u" constant string prefix. Depending on the incoming string's format the comparison might not be what you expekt. You should write if RefName==u"Flächen für die Landwirdshaft" and make sure that RefName also is a correct ...


4

I am not sure if the following will not do the same thing as dissolve, but if I'm correct, it should not. You can use a SearchCursor() to loop through the polygons, get each polygon's geometry, add these as parts on a new polygon geometry object, and use an InsertCursor() to insert this new record. sc = arcpy.SearchCursor("c:/temp/fishnet2.shp") ic = ...


4

Put a u in front of the string so the interpreter knows it's Unicode. myCalc(!Epulettipus!, u"Lakóépület")


3

Here is a field calculator method that incorporates itertools.takewhile. While ian's solution writes the new values to a text field, this is suited for writing to a numeric field. import itertools def convert(x): try: return int("".join(itertools.takewhile(str.isdigit, str(x)))) except: pass convert(!OriginalString!)


3

You don't 'Dim' variables in python, you just declare and assign them. That said, your basic route is to set the parser to python and check Show Codeblock. In the Pre-Logic Script Code box, enter your function like this: def DoThis(fld): val = 0 if fld <> 'a certain string': val = # do your calculation here return val In your ...


3

I just found a solution. There is also an active psycop2 connection. When I commit it or close the connection before osm2pgsql runs and open it afterwards again it works. Probably osm2pgsql can't access to the database if this connection is open.


3

Based on your variable, you just need to make sure variables and strings are not confused field_1="!field_name1!" field_2="!field_name2!" arcpy.CalculateField_management("Layer", field_0, field_1 + " / " + field_2, "PYTHON_9.3") note that if you have the strings as variables without the "!", it is nicer to use format() field_1="field_name1" ...


2

You are missing the wrapping exclamation marks, try this: arcpy.CalculateField_management("Layer", field_0, '!' + field_1 + '!/!' + field_2 + '!', "PYTHON_9.3")


2

You have embedded the string variable within a string so python sees it as a string. I would suggest you make you code something like: field_0="field_name0" calcString = "!field_name1! / !field_name2!" arcpy.CalculateField_management("Layer", field_0, calcString', "PYTHON_9.3")


2

Your code is wrong. Do this: from osgeo import gdal GDAL is a module of the osgeo package. You don't ever import osgeo itself. In Python a package is a convenient collection of modules and provides a 'name-space' for that collection. So, you can drill down further and import specific functions or variables from a module within a package like this: ...


1

Adding a toolbar: # Create toolbar self.toolbar = self.iface.addToolBar("My Toolbar") self.toolbar.setObjectName("My toolbar Plugin") self.toolbar.addAction(self.action) self.btn = QAction(QIcon(":/plugins/import_PostGIS/icon.png"), "button1", self.iface.mainWindow()) QObject.connect(self.btn, SIGNAL("triggered()"), self.method) ...


1

While I'm a big user of both shapely and fiona, I wouldn't go this approach. This is a task of writing an effective SQL statement. Using ogr2ogr with an SQLITE dialect, you can process this from a command line. Change directory to one before the shapefiles, so that all of the shapefiles are in one directory called data. OGR treats directories of shapefiles ...


1

Some issues in your code: you only use correctly one table as input whereas, you should use both input bufSHP and ctSHP you want to make an intersection between a list of shape and a filename with shapes.intersection(ctSHP) whereas you have to do an intersection between two shape elements See below a possibility, I choose to use Rtree to optimize, ...


1

This is straightforward with ogr2ogr. You may need some tricks to get OGR to understand the structure of your file, see the CSV driver if you have difficulties. ogr2ogr -spat xmin ymin xmax ymax clipped.csv input.csv You can also use a shapefile dataset to clip using -clipsrc in combination with -clipsrcsql, -clipsrclayer, and/or -clipsrcwhere options.


1

What shape is your polygon shapefile? Ie. is it a rectangle or is it convoluted. If it is the former, you just have to determine whether the XYZ values of your points is within the boundary defined by a rectangle (there will be max and min Easting and Northing values), but if it is the latter, I suspect that you can't do what you are asking without first ...


1

The 770.osc.gz file lives in the same directory as osmconvert.exe and the output extract.05m should populate in the same directory as the osmconvert.exe exists. That's not what your code is saying. The code says "execute osmconvert.exe from inside c:\temp\ but read 770.osc.gz and write extract.o5m from the current working directory". If you want ...


1

Shapefile fields are constrained to 10 chars, and so your 'a_fieldname' gets truncated by OGR (used by Fiona) to 'a_fieldname'. There might be a Fiona bug here. Workaround in the meanwhile is to change 'a_fieldname' in your schema to 'number' or something shorter than 10.


1

If you have already created the layers in QGIS and you want to publish them using the same style, I think you should go with QGIS Web Client. Related to the new points, everytime the user load the WebGIS application, a new request will be made to the database and so the information will be always updated.


1

What you're asking for isn't possible. ArcGIS server supervises the Python process and kills it if it takes too long. It doesn't send an interrupt/break to the Python session so the Python interpreter would never get to that finally block. I know you said it's out of your control, but you may want to beg the administrators of your server to let you tick up ...


1

I may have found why the call to SAGA:MERGESHAPESLAYERS is not working in ubuntu from QGis Regardless of my 2.0.8 syntax setting QGis generates the following line of shell script shapes_tools "Merge Shapes Layers" -MAIN "/tmp/vlayer_01.shp" -LAYERS "/tmp/vlayer_01.shp;/tmp/vlayer_02.shp" -OUT "/tmp/output.shp" When run it generates the following error: ...


1

The problem with your solution is that source_srs is not a valid osr.SpatialReference(). If the result of source_epsg is 4269 then: source_srs = osr.SpatialReference() source_srs.ImportFromEPSG(4269) gives a valid osr.SpatialReference() NEW If I understand correctly your question, you want to use Leaflet, and Leaflet expects coordinates and GeoJSON ...


1

there is a flipline tool, though it doesn't seem to allow queries on a feature. it may be that you can provide the tool with a feature layer based on the selected attributes. EDIT: As @JasonT mentioned, the flip tool should honor selections, so perhaps use make feature layer with a SQL clause on the features that should be flipped and pass that layer to ...


1

I'm not sure why, it must be some memory issue, but you need to use the full file path to the feature class you are creating the feature layer on. So for fcStops, put the full file path, not just the layer name from ArcMap. I tested it on my machine, and it failed with the same error when I used the layer in the TOC, but worked fine when I used the full ...


1

Then I put every record in the rows of a pandas.DataFrame Why ? If you only want to copy the original attributes (LineString) to the new shapefile (Points), after computing the centroid, you don't need Pandas: import fiona from shapely.geometry import shape, mapping with fiona.open("polyline.shp") as input: # change only the geometry of the ...


1

For those who want to do this in 10.2, this modification of above worked for me: # Import system modules import sys import string import os import arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create(10.2) # Load required toolboxes... gp.AddToolbox("C:/Program Files (x86)/arcgis/Desktop10.2/ArcToolbox/Toolboxes/Data Management ...


1

I realize this question was closed long ago, but I have some old tools that this was newly a problem for and the SendKeys solution no longer seems to work, so I rolled my own solution after experimenting. It doesn't disable drawing, but creates the performance equivalent of that by disabling layers and reenabling them when done. Having the script run in the ...



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