Here's a python function that will select random features in a layer based on percent, ignoring current selection:
def SelectRandomByPercent (layer, percent):
#layer variable is the layer name in TOC
#percent is percent as whole number (0-100)
if percent > 100:
print "percent is greater than 100"
if percent < 0:
You can use fractals for this: .
The upper row was generated with the fractal dimension d=2.0005 (left: elevation map, right: aspect map), the lower row with fractal dimension d=2.90 (left: elevation map, right: aspect map). I used r.surf.fractal of GRASS GIS. Then simply export the artificial DEM with r.out.gdal (or the GUI) to GeoTIFF.
Generally, I also recommend using the spatial ecology tools as discussed by blah238.
However, another method you could try would be to add an attribute called Random to store a random number:
Then, using the field calculator on that attribute, with the Python Parser, use the following codeblock:
Personally I do not like the random point algorithm in ArcGIS. Alternatively, use Geospatial Modelling Environment's (GME) genrandompnts function. You will be able to identify specific polygons where random points will be excluded (see highlighted area in attached .jpg). Best of all this software is free.
GME provides you with a suite of analysis and ...
I made and tested the functions I need. For point generation I used a simplified version of the functions in trac.osgeo.org/postgis/wiki/UserWikiRandomPoint:
CREATE OR REPLACE FUNCTION random_point( x_min integer DEFAULT 13, y_min integer DEFAULT 49,
x_max integer DEFAULT 16, y_max integer DEFAULT 51, srid integer DEFAULT 4326 )
RETURNS geometry AS
as mentioned by @George, the randint takes a sample with repetition. If you want unique values, create a list of the required size and shuffle it.
import random, arcpy
listUnique = range(maxvalue)
with arcpy.da.UpdateCursor(featureClass,[fieldToUpdate]) as cursor:
for row in cursor:
row = ...
You can edit the script to set your seed value. For example, if I want to set a seed value to the Random points inside polygons (fixed) tool, I can find the script in:
C:/Program Files/QGIS 2.16.1/apps/qgis/python/plugins/processing/algs/qgis/
Edit the script and search for random.seed() then insert your value (it is intially empty):
(Note: You may have ...
I would guess that your polygon layer originally was not saved with the EPSG:28356 CRS but that you set it manually.
Most likely the polygon layer was orignally saved with another CRS using degrees as units.
I did a quick test using polygons with a CRS of EPSG:4326 (i.e. using degrees as units) and using your exact parameters for the Random Points Inside ...
The ST_GeneratePoints function in PostGIS does this quite well.
You simply provide it with a geometry and the desired number of points, for example:
SELECT ST_GeneratePoints(geom, 100);
It's implemented following the same approach as your pseudocode, but it prepares (internally indexes) the polygon so that the if point within polygon tests are fast.
Try or read this page for some good information. and second link show you the way of random digital elevatin model.
Numerical and Scientific Python and Data Visualisation
creating elevation/height field gdal numpy python
There is also an earlier Select features at random script from @StephenLead available for ArcGIS Desktop. Although written, I think, for ArcGIS 9.x, and last modified in 2008, I used it in about 2010 at 10.0, and it still worked well.
There is a large amount of documentation from ESRI on creating your own tools in Python, so I will assume that you can access your selected layer without issue. There are many methods for selecting data randomly, for example choosing in random number in the range of the number of features (using the random module as suggested by @MichaelMiles-Stimson above), ...
Select Feature by Radius like under the link you provided.
Create a new shapefile with a single point, then create a buffer with needed radius for your point (Vector -> Geoprocessing -> Buffer) and eventually use it to select your points -> Research tools -> Select by location
Vector -> Research tools -> Random selection will give you an ...
You can use Vector -> Research Tools -> Random Points by using a field to put your "weights". For example, in my shapefile the field n_points has the number of random points for each feature:
Selecting "Use value from input field" (n_points):
Result is showing the "weights" for each feature:
It is possible if you convert your raster to a vector layer.
Quick example, starting from this classification raster:
Use Raster > Conversion > Polygonize to convert it to a vector layer:
If you want to create points over a whole class (and not over each separate "patch"), use the Vector > Geometry Tools > Singleparts to Multiparts tool.
You can use Random points inside polygons (fixed) from Processing Toolbox. If you don't see Processing Toolbox panel, activate it from menu Processing --> Toolbox. For distances in meters you have to use projected CRS (e.g some UTM) for more information about CRS see QGIS Doucumentation
Point sampling tool that you mentioned, is good for retrieving ...
Following PyQGIS code is one of possible approach:
registry = QgsMapLayerRegistry.instance()
trajectory = registry.mapLayersByName('trajectory')
extent_trajectory = registry.mapLayersByName('extent_trajectory')
feat_extent_trajectory = extent_trajectory.getFeatures().next()
line_points = [ feat.geometry().asPolyline() for feat in ...
If there isn't the need to use PyQGIS, maybe the Random points inside polygons (fixed) algorithm from the Processing Toolbox should return what you are looking for: it allows to specify the number of the points or the density as a parameter (in addition to a minimum distance among them).
Instead, using PyQGIS, you may run this simple code from the Python ...
You could try Hawth's Tools: http://www.spatialecology.com/htools/rndsel.php
Note that the existing selection is not honored so you would have to make a feature layer from the existing selection first.
A script implementation of this would be relatively straightforward:
Create random points for subset A, creating points α.
Buffer α by distance A, creating polygon buff1.
Use Erase to remove buff1 from erase0 (input polygon), creating polygon erase1.
Create random points for subset B, based on erase1, creating points β.
Buffer β by distance B, creating ...
Here is an R solution using a Gaussian Kernel to add autocorrelation to a random raster. Although, I have to say that the GRASS r.surf.fractal function, suggested by @markusN, seems like the best approach.
# Create 100x100 random raster with a Z range of 500-1500
r <- raster(ncols=100, nrows=100, xmn=0)
r <- runif(ncell(r), min=...
You can manipulate individual point geometry using an Update Cursor. Accessing the SHAPE@XY token is by far the most efficient cursor-based approach. However, if you have a polygon of your area of interest, using a random point generator will likely be more efficient. In this example, I use a minimum and maximum threshold to set the limits for a random ...
If I understand you correctly, you want to draw a distance-constrained random sample from your data for each observation in the data. This is akin to a K nearest neighbor analysis.
Here is an example workflow that will create a kNN random sample, using a minimum distance constraint, and add the corresponding rowname back to your data.
Add libraries ...
You can generate random numbers for sure using the RandomNumberGenerator transformer. It could create either integers or floats.
Characters are a bit more difficult. There's no random generator for that. You could either use the RandomNumberGenerator to generate character codes and convert them to ASCII using the CharacterCodeReplacer, or you could try and ...
What you want to do is to generate a random set of numbers within the following approximated box:
Source for these points is https://gist.github.com/UsabilityEtc/6d2059bd4f0181a98d76 ...
For making reproducible a random selection you need to use in a PyQGIS script, for instance, 'random.seed' method from numpy. Assuming that you have 10.000 points in your layer, next code select same 250 points each time is running (with seed equal 0).
import numpy as np
random_numbers = 
n = 0
while (n < 250):
number = np....
You can do it in two steps:
Create a negative buffer for the polygons. It the same old buffer algoritm, but with a negative distance. The buffer distance should be half of the desired minimum distance between points from different polygons.
Run the Random Points Inside Polygons... on these new polygons