Questions tagged [function]

A programming function is a type of procedure or routine. Some programming languages make a distinction between a function, which returns a value, and a procedure, which performs some operation but does not return a value.

Filter by
Sorted by
Tagged with
6
votes
2answers
1k views

QGIS Field Calculator functions

Using QGIS 2.12.3, within the Field Calculator "Geometry" section, there are certain functions, such as "area", that also have a corresponding term beginning with a dollar sign, i.e. "$area". I don't ...
6
votes
1answer
172 views

Why do I need to use labelling when setting fill colour with a python expression in QGIS?

I'm having problems using a Python function in the expression editor to style a polygon fill in QGIS. I'm trying to use a random colour scheme. However, I need to do this over a series of different ...
5
votes
1answer
1k views

Style line-width proportionally to maintain relative size in Mapbox GL

I want a data driven line-width to keep its relative size in all sizes I tried using an exponential function for that but it did not work the way I expected. For the sake of the example let's say I ...
5
votes
1answer
411 views

Writing QGIS field calculator formula?

I have a table with 2 fields, field1 contains site specific data, field2 contains a number which groups the field1: Field1, Field2 180, 1 203, 1 220, 1 205, 1 160, 2 140, 2 135, 2 I want to sort ...
5
votes
1answer
960 views

referencing to features geometry in an expression

I have a layerA with roads and a layerB with one shortest path. If I put an aggregate function into a virtual field in layerB to calculate the sum of fieldAA where the shortest path contains features ...
5
votes
1answer
841 views

Specifying input layer in custom QGIS function to rank features

How do I specify the input layer so it refers to the layer from which the function was called (without having to explicitly identify it by name)? I have written a custom function to use in the ...
4
votes
2answers
2k views

How to extract a part of string from fields in QGIS field calculator?

