Tag Info

New answers tagged

0

From the looks of it, you are getting a python error because the headers argument is expecting a dictionary, not a string The following works for me on the entire date range: import requests url = "http://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GHCNDMS&locationid=ZIP:28801&startdate=2000-01-01&enddate=2010-01-01" # replace 'myToken' ...


0

I just used the below code to transfer a shapefile into PostGIS. I saw your post and thought it might help. The Shape@WKT makes it really easy to transfer the geometry. Everything is hard coded and works which I am happy with and will probably revisit at a later date when my coding improves. If anything is not clear please let me know. import psycopg2, ...


0

Here's what I was thinking, and it's based on the way a lot of attribute-heavy government data is official disseminated (like US soil surveys, etc.): --Create a single shapefile with an attribute Name to hold your geometry. --Create series of a-spatial tables, each with different fields but all with the Name field (sorry, not familiar with how to do this ...


0

You have to use a Canvas-Object as first agrument in QObject.connect(). This snippset works for me: def _onRenderComplete(): print("do something") _canvas = qgis.utils.iface.mapCanvas() QObject.connect(_canvas, SIGNAL("renderComplete(QPainter *)"), _onRenderComplete)


1

I think the module your looking for is pyshp. if it isn't installed, open your osgeo shell and enter easy_install pyshp


0

It looks like the ability to create rasters is not yet available in the driver. However, you can create a layer using your standard PostgreSQL Python driver (i.e. psycopg2) and then open it from GDAL. So you'd create a layer using ST_MakeEmptyRaster and ST_AddBand: CREATE TABLE rtest (gid serial primary key, rast raster); INSERT INTO rtest (rast) VALUES ...


2

Raster Calculator is an option but limits what you can do. When using arcpy, you must convert your raster dataset to a raster object to perform map algebra. When defining the parameters in a python toolbox, it may be sufficient to change the data type to GPRasterLayer or GPRasterDataset. Otherwise, just cast the path of the raster to a raster object with ...


3

You could loop through the the Layers panel to check if the layer exists or not by the name before assigning: layers = QgsMapLayerRegistry.instance().mapLayers().values() foundLayer = False for layer in layers: if layer.name() == 'my_layer': inputLayer = QgsMapLayerRegistry.instance().mapLayersByName("my_layer")[0] foundLayer = True if ...


1

You can have multiple layers (or shapefiles) with different attributes. It sounds like from your description that you want to do a JOIN - which is basically connecting a number of layers together by a common attribute. So you could, for example, have a single layer which is joined to a number of other layers by using the name attribute. Then that layer will ...


0

I'm surprised PyQGIS Developer Cookbook is not there yet. I find it indispensable for matching my old GIS skills and my new Python skills, especially without having access to ArcGIS now. If you are more ArcGIS-oriented, then there's much more resources for you. There is a list of Python training programs on StackOverflow. I personally prefer Checkio. ...


2

QGIS has created a function called format_number to address this. You simply do format_number(12345,0) to get 12,345.


1

Your approach is calling either this or that for every single field in the attribute table. That might mess things up. Instead try field_names = [field.name() for field in self.layer.pendingFields()] if 'elevation' in field_names: do this else: do that


1

So I've found out what was it ! I added into the code a column with city names to add as labels on the map. But it only contain a small number of them, and Qgis probably don't like Null values that much... After replacing them with zeros the importation of the .xlsx files went smoothly ;) !


0

If you are to be tackling this with or without COTS, I recommend looking at LAS file format standards, such as Spec Version 1.2. It would help you understand what you have. Your question is too broad to answer adequately in a few paragraphs. If you still wish to take a pythonic approach, I would look into python libraries such as libLas and laspy. I've ...


0

Have you looked into LAS Tools? I use that with all point-cloud data that I use from LiDAR and it seems to be able to do nearly everything that I need. The download for LAS Tools can be found here. Look at the LAS tile tool within the toolbox.


3

Here's some quick-and-dirty Python code that works on a simple shapefile layer: # Get the currently selected layer inLayer = iface.activeLayer() # Get its list of fields inFields = inLayer.dataProvider().fields() # Convert its geometry type enum to a string we can pass to # QgsVectorLayer's constructor inLayerGeometryType = ...


1

The two top answers by @SCW and @Mike Toews are great. The site listed by Mike is for unofficial binaries - which was very useful when 64 bit GDAL was not readily available (as per the time he wrote his reply), but it has been now for some time. I have added this alternative answer here as, although I have mentioned it many times, it still keep cropping up ...


2

I think you are seeing that particular error message from this line of your code: arcpy.KMLToLayer_conversion( r"C:\Project\gis\layers" ,r'C:\Project\gis') arcpy.KMLToLayer_conversion expects a file as its first parameter (KML or KMZ) but you are giving it a folder name. You could try concatenating the contents of your filename variable, with the ...


