Tag Info

New answers tagged

0

The following code uses the approach of calling a subprocess and piping the text to the clipboard. A couple of things to note: I use the onMouseUpMap event, this returns the XY coordinates in map units. I placed a comma between the numbers so there is no space between them. Wrapped the code up in a try-except to capture any failures. import arcpy import ...


2

After following a subset of this advice, this is how I got the Python GDAL 1.11.0 install to work on Ubuntu 14.04 with pip: Install dependencies: sudo apt-get install libgdal-dev libgdal1h Pip install and pass along the include path: sudo pip install --global-option=build_ext --global-option="-I/usr/include/gdal" gdal


1

You cannot only unzip the folder, you must install the module with python setup.py installbut osgeo is a Python wrapper of the GDAL C++ library. Therefore you need to install first the GDAL library and then install the Python module witch uses the GDAL libraries Dependencies: * libgdal (1.11.0 or greater) and header files (gdal-devel) You can compile ...


1

1) With Fiona, you don't need shapely to count the number of points in a polygon/multipolygon. Simply use the resulting GeoJSON format (= a Python dictionary). Polygon simple: jmport fiona shape = fiona.open("simplePoly.shp") # first feature feature = shape.next() geom = feature['geometry'] print geom {'type': 'Polygon', 'coordinates': [[(1.0, 1.0), (1.0, ...


1

You should just install the 32 bit version of Anaconda.


1

You're using a 64 bit version of Python in your Anaconda installation and ArcMap's Python is 32 bit. You'll need to install some 64 bit ArcGIS build (either 64 bit Background Geoprocessing or ArcGIS for Server) and point to that instead, or install a 32 bit Anaconda instance instead and try again. See the downloads page and get the 32 bit installer.


2

Apologies if I misunderstood your question but perhaps you could create a new attribute column and calculate the length of each feature from there using: $length Hopefully others will help if I am indeed mistaken.


0

php Array with 3 letter ISO country codes $Countries=array(); array_push($Countries,"ABW"); array_push($Countries,"AFG"); array_push($Countries,"AGO"); array_push($Countries,"AIA"); array_push($Countries,"ALA"); array_push($Countries,"ALB"); array_push($Countries,"AND"); array_push($Countries,"ARE"); array_push($Countries,"ARG"); ...


0

Did you try Envoy library, a wrapper on top of Python subprocess? It could help skip the issue. To launch commands 1 and 2 import envoy cmd1 = ['gdalwarp', '-t_srs','+proj=longlat +ellps=WGS84','*.tif','new7.tif'] cmd2 = ['gdalwarp', '-t_srs','+proj=longlat +ellps=WGS84','newfolder/band4.tif','newfolder/band4_r.tif'] r1 = envoy.run(' '.join(cmd1)) r2 = ...


0

I have done this using urllib2 in python. Some simple code is import urllib2 request_file = open("my_wps_request.xml", "r") xml_data = request_file.read() r = urllib2.Request( "http://192.168.109.147:8080/geoserver/wps", data=xml_data, headers={ 'Content-Type': 'application/xml', 'Accept' : 'image/tiff' }) u = ...


2

You can get polygon exterior and interior points coordinates this way: def extract_poly_coords(geom): if geom.type == 'Polygon': exterior_coords = geom.exterior.coords[:] interior_coords = [] for int in geom.interiors: interior_coords += i.coords[:] elif geom.type == 'MultiPolygon': ...


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) ...


2

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 ...


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

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: ...


3

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 ...


2

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.


0

No, You can't clip it unless you make the XYZ text file spatial. It is the nature of clipping. You could write a query that determines the Extent of the square and then exclude any points that have values outside it, but that is more work than just clipping. What GIS software package have you got?


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 ...


4

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


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 ...


-2

I'm a long time ArcGIS user but find that the QGIS field calculator is a lot more intuitive & provides options for dragging & dropping fieldnames, expressions & operators. If you are a programmer, then you'll probably find it a lot easier and you'll find it builds your knowledge for using the expression builder in ArcGIS.


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.


0

I haven't really used model builder too much (usually just hack my way through a model to run some script I made), because I usually use ArcPy for stuff. But maybe I could help you go in the right direction. I would suggest to use the Add Field tool from toolbox datamanagement->Fields->Addfield. then hook the output of that up to calculate field from the ...


0

If you want the coordinates (longitud, latitud) in a single list, use the function zip() longitud= [-2.7692601473009155, -2.7362662697828974, -2.3913741501505776, -2.424387612708171, -2.7692601473009155] latitud= [43.82769682706945, 43.66046724635432, 43.69596983959721, 43.86319942031234, 43.82769682706945] coord = zip(longitud, latitud) print coord ...


0

your problem is a combination of two problems 1) write the name of the fc into a field Use Feature Class "Name" from Iterate Feature Classes to Calculate Field with Model Builder 10.1 then 2) extract a small part. For the second, just use the field calculator with the python parser !Image![2:6]


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.


0

"FATAL ERROR: packing type 40 not supported" wgrib2 was compiled without support for jpeg2000 compression (packing 40). You tried reading a grib record that was compressed with jpeg2000.


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 ...


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")


0

I picked up this book about a year and a half ago (Python Scripting for ArcGIS) and found it to be very good as it is geared toward ArcGIS. I had picked up some other Python books from the library and found them hard to relate back to GIS. I do not have a programming background, but this book was quite helpful in going over the basics as well as info ...


0

The easiest way to do this is by importing the path where gdal_merge.py is located, in my case, /usr/bin/ -- substitute with the path to gdal_merge on your system, which, obviously, could be a Windows path too. import sys sys.path.append('/usr/bin/') import gdal_merge as gm You will now have to build up an array for sys.argv, as if you were calling ...


-1

Can you use Spatial Join to stamp the IDs into the polygons?


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 ...


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 ...


0

This excellent Example using the WGrib Utility will show you how to do it. ( See the first answer ). It also gives information on how to use GDal to convert to a Tiff format as well.


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

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 ...


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 = ...


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.


0

I would suggest Grass GIS. The v.net package is a pretty powerful tool. Grass can be a bit tricky to get going on but with a tutorial or two you should be OK. You will also need to interpret the matrix result that will be ~200 by ~200 with the distances. Export to excel, import with Python, etc. and do what needs doing with it. ...


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!)


0

QgsSpatialIndex only knows about the bounding boxes. You will need to get the actual geometries to find the real nearest neighbour. I have done it like this in the NNJoin plugin: # Find a nearest index entry to myPoint (QgsPoint) nearestindexid = self.spIndex.nearestNeighbor(myPoint, 1)[0] # Get the feature in the layer (self.myvectorlayer) that is # being ...


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 ...


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 ...



Top 50 recent answers are included