New answers tagged

0

Good question just figure this out 2 days ago. Go take those installed libraries and copy them into your C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy folder or where ever your arcpy downloads are But are they installed already? if you import them just using python do they work?


1

Try using arcpy to back up your geodatabases. Example: workspace = r"workspace\file\path" arcpy.env.workspace = workspace print "Set Workspace" backup_location = r"new\folder\path" + "\\" + "workspace.gdb" print "Backing up workspace" arcpy.Copy_management(workspace, backup_location) print "Clearing Workspace cache" arcpy.env.workspace = "" ...


0

I couldn't get it to work in time for my deadline so ended up converting the .shp file to topojson and adding the features directly to the json (the final output I needed was topojson for d3 anyway...) see below: import json import csv from collections import OrderedDict import io # read proeprties to be added to topojson csvdata = ...


0

As far as I know, the Fiona package in the default Anaconda channel is broken. Is that the one you're using? If so, can you try the "conda-forge" channel instead?


1

Fiona works with Python dictionaries (schema, features) and and more specifically Ordered Dictionaries shape = fiona.open("a_shapefile.shp") # schema of the shapefile shape.schema {'geometry': 'Point', 'properties': OrderedDict([(u'id', 'str:10')])} # keys of the dictionary shape.schema.keys() ['geometry', 'properties'] # first feature of the shapefile elem ...


1

Assuming there is a common field between them all: Merge all the feature classes together into one feature class Dissolve the feature class based on the identifier field. This will result in a multi-point feature class with each entry comprised of multiple locations Run feature to point to collapse the multipoint to point


1

The download for the 64 bit geoprocessing installation is not freely available. I found it in my.esri.com under My Organizations -> Downloads -> ArcGIS for Desktop 10.4 -> ArcGIS for Desktop Background Geoprocessing (64-bit).


0

I'm guessing the CSW you are querying has 'http://localhost:8080' set as it's host in the CSW configuration. OWSLib's CSW support does a GetCapabilities request by default to get this information. You can use the skip_caps=True parameter to bypass this: csw = CatalogueServiceWeb(geonetwork, skip_caps=True) which means OWSLib will always use the URL you ...


0

Since you already know what will be your new path, you could simply define it yourself... import os ... result = arcpy.CreateFeatureclass_management(env, fc, arcpy.GetParameterAsText(3),"","","",arcpy.GetParameterAsText(4)) if result.status == 4: newpath = os.path.join(env,fc) arcpy.AddField_management(newpath, "Company", "TEXT") ...


0

Solution: # local variables root_dir = r"path\to\dir" #inside dir a gdb with a FC gdb = os.path.join(root_dir, "gdb2shp.gdb") feature_class = os.path.join(gdb, "FC") # Get list of distinct UTM values utm_field = "UTM_grid" #FC attribute sql_prefix = "DISTINCT {}".format(utm_field) sql_suffix = None distinct_utm = [ i[0] for i in ...


1

I think the following parameters requires a minimum value of 1: JPEGCOMPRESSION ZLEVEL PREDICTOR The others can be set to 0 so you could try running the following which works for me: processing.runalg('gdalogr:cliprasterbymasklayer', inputlayer, maskshape, "", False, False, False, 0, 0, 1, 1, 1, False, 0, False, "", "outputraster")


2

You should replace : myquery = PropertyIsEqualTo('csw:AnyText', 'été') with: myquery = PropertyIsEqualTo('csw:AnyText', u'été') The prefix indicates a unicode string : 3.1.3. Unicode Strings


0

From release 5.4 OTB will distribute standalone binary packages which contain all exe and applications in a self contained archive for LINUX/Windows/Mac. 5.4 is not released yet (targeted for May) but you can already try it (nightly package are available on a daily basis). 32 bits system: ...


1

I think the confusion lies with the OUTPUT parameter where the algorithm does not require this as you're only selecting attributes from the same layer. Remove this from your algorithm (this should also be removed from the documentation in my opinion). So your algorithm should look like: ...


1

Actually ignore this - I misinterpreted the question.


0

You can try to search on this link. It gives some explanation on how to convert gpx to shp, but in arcmap. And you can try on this link, to search for method to do it in qgis.


0

To sum up, this code works, as Michael helped: >>> arcpy.env.overwriteOutput = True fdList = ["Dataset_A", "Dataset_B", "Dataset_C"] folList = ["D:\\GIS_Temp\Folder A", "D:\\GIS_Temp\\Folder B", "D:\\GIS_Temp\\Folder C"] workRange = range(len(fdList)) for thisIndex in workRange: fd = fdList[thisIndex] arcpy.env.workspace = ...


3

What is strange if the intersection result is a point ? The intersect predicate is Returns True if the boundary and interior of the object intersect in any way with those of the other. With a common point between the geometries, the intersects predicate returns TRUE because the boundary of the first geometry intersects the boundary of the second ...


2

I have done a similar stuff, mine does work. Check it out. It is for 2.14 qgis. If you are locked you should probably check http://docs.qgis.org/2.2/en/docs/pyqgis_developer_cookbook/raster.html (see the version number on the link) from PyQt4.QtCore import QSize from PyQt4.QtGui import QPainter, QImage, QColor from PyQt4.QtCore import QFileInfo from ...