2

It only took ESRI five years to realize that killing off ArcScripts was one of their more stupid decisions....ArcScripts was easy, simple and just searched for what you wanted...it was one of the things that made ESRI products the best. Trying to find anything on ArcGIS Resource Center was always a nightmare. Now it's back! New Beta here: ...


3

Here's a trivial example, which generates a single 'hotspot' around one region: # Generate coords extent of Tanzania x <- runif(1000, min = 30, max = 40) y <- runif(1000, min = -12, max = -1) # Assign some values, make data frame xyvals <- runif(1000, min=0.1, max=0.5) xydata <- data.frame(x, y, vals = xyvals) # Generate a hotspot centred ...


1

In the past I've used data generated using a Gibbs Sampler which is described at http://www.geog.leeds.ac.uk/people/a.turner/publications/archive/BrunsdonEtAl1999.html


2

QGIS updated to the SIP API V2 between 1.8 and 2.0. See: https://hub.qgis.org/wiki/17/Python_plugin_API_changes_from_18_to_20#Replace-QStringList-with-list It will transparently convert some types (like QString or QList) between python and Qt types. So you can just use a python list of str or unicode objects and pass it to the pyqgis and pyqt API wherever ...


1

As described in https://www.gaia-gis.it/gaia-sins/spatialite-sql-latest.html the function is used as ST_Line_Interpolate_Point( line Curve , fraction Double precision ) : Point An example that can be tested with SQL command line for example with spatialite-gui. Fraction=0.5 finds the midpoint. SELECT ST_AsText( ST_Line_Interpolate_Point ...


2

This is calling on the built in map function, which takes a function as the first argument (arcpy.AddError) and telling it to call AddError for every piece of the message split by a new line character. So for example, if the traceback message was this: Error Reading File: File is of the wrong type Needs to be CSV file the raw string would be: ...


0

What you could do is use the Times tool on each band and then combine the individual rasters into one raster using the Composite Bands tool. Essentially to multiply each band, when adding the raster to the Times tool, double click on the raster filename again like you would open a folder. Then you'll see all the bands.


0

At ArcGIS for Server 10.1+ you can use the ArcGIS Server Administration Toolkit - 10.1+ From the description (emphases mine): The ArcGIS Server Administration Toolkit provides you the tools and scripts to help you administer your ArcGIS Server. These tools haven been written in Python and connect to the REST Admin of an ArcGIS Server allowing you to ...


2

I figured it out. Rather than setting up a new variable "params" and holding the multiple parameters to be returned through that, I just simplified it to return the parameters directly as shown below. return [param0, param1] Now it loads the tool up when clicked on with both of the parameters correctly displayed. I guess it's best to keep it simple ...


1

You create a memory layer without any fields. To set some attributes you need corresponding fields. When creating memory layers you can give field definitions as part of the argument type: self.layer = QgsVectorLayer(self.type+'?field_a:string(20)&field_b:int', self.name, "memory") For your layer to work you have to define the same fields as for the ...


0

Not sure why you're getting NULL values but the following code worked for me (note that I call the QGIS Zonal Statistics tool from the Processing plugin and I want to load the result): vectorlayer = qgis.utils.iface.mapCanvas().layer(0) rasterfile = qgis.utils.iface.mapCanvas().layer(1).source() processing.runandload('qgis:zonalstatistics', rasterfile, 3, ...


0

I was able to figure it out with a work around. I added the Lat/Long Fields and then us Convert Coordinate Notation. That generated a new feature class with two new fields: DDLat and DDLon. That got me what I needed even though I had to add a couple additional steps. The output was 076.###W, 37.####N as opposed to what I wanted which was (-76.###, 37.####) ...


2

To simply state your problem, you have one set of points with a value but those points/values apply to both ends of a line; you want to add two different point values as separate attributes to one line. There are (at least) two ways to do this. The first is to extract the start and end nodes of all your lines as points. Since you have an Advanced license, ...


0

it seems that my problem was in the GRASS algorithm I was using. Now, I've moved to GDAL algorithm named "Grid - InverseDistance To a Power" and it works. I don't really know what was wrong: my only suspect is that after running grass algorithm I would need to "convert" the grass raster map created to a "readble" raster, to be loaded in QGis correctly. I ...


0

I started to dive into VTK - The Visualization ToolKit (VTK) is an open source, freely available software system for 3D computer graphics. It is pretty powerful and robust tool, seems to be able to do all the operations I asked for though I can't confirm it all yet. On the other hand it doesn't support datum and projection as is expected from GIS software. ...


1

