Skip to content
Permalink
Browse files
[FEATURE][processing] Add "random points on lines" algorithm
The Random points on lines algorithm supplements the existing "Random points along line" algorithm, and will prove to be more useful to the majority of users than the "original".

Features:

The points are distributed randomly over the lines based on "along the line" distance, meaning that the distribution of the points will be flat over the length of the line (each place on the feature has the same probability of being "hit"). 

The Random points along line, on the other hand, uses a line segment based approach, meaning that the density will depend on the segment length (short segments will have a higher point density than longer ones).
  • Loading branch information
havatv committed Mar 30, 2020
1 parent 3a74358 commit c774ade88fc5eb7eb4ab633707f1c55bc1e3c68e
@@ -112,6 +112,7 @@
<file>themes/default/algorithms/mAlgorithmNearestNeighbour.svg</file>
<file>themes/default/algorithms/mAlgorithmNetworkAnalysis.svg</file>
<file>themes/default/algorithms/mAlgorithmPolygonToLine.svg</file>
<file>themes/default/algorithms/mAlgorithmRandomPointsOnLines.svg</file>
<file>themes/default/algorithms/mAlgorithmRandomPointsWithinPolygon.svg</file>
<file>themes/default/algorithms/mAlgorithmRandomPointsWithinExtent.svg</file>
<file>themes/default/algorithms/mAlgorithmRegularPoints.svg</file>
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="24"
height="24"
viewBox="0 0 6.35 6.35"
version="1.1"
id="svg20"
sodipodi:docname="mAlgorithmRandomPointsOnLines.svg"
inkscape:version="0.92.4 (f8dce91, 2019-08-02)">
<metadata
id="metadata26">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs24" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1312"
inkscape:window-height="1127"
id="namedview22"
showgrid="false"
inkscape:zoom="29.816738"
inkscape:cx="7.3227221"
inkscape:cy="10.572049"
inkscape:window-x="67"
inkscape:window-y="27"
inkscape:window-maximized="0"
inkscape:current-layer="svg20" />
<g
id="g4547"
style="stroke:#afafaf;stroke-opacity:0.99435025">
<path
sodipodi:nodetypes="cccc"
inkscape:connector-curvature="0"
id="path3733"
d="M 0.23699003,0.19522033 2.3692648,3.395074 2.0941816,4.6196379 0.3460723,6.1192849"
style="fill:none;stroke:#afafaf;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:0.99435025" />
<path
sodipodi:nodetypes="ccc"
inkscape:connector-curvature="0"
id="path4540"
d="M 2.4225069,0.50226379 5.3064434,1.9131743 4.7119087,5.4537611"
style="fill:none;stroke:#afafaf;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:0.99435025" />
<path
sodipodi:nodetypes="cccc"
inkscape:connector-curvature="0"
id="path4542"
d="M 3.842291,1.1500403 2.9105575,1.8510588 3.1856407,3.2176011 3.7180599,6.5807148"
style="fill:none;stroke:#afafaf;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:0.99435025" />
</g>
<circle
cx="4.4182353"
cy="1.4027646"
id="circle6"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
<circle
cx="5.0579815"
cy="3.4926841"
id="circle6-3"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
<circle
cx="2.8661895"
cy="0.72410506"
id="circle6-6"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
<circle
cx="2.9283047"
cy="1.8776797"
id="circle6-7"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
<circle
cx="3.7003126"
cy="6.3322525"
id="circle6-5"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
<circle
cx="0.95835429"
cy="1.2565242"
id="circle6-35"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
<circle
cx="1.5706362"
cy="5.0899415"
id="circle6-62"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
<circle
cx="0.80750227"
cy="5.7110972"
id="circle6-9"
style="fill:#cc0000;fill-opacity:1;stroke:#5e5e5e;stroke-width:0.18342039;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
r="0.30516481" />
</svg>
@@ -0,0 +1,194 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ randompointsonlines.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-0.6048972614132321</gml:X><gml:Y>-1</gml:Y></gml:coord>
<gml:coord><gml:X>5.5706404884031</gml:X><gml:Y>2.983529974375954</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.680375434309419,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>0</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-0.211234146361814,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>1</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.566198447517212,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>2</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.596880066952147,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>3</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.823294715873569,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>4</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-0.604897261413232,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>5</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-0.329554488570222,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>6</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.7">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.536459189623808,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>7</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-0.444450578393624,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>8</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.9">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.107939911590861,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>9</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.10">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.63030422879655,1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>10</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.11">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.02166180257582,2.26721545068545</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>11</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.12">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.24573385250727,1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>12</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.13">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.7532568994615,1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>13</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.14">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.00278822202651,1.16311098855098</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>14</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.15">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.00489146772082,1.28615086166781</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>15</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.16">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.02126252335406,2.24385761621232</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>16</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.17">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.01650061531363,1.96528599584743</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>17</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.18">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.48357073824498,1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>18</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.19">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.02294016604118,2.3419997134092</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>19</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.20">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.0,0.148289222714595</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>20</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.21">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.20958450135476,2.0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>21</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.22">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.0,1.24842025927014</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>22</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.23">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.79936109924074,2.98352997437595</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>23</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.24">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.0,1.42533776707812</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>24</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.25">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.0,2.64746304269474</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>25</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.26">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.0,1.1807269654443</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>26</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.27">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.0,0.989853181150094</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>27</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.28">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.5706404884031,2.94703455703008</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>28</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
<gml:featureMember>
<ogr:randompointsonlines fid="randompointsonlines.29">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.0,1.98552220048164</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:rand_point_id>29</ogr:rand_point_id>
</ogr:randompointsonlines>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="randompointsonlines" type="ogr:randompointsonlines_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="randompointsonlines_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="rand_point_id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:long">
<xs:totalDigits value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

0 comments on commit c774ade

Please sign in to comment.