0

The old-school version of the update cursor will do what you want pretty easily. I'm guessing you're working in ArcGIS? If so, here's what you do. Open ArcMap, add your city layer into your mxd, and create a field for the sort order, if it doesn't already exist. (And maybe start an edit session in case something goes wrong and you want to undo it.) You'll ...


5

you can get a list of the drivers with >>> import fiona >>> fiona.supported_drivers {'ESRI Shapefile': 'raw', 'ARCGEN': 'r', 'PCIDSK': 'r', 'SUA': 'r', 'DGN': 'raw', 'SEGY': 'r', 'MapInfo File': 'raw', 'GeoJSON': 'rw', 'PDS': 'r', 'FileGDB': 'raw', 'GPX': 'raw', 'DXF': 'raw', 'GMT': 'raw', 'Idrisi': 'r', 'GPKG': 'rw', 'OpenFileGDB': ...


1

import os from PyQt4 import QtGui, uic from PyQt4.QtCore import pyqtSignal FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path.dirname(__file__), 'my_dockwidget_base.ui')) class myDockWidget(QtGui.QDockWidget, FORM_CLASS): closingPlugin = pyqtSignal() def __init__(self, parent=None): """Constructor.""" super(myDockWidget, ...


1

Not a proper answer but does not fit into the comment box. However, at least PostGIS does return a point for two polygons which touch at one point. SELECT ST_AsText( ST_Intersection(ST_GeomFromText( 'POLYGON (( 140 360, 140 480, 220 480, 220 360, 140 360 ))'), ST_GeomFromText( 'POLYGON (( 220 260, 220 360, 300 360, 300 260, 220 260 ))'))); ...


2

This comes down to efficient chaining of boolean operations. Each comparison (tifArray > threshold) yields a temporary boolean array with the same dimensions as tifArray, which also consumes memory (since bool is stored as int8 it needs half the memory of a uint16 array). An array of type uint16 and size=(55500, 55500) takes up ~6 Gb of memory. So on a ...


1

This could work, based on answer Michael wrote, but there are still some problems: >>> fdList = ["Datase_A", "Dataset_B", "Dataset_C"] folList = ["D:\\GIS_Temp\Folder A", "D:\\GIS_Temp\\Folder B", "D:\\GIS_Temp\\Folder C"] workRange = range(len(fdList)) for thisIndex in workRange: fd = fdList[thisIndex] arcpy.env.workspace = ...


1

I suspect that your script is failing because the output already exists, to avoid this set overwrite to True, which is easier than check and delete, but may not be what you need in the long run. Putting together your scraps into a contiguous codeblock: # set overwrite = True so it won't crash if # the output already exists arcpy.env.overwriteOutput = True ...


2

I got it to work on my GNU/Linux machine by replacing this code block from your script: QgsApplication.setPrefixPath('/usr', True) QgsApplication.initQgis() by this one: qgisApp = QgsApplication([], True) QgsApplication.setPrefixPath('/usr', True) QgsApplication.initQgis() The first line of this code block initializes the QgsApplication class, making ...


3

Some vector formats are read-only in QGIS. So, first check if your Cropped layer is read-only: Cropped.isReadOnly() If not, then you could use this code snippet to delete all features whose Name attribute value is already in the roads list (note the handy function to delete all those features in a single step): features = Cropped.getFeatures() ids = [ ...


2

--- gdal --- use gdal_contour function. documentation here ---- ArcGIS version----- posted before the software was specified Assuming you are using ArcGIS: 1. Convert the GeoTiff into ESRI GRID (esri raster format) using raster to other formats function, or simply import it in arcGIS and use save (export data) and save it as ESRI GRID. 2. use the Contour ...


0

Guess the answer was simpler than I thought. Had to insert everything into the run(self) function. So the following code works: def run(self): def test_print(): print 'It works!' self.dockwidget.pushButton.clicked.connect(test_print)


2

The best way depends on too many things that you have not mentioned. Is this to only be done once or every time you update the FC/table? Does the sort have to be reflected by the ObjectID or is the sort good enough if it just happens in memory and is reflected in the numbering order of separate column only? Anyway, the Sort tool is the easiest way to ...


0

You could try something like this: import os import arcpy arcpy.env.overwriteOutput = 1 output_folder = r"full_path_to_folder" fc = r"full_path_to_feature_class" fields = ["OID@","SHAPE@","UTM_GRID"] #modify as required template_fc = r"full_path_to_template_schema" #with fields you want to keep - they should also be in the field list above fc_data = ...


1

Use the spatial join tool under the Analysis Tool - Overlay in ArcToolbox.


2

When you use QgsZonalStatistics, the results are are automatically added to the shapefile (look at Problem with calculating QGIS Zonal Statistics MEAN or Estadística zonal con PyQGIS: clase QgsZonalStatistics) vLayer = QgsVectorLayer("a_polygon.shp","a_polygon.shp","ogr") path = "test.tif" zoneStat = QgsZonalStatistics(vLayer, path,"", 1, ...


1

Are the feature classes in different directories? That is, your files are like: r"C:\Mydirectory\Name1.shp" r"C:\Mydirectory\Name2.shp" r"C:\Anotherdirectory\Shapefile_To_Intersect.shp" Instead of relying on workspaces, include the path with the name in your list. Then perform the intersect on that list. This intersects all of the layers together. ...


0

Apparently adding print(joinObject.memoryCache) ensures that all layers are cached. Not sure why but this seems to only work if you print the bool state of QgsVectorJoinInfo::memoryCache, otherwise only some layers are cached. Weird. Here is the code: shp = QgsMapLayerRegistry.instance().mapLayersByName( "Main" )[0] shpField = 'ID' root = ...


1

Use the arcpy.MakeFeatureLayer_management(r"C:\Anotherdirectory\Shapefile_to_Intersect.shp", "lyr_to_Intersect") arcpy.Intersect_analysis([files, "lyr_to_Intersect"], os.path.join(out,files)) as input for your Intersect_analysis. Intersect_analysis only accepts layers or classes not shp files.


1

Thats what you need to add: import sys # where is the module sys.path.append("/Applications/QGIS.app/Contents/Resources/python/") sys.path.append('/Applications/QGIS.app/Contents/Resources/python/plugins') qpp = QgsApplication([], True) QgsApplication.setPrefixPath(r"/Applications/QGIS.app/Contents/PlugIns", True) QgsApplication.initQgis()


1

Actually it works, just need to wait few minutes after code exercise.


2

The next code only select the number 3 band (blue band) in a RGB raster and write it as blueband.tif. from osgeo import gdal, osr import os, struct import numpy as np layer = iface.activeLayer() provider = layer.dataProvider() path = provider.dataSourceUri() fmttypes = {'Byte':'B', 'UInt16':'H', 'Int16':'h', 'UInt32':'I', 'Int32':'i', 'Float32':'f', ...


4

Try to update your script and use ST_AsGeoJSON(). You can also choose the number of digits with this function. http://postgis.net/docs/ST_AsGeoJSON.html


4

To geocode an address, you need to have a geocoding locator. Your options are: buying Esri StreetMap Premium geocoding locators from Esri (ready to use in ArcGIS); buying TomTom MultiNet / HERE PointAddressing and building your own geocoding locator (will need to learn quite a lot before being to build); getting ArcGIS Online organization subscription ...


3

You don't need Gdal/Python here. It is easier to use Shapely 1) Transform the list of points to a shapely geometry list = [(0.0, 0.0), (0.0, 1.0), (0.0, 2.0), (0.0, 3.0), (0.0, 4.0), (0.0, 5.0), (0.0, 6.0), (0.0, 7.0), (0.0, 8.0), (0.0, 9.0), (1.0, 0.0), (1.0, 1.0), (1.0, 2.0), (1.0, 3.0), (1.0, 4.0), (1.0, 5.0), (1.0, 6.0), (1.0, 7.0), (1.0, 8.0), (1.0, ...


0

According to my opinion you are mixing something up. If you are writing some code to use inside a running ArcMap process you have to work with the IMxDocument. In a standalone application without ArcMap only using arcobjects you have to work with the IMapDocument to access an MXD. Using both at once does not work correctly. If you like to access the style ...


1

For your first question, I believe this previous asked question will help you: Why does this simple Python OGR code create an empty polygon? Here is a python GDAL cookbook (a few years old, but still applicable) GDAL/OGR python Cookbook: https://pcjericks.github.io/py-gdalogr-cookbook/ For your second question, I believe that you want to set a spatial ...


4

The native shapely function is unary_union (Planar graph) The circles 1) Using the script of How to find the intersection areas of overlapping buffer zones in single shapefile? rings = [LineString(pol.exterior.coords) for pol in circles] union = unary_union(rings) result = [geom for geom in polygonize(union)] Result: you have all the intersections ...


1

The Shapely distributions I am making for OS X (https://pypi.python.org/pypi/Shapely#downloads) have GEOS included and you won't have to think about library paths at all. If you're using Python 2.7, 3.4, or 3.5 and OS X 10.6+, pip install shapely is the best way to get it.


3

There is a handy option in the QgsLayerTreeGroup class that you can use: findGroup. It traverses the whole tree. So, in your case, this would be enough: root = QgsProject.instance().layerTreeRoot() subGroup1A = root.findGroup('Sub_Group_1A') for child in subGroup1A.children(): if isinstance(child, QgsLayerTreeLayer): child.layerName()


1

Eugh, I guess one method is to: Search the children of Main_group, then Search the children of Sub_Group_1 and then Search the children of Sub_Group_1A. Basically repeating the loops, I'm hoping there is a much nicer and efficient way of accessing those layers but for now, here's the code I used: root = QgsProject.instance().layerTreeRoot() for child ...


6

I believe the answer by @iant is the best method to use (when you get it working, you should accept his answer). Just want to add that you can use the following expressions in your filter for your 3 individual rules (you can add rules by clicking the + as shown in the image, set the expression filter and the svg symbol): "myfield" < 1300 "myfield" > ...



Top 50 recent answers are included