Use the Create Fishnet tool to create a grid of polygons the required size, and covering the area of ocean. Use the Erase tool to remove the areas of land from the fishnet you have created. If you have a dataset representing the ocean, you can simply clip the fishnet to the ocean. From here you can use your choice of several tools to examine the incidence ...


1

Yes, this is possible. Make your grid. Fishnet. Filter out the "sea area" in some way. Perhaps, Select Layer By Location, HAVE_THEIR_CENTER_IN, NEW_SELECTION (against a "sea" layer) Select the grid cells that contain a point. Select Layer By Location, CONTAINS, SUBSET SELECTION


4

It looks like you've done everything correctly. You can evaluate the errors from each method by performing the inverse calculations to find the distance given the origin and destination coordinates, then evaluate the residuals of distances. This is a round-trip exercise. # For Vincenty's method: geopy_inv_dist = geopy.distance.vincenty(origin, ...


4

As stated in the tool documentation for Calculate Field: Python expressions can use the geometry area and length properties with an areal or linear unit to convert the value to a different unit of measure (for example, !shape.length@kilometers!) These expressions are not usable with points or individual coordinates. Fortunately, you can use other ...


2

As requested, comment is appended below as an answer: "Also, is Feature To Polygon designed to work on a layer selection? Perhaps export the layer as a standalone feature class with Copy Features (in memory perhaps) and try running the tool that way. If that doesn't solve it, there are some threads here and here that use arcpy.Geometry.cut() for those who ...


1

Expression type needs to be PYTHON_9.3 This code worked for me: from arcpy import * fc = r"C:\test\test.gdb\test" fld = "testfld" shapeFldName = Describe (fc).shapeFieldName CalculateField_management (fc, fld, "!{}!.firstPoint.Z".format (shapeFldName), "PYTHON_9.3") Happy ...


2

You can't use punctuation marks in variable names in python. Your function should probably read more like this: def calc(LONG_x): if LONG_x >= -113.90550 and LONG_x <= -113.90559: return "05" else: return "0" You can then pass in !LONG_x! as an argument to the function. eg. result = calc(!LONG_x!)


0

Try using the absolute path in Python. Instead of H:, what does H: point to? For example: mxd = mapping.MapDocument(r"\FileServer\ThisIsWhereHPoints\Python\Python_Cookbook\Maps\TravisCounty.mxd") More about path referencing here.


2

Try saving the mxd using the save() method or just refresthing the display/TOC. If scripting is used to modify the appearance of some map document elements while using the CURRENT map document (for example, change a layer name, the data frame extent, and so on), the map may not automatically update with each executed line of code. To refresh the ...


0

Found an answer for those MXDs that do open in ArcMap but do (also) crash the Arcpy.listdataframes command. Maybe this helps someone else too: -Open the MXD. -Switch to layout view, select all elements. -In my case, a blank frame appeared when selected (it has no fill and no outline). -Check this frame's properties: In my MXDs, the objects exhibited ...


0

Sounds like a corrupt mxd. Did you try using Save As to save it under a different name? Mxds often can become invalid - resaving it is a good way to force a refresh of the internal properties.


0

I finally got a workaround by using the Generic Mapping Tool gmt. I used the nearneighbour command, which does the gridding much faster than gdal_grid: http://gmt.soest.hawaii.edu/doc/5.1.0/nearneighbor.html


5

Join the points to the lines, using a spatial or table join, to give the elevation (Z) at each end of the line. This allows you to calculate the elevation change (Z1 - Z2). Use your GIS to calculate the 2D length of the line (Shape.length). This allows you to use SOHCAHTOA to calculate the slope angle. tan(slope) = (opposite / adjacent) slope = ...


1

The python script is here at the bottom of the page http://resources.arcgis.com/en/help/main/10.2/index.html#//004800000028000000 First create a network out of your pipeline. You may have to export to a feature class and do it from there, I am not sure if it works on shapefiles. then create a seperate shapefile/featureclass with your incidents and load ...


1

There is a python module called networkx which is able to work on directed graphs. The basic concept is: Add all nodes to the graph (add_node) Add all edges to the graph (add_edge) Run bellman_ford on the graph It has successfully been used to find downstream reaches and wastewater structures in wastewater networks in the QGEP project (link points to ...


2

Feature To Polygon will slice polygons by line feature classes when you use the two feature classes as its input. Inputs: Results: If you only want certain polygons sliced by certain lines, use an SQL expression and feature layers to limit your inputs.


1

% formatting works but only within a string: myString = "%d_rest" % (Number) will substitute a number into the string.. for inserting a string use %s: myString = "%s_rest" % (InsertString) For your case a simple append might be the best: myMonths =['january', 'february', 'march','april','may','june','july','august', 'september', 'october', ...



Top 50 recent answers are included