I want to create a new field in my attribute table. My goal: returning all digits between the / and _ characters of the field named "location" by applying the next expression: regexp_substr( "Text", ...
4
votes
2answers
5k views

QGIS Error while executing Python function in openProject() Macro: “QgsMapLayerRegistry is not defined”

I have the following script that sets the a feature id automatically after a new feature is digitized. I want the following function to be executed automatically when project is opened (and layers ...
4
votes
1answer
104 views

How to re-use an expression, stored as a string, in QGIS Field Calculator

As discussed in this question, QGIS automatically saves recently used expressions in the field calculator. But recently used expressions are deleted after a while. Sometimes I need to re-use an ...
4
votes
2answers
312 views

How is the st_length function stored in an Oracle geodatabase?

How is the st_length function stored in an Oracle geodatabase? Is it in a: PL/SQL function Separate .dll library Somewhere else? I've noticed that the sde.st_length function works, even when the ...
4
votes
1answer
363 views

Creating function in function editor in QGIS

After my previous question Weighted values of field in QGIS, I successfully adapted the following formula in Expression dialogue "Value" / (sum("Value") / (count(CASE WHEN "Value" >= 1 THEN +1 END)...
4
votes
2answers
424 views

QGIS stopEditing function in python

I am trying to stop the edits using the python console of the QGIS and the code QgsTrackedVectorLayerTools.stopEditing(layer,False) where layer is the layer in the edit mode. I am receiving the ...
4
votes
1answer
919 views

Reading and plotting shapefiles with a custom function in R?

I have this piece of code that want to turn into a function r <- readShapeSpatial("roads") b <- readShapeSpatial("buildings") lc <- readShapeSpatial("landcover.shp") here is the preparation ...
3
votes
2answers
3k views

How to extract part of string after '*', '~', '-' or '#'

I have strings like this: 234/1-1 3345#5 11/2~10 6754*15 It needed only rightmost part of string after '-', '#', '~'or '*' . I figured how to extract when there is only one sign for example '~' ...
3
votes
2answers
9k views

Leaflet layers on different zoom levels. How?

I've added a polygon layer and a point layer to my leaflet map. I would like the points to appear after a certain zoom level or when a "click" event occurs e.g. (polygons.on("click", function....) ...
3
votes
1answer
147 views

Difference between two vector layer

I have two vector layer land cover for 2016 and 2018. I want to get result layer that will show changes in land cover e.g. the forest has changed into a meadow. What option in QGIS can I do that. In ...
3
votes
2answers
246 views

ST_Distance loop

I want to create a postgresql function which calculates the distances between random points who are stored in one table. For the Table: CREATE TABLE s_1( id bigserial primary key, the_geom geometry, ...
3
votes
1answer
110 views

PostGIS function testing geometries, inside and boundary

Is there a st_????(A geometry, B geometry) in PostGIS that returns true when B is inside A and possibly shares a boundary ? I would say no after reading the doc but something may have escaped me.
3
votes
1answer
391 views

Accessing each value from array and feed it to another function in PostGIS?

I have an edge_table containing start_id and start_geom column. I want to make one function which will take integer array as input (starts). In between the function, the array values will be checked ...
3
votes
0answers
189 views

ST_Difference in PostGIS : problem with geometry result (Polygon)

I'm experimenting a result issue using the ST_Difference spatial function in PostGIS. Input : Feature 1 and 2 overlaps each other. Both contains 5 vertices, like a rectangle (4 plus an additional ...
3
votes
1answer
433 views

Reusing leaflet map elements in custom functions in Shiny/R

I have an application that reuses several leaflet elements, so I'm trying to build functions to streamline my code. All of my logical attempts failed, so I utilized an example I was familiar with ...
2
votes
1answer
647 views

Selecting entities based on first character of field being a letter using QGIS?

I would like to select entities whose addresses are incomplete, i.e. the first character is a letter instead of being a number. Does QGIS have an "is numeric" -type function to accomplish this? Not ...
2
votes
2answers
105 views

Adding xy data and exporting layer in function using ArcPy?

I am trying to add xy data into the attribute tables of 2 point layers, then export the tables into 2 separate excel tables using this code: env.workspace = r"G:\PROJECTS\osfie\gis\lyr" lyr1 = r"G:\...
2
votes
2answers
58 views

Clipping Lines Using Expression in QGIS?

I have a set of roads that I wish to clip. How ever I only need a segment of each road based on the state its located in. I can do this independently but seems like there should be a better way. Ill ...
2
votes
1answer
239 views

Earth Engine - function for printing multiple histograms

I have several time periods within a feature where the precipitation was very low stored in a FeatureCollection with the properties "begin", "end", "amount", "days".I want to use the feature ...
2
votes
1answer
123 views

Linking layers using conditional spatial queries?

I am looking at a drainage scheme where there are blockages in the system. The blockages are one layer. I then have a layer containing the main risk areas within the area and another layer that ...
2
votes
1answer
2k views

Getting multiple functions to work with mouseover event in Leaflet

I am making a web mapping app using leaflet and some geoJSON data for a grid. I want to be able to mouseover each grid cell and both highlight that cell AND show a popup of the coordinates. In the ...
2
votes
1answer
8k views

Save raster to file when using stack() in R

I'm working on a function for raster package. In the end of the function I have to use stack() to create a RasterStack. When I do this the data source is in memory. I want to have the data source on ...
2
votes
1answer
174 views

Calculate mean for a each object of SpatialPointsDataFrame

I have a list with several SpatialPointsDataFrame objects, and each object has certain slots. How can I calculate the mean value of a certain slot for every object in the list, and then save that ...
2
votes
1answer
55 views

Cross-schema function call with PostGIS dependencies

I have an issue where I am unable to make a cross-schema function call because of that function's use of PostGIS. I have both PostGIS and my function in the public schema, but I'm trying to call the ...
2
votes
1answer
466 views

Can you auto-populate a field in Survey123 from another field by only pulling certain characters?

I have a field where the user inputs text Aa1Bb2Cc3 Am I able to auto populate another field by only populating the field with Bb or 3. Auto populate the field with characters [4:6] or just [9] ...
2
votes
1answer
1k views

Arcpy module to read csv files and create polyline shapefiles

I am creating a module in arcpy that will loop through a folder with csv files in it. I have both of them written, and they work fine on my computer. However when I send them to anyone else they won't ...
2
votes
1answer
480 views

QGIS polyline length calculation [closed]

I meet a problem while I try to calculate the length of a polyline in QGIS in the attribute table. I created a new column with the function "$length" inside (type: real, 10 digits and 3 digits of ...
2
votes
0answers
42 views

Calculating line length to both sites in QGIS

Is there a function or a plugin for QGIS that works like this? I have a line, for example, 7 km I click on that line at any point A popup or something gives me the distance to the left an to the ...
2
votes
0answers
53 views

Getting travel time while performing pgrouting i.e. what are parameters and function required?

While doing the pgrouting to find the shortest distance I got success in getting the output but when I thought to come up with the time consumed for travelling, I cannot find the proper source to get ...
2
votes
0answers
48 views

Populate b.field into a.field when 2 vector points not always coincident but should be coincident

Using QGIS/pgAdmin3, I have a situation where two vector points, should be coincident but I can't guarantee they always are, I need to take feature a.field and populate a field in feature b, upon both ...
2
votes
0answers
31 views

How to obtain Wide Function in QGIS?

Is there a way to compute the wide function in QGIS?. I want to obtain this function to compare the topology of two stream networks. According to Bras (1990) the wide geometrical function N(x) ...
2
votes
0answers
293 views

Splitting / Divide Polygon in same squares

I have a polygon in a table with 100 meters to 100 meters ( 1 row) and I would like to splitt / devide it to same square parts for 10 meters. The result should be then 100 rows with 10x10 meters. How ...
2
votes
0answers
178 views

Application of a Piecewise Logistic Function to Extract Seasonality Metrics

I am working with 16-day MODIS EVI (satellite) data and I want to fit a Piecewise Logistic Function through my 23 EVI data values. The following formula is for the Piecewise Logistic Function: y(t)= [...
1
vote
1answer
100 views

Filtering number of features in GeoServer using SLD?

I have published point file in geoserver from postgis table as store. I had huge data in my table(rows) and the data will keep udate daily (at least one point for one day). Now I want to show only ...
1
vote
1answer
66 views

Arcpy reclassify with function

I have two rasters, one with NDVI values, and one with greyscale values (=(red band + green band + blue band) / 3). The rasters have the same name. I need to reclassify them in arcpy with the ...
1
vote
1answer
70 views

Using double offset in QGIS Expression String Builder?

I need to dynamically translate points 20 metres from their original point to a suitable cartographic position. I have a rotation value stored in a rotation attribute. I cannot use this tool right ...
1
vote
1answer
60 views

Seeking Function to calculate red-edgeNDVI in Google Earth Engine?

I am trying to calculate the red-edgeNDVI ((NIR – red edge)/(NIR + red edge)) of an Image.Collection in Google Earth Engine. There is a built in function for NDVI but not for red-edge NDVI. The code I ...
1
vote
1answer
23 views

Apply function from rgeos package to data sets

I am using gDistance function from rgeos package to calculate the nearest distance from points to a polygon. Originally I used for loop to calculate the distance for each row in my points data set, ...
1
vote
1answer
1k views

Removing n first digits on a field attribute table using QGIS string functions

I'm looking for a QGIS function to remove the first n digits on a field attribute table using QGIS string function. For exemple I have the following string in a QGIS attribute table: 742-004-SRV ...
1
vote
1answer
13k views

Python: Point in polygon, boundary and vertex check (ray casting)

So I have written some code to check whether a point [(x,y)] lies within a polygon [(x,y), (x,y), (x,y), (x,y)] but the code fails if the point lies on a boundary or a vertex, I need this to be ...
1
vote
1answer
88 views

Earth Engine how to avoid timeout for buffer calculation?

I have a function that takes a feature and creates a buffer around it. createBuffer = function(feature){ var AOI = feature.geometry().buffer(3000); return ee.Feature(AOI).copyProperties(feature)...
1
vote
1answer
294 views

NDWI and Cloud Pixel count

I am trying to add the (amount of pixels of) NDWI and Clouds as bands to my image collection. The NDWI works out, but I get stuck when adding the Clouds. The error refers to an incompatible number of ...
1
vote
1answer
26 views

Classifying text field 'B' using integer in field 'A'?

I wrote an if elif statement that will loop through records (field A) and populate a new field (field B) based on A's contents. Field A name is 'CLASS'. Field B is 'class_desc'. reclass(!class_desc!...
1
vote
1answer
887 views

Nearest Neighbour function

I'm trying to create a function which calculates the nearest neighbors under a certain length in a table s_1 an stores them in an output table. This is what I've got so far: CREATE OR REPLACE ...