Skip to content

Commit 068c2b4

Browse files
authored
Merge branch 'apache:master' into master
2 parents 371fc39 + 9cdb052 commit 068c2b4

File tree

35 files changed

+1347
-325
lines changed

35 files changed

+1347
-325
lines changed

common/src/main/java/org/apache/sedona/common/Functions.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,24 @@ private static Geometry[] convertGeometryToArray(Geometry geom) {
18121812
return array;
18131813
}
18141814

1815+
public static Geometry generatePoints(Geometry geom, int numPoints, long seed) {
1816+
RandomPointsBuilderSeed pointsBuilder = new RandomPointsBuilderSeed(geom.getFactory(), seed);
1817+
pointsBuilder.setExtent(geom);
1818+
pointsBuilder.setNumPoints(numPoints);
1819+
return pointsBuilder.getGeometry();
1820+
}
1821+
1822+
public static Geometry generatePoints(Geometry geom, int numPoints) {
1823+
return generatePoints(geom, numPoints, 0);
1824+
}
1825+
1826+
public static Geometry generatePoints(Geometry geom, int numPoints, Random random) {
1827+
RandomPointsBuilderSeed pointsBuilder = new RandomPointsBuilderSeed(geom.getFactory(), random);
1828+
pointsBuilder.setExtent(geom);
1829+
pointsBuilder.setNumPoints(numPoints);
1830+
return pointsBuilder.getGeometry();
1831+
}
1832+
18151833
public static Integer nRings(Geometry geometry) throws Exception {
18161834
String geometryType = geometry.getGeometryType();
18171835
if (!(geometry instanceof Polygon || geometry instanceof MultiPolygon)) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.sedona.common.utils;
20+
21+
import java.util.Random;
22+
import org.locationtech.jts.geom.*;
23+
import org.locationtech.jts.shape.random.RandomPointsBuilder;
24+
25+
public class RandomPointsBuilderSeed extends RandomPointsBuilder {
26+
Random rand;
27+
28+
public RandomPointsBuilderSeed(GeometryFactory geometryFactory, long seed) {
29+
super(geometryFactory);
30+
if (seed > 0) {
31+
this.rand = new Random(seed);
32+
} else {
33+
this.rand = new Random();
34+
}
35+
}
36+
37+
public RandomPointsBuilderSeed(GeometryFactory geometryFactory, Random random) {
38+
super(geometryFactory);
39+
this.rand = random;
40+
}
41+
42+
@Override
43+
protected Coordinate createRandomCoord(Envelope env) {
44+
double x = env.getMinX() + env.getWidth() * rand.nextDouble();
45+
double y = env.getMinY() + env.getHeight() * rand.nextDouble();
46+
return createCoord(x, y);
47+
}
48+
}

common/src/test/java/org/apache/sedona/common/FunctionsTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,48 @@ public void minimumClearanceLine() throws ParseException {
21122112
assertEquals(expected, actual);
21132113
}
21142114

2115+
@Test
2116+
public void generatePoints() throws ParseException {
2117+
Geometry geom = Constructors.geomFromWKT("LINESTRING(50 50,10 10,10 50)", 4326);
2118+
2119+
Geometry actual =
2120+
Functions.generatePoints(Functions.buffer(geom, 10, false, "endcap=round join=round"), 12);
2121+
assertEquals(actual.getNumGeometries(), 12);
2122+
2123+
actual =
2124+
Functions.reducePrecision(
2125+
Functions.generatePoints(
2126+
Functions.buffer(geom, 10, false, "endcap=round join=round"), 5, 100),
2127+
5);
2128+
String expected =
2129+
"MULTIPOINT ((40.02957 46.70645), (37.11646 37.38582), (14.2051 29.23363), (40.82533 31.47273), (28.16839 34.16338))";
2130+
assertEquals(expected, actual.toString());
2131+
assertEquals(4326, actual.getSRID());
2132+
2133+
geom =
2134+
Constructors.geomFromEWKT(
2135+
"MULTIPOLYGON (((10 0, 10 10, 20 10, 20 0, 10 0)), ((50 0, 50 10, 70 10, 70 0, 50 0)))");
2136+
actual = Functions.generatePoints(geom, 30);
2137+
assertEquals(actual.getNumGeometries(), 30);
2138+
2139+
// Deterministic when using the same seed
2140+
Geometry first = Functions.generatePoints(geom, 10, 100);
2141+
Geometry second = Functions.generatePoints(geom, 10, 100);
2142+
assertEquals(first, second);
2143+
2144+
// Deterministic when using the same random number generator
2145+
geom = geom.buffer(10, 48);
2146+
Random rand = new Random(100);
2147+
Random rand2 = new Random(100);
2148+
first = Functions.generatePoints(geom, 100, rand);
2149+
second = Functions.generatePoints(geom, 100, rand);
2150+
Geometry first2 = Functions.generatePoints(geom, 100, rand2);
2151+
Geometry second2 = Functions.generatePoints(geom, 100, rand2);
2152+
assertNotEquals(first, second);
2153+
assertEquals(first, first2);
2154+
assertEquals(second, second2);
2155+
}
2156+
21152157
@Test
21162158
public void nRingsPolygonOnlyExternal() throws Exception {
21172159
Polygon polygon = GEOMETRY_FACTORY.createPolygon(coordArray(1, 0, 1, 1, 2, 1, 2, 0, 1, 0));

docs/api/flink/Function.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,35 @@ Output:
15521552
5.0990195135927845
15531553
```
15541554

1555+
## ST_GeneratePoints
1556+
1557+
Introduction: Generates a specified quantity of pseudo-random points within the boundaries of the provided polygonal geometry. When `seed` is either zero or not defined then output will be random.
1558+
1559+
Format:
1560+
1561+
`ST_GeneratePoints(geom: Geometry, numPoints: Integer, seed: Long = 0)`
1562+
1563+
`ST_GeneratePoints(geom: Geometry, numPoints: Integer)`
1564+
1565+
Since: `v1.6.1`
1566+
1567+
SQL Example:
1568+
1569+
```sql
1570+
SELECT ST_GeneratePoints(
1571+
ST_GeomFromWKT('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'), 4
1572+
)
1573+
```
1574+
1575+
Output:
1576+
1577+
!!!Note
1578+
Due to the pseudo-random nature of point generation, the output of this function will vary between executions and may not match any provided examples.
1579+
1580+
```
1581+
MULTIPOINT ((0.2393028905520183 0.9721563442837837), (0.3805848547053376 0.7546556656982678), (0.0950295778200995 0.2494334895495989), (0.4133520939987385 0.3447046312451945))
1582+
```
1583+
15551584
## ST_GeoHash
15561585

15571586
Introduction: Returns GeoHash of the geometry with given precision

docs/api/snowflake/vector-data/Function.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,33 @@ Output:
11631163
5.0990195135927845
11641164
```
11651165

1166+
## ST_GeneratePoints
1167+
1168+
Introduction: Generates a specified quantity of pseudo-random points within the boundaries of the provided polygonal geometry. When `seed` is either zero or not defined then output will be random.
1169+
1170+
Format:
1171+
1172+
`ST_GeneratePoints(geom: Geometry, numPoints: Integer, seed: Long = 0)`
1173+
1174+
`ST_GeneratePoints(geom: Geometry, numPoints: Integer)`
1175+
1176+
SQL Example:
1177+
1178+
```sql
1179+
SELECT ST_GeneratePoints(
1180+
ST_GeomFromWKT('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'), 4
1181+
)
1182+
```
1183+
1184+
Output:
1185+
1186+
!!!Note
1187+
Due to the pseudo-random nature of point generation, the output of this function will vary between executions and may not match any provided examples.
1188+
1189+
```
1190+
MULTIPOINT ((0.2393028905520183 0.9721563442837837), (0.3805848547053376 0.7546556656982678), (0.0950295778200995 0.2494334895495989), (0.4133520939987385 0.3447046312451945))
1191+
```
1192+
11661193
## ST_GeoHash
11671194

11681195
Introduction: Returns GeoHash of the geometry with given precision

docs/api/sql/Function.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,35 @@ Output:
15571557
5.0990195135927845
15581558
```
15591559

1560+
## ST_GeneratePoints
1561+
1562+
Introduction: Generates a specified quantity of pseudo-random points within the boundaries of the provided polygonal geometry. When `seed` is either zero or not defined then output will be random.
1563+
1564+
Format:
1565+
1566+
`ST_GeneratePoints(geom: Geometry, numPoints: Integer, seed: Long = 0)`
1567+
1568+
`ST_GeneratePoints(geom: Geometry, numPoints: Integer)`
1569+
1570+
Since: `v1.6.1`
1571+
1572+
SQL Example:
1573+
1574+
```sql
1575+
SELECT ST_GeneratePoints(
1576+
ST_GeomFromWKT('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'), 4
1577+
)
1578+
```
1579+
1580+
Output:
1581+
1582+
!!!Note
1583+
Due to the pseudo-random nature of point generation, the output of this function will vary between executions and may not match any provided examples.
1584+
1585+
```
1586+
MULTIPOINT ((0.2393028905520183 0.9721563442837837), (0.3805848547053376 0.7546556656982678), (0.0950295778200995 0.2494334895495989), (0.4133520939987385 0.3447046312451945))
1587+
```
1588+
15601589
## ST_GeoHash
15611590

15621591
Introduction: Returns GeoHash of the geometry with given precision

docs/api/sql/Raster-operators.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ SELECT RS_GeoReferrence(ST_MakeEmptyRaster(1, 3, 4, 100.0, 200.0,2.0, -3.0, 0.1,
452452

453453
### RS_GeoTransform
454454

455-
Introduction: Returns an array of parameters that represent the GeoTransformation of the raster. The array contains the following values:
455+
Introduction: Returns a struct of parameters that represent the GeoTransformation of the raster. The struct has the following schema:
456456

457-
- 0: pixel width along west-east axis (x-axis)
458-
- 1: pixel height along north-south axis (y-axis)
459-
- 2: Rotation of the raster
460-
- 3: Angular separation between x-axis and y-axis
461-
- 4: X ordinate of upper-left coordinate
462-
- 5: Y ordinate of upper-left coordinate
457+
- magnitudeI: size of a pixel along the transformed i axis
458+
- magnitudeJ: size of a pixel along the transformed j axis
459+
- thetaI: angle by which the raster is rotated (Radians positive clockwise)
460+
- thetaIJ: angle from transformed i axis to transformed j axis (Radians positive counter-clockwise)
461+
- offsetX: X ordinate of the upper-left corner of the upper-left pixel
462+
- offsetY: Y ordinate of the upper-left corner of the upper-left pixel
463463

464464
!!!note
465465
Refer to [this image](https://www.researchgate.net/figure/Relation-between-the-cartesian-axes-x-y-and-i-j-axes-of-the-pixels_fig3_313860913) for a clear understanding between i & j axis and x & y-axis.
@@ -479,7 +479,7 @@ SELECT RS_GeoTransform(
479479
Output:
480480

481481
```
482-
[2.23606797749979, 2.23606797749979, -1.1071487177940904, -2.214297435588181, 1.0, 2.0]
482+
{2.23606797749979, 2.23606797749979, -1.1071487177940904, -2.214297435588181, 1.0, 2.0}
483483
```
484484

485485
### RS_Height
@@ -1094,7 +1094,7 @@ Output:
10941094

10951095
### RS_SummaryStatsAll
10961096

1097-
Introduction: Returns summary stats consisting of count, sum, mean, stddev, min, max for a given band in raster. If band is not specified then it defaults to `1`.
1097+
Introduction: Returns summary stats struct consisting of count, sum, mean, stddev, min, max for a given band in raster. If band is not specified then it defaults to `1`.
10981098

10991099
!!!Note
11001100
If excludeNoDataValue is set `true` then it will only count pixels with value not equal to the nodata value of the raster.
@@ -1122,7 +1122,7 @@ SELECT RS_SummaryStatsAll(RS_MakeEmptyRaster(2, 5, 5, 0, 0, 1, -1, 0, 0, 0), 1,
11221122
Output:
11231123

11241124
```
1125-
25.0, 204.0, 8.16, 9.4678403028357, 0.0, 25.0
1125+
{25.0, 204.0, 8.16, 9.4678403028357, 0.0, 25.0}
11261126
```
11271127

11281128
SQL Example
@@ -1134,7 +1134,7 @@ SELECT RS_SummaryStatsAll(RS_MakeEmptyRaster(2, 5, 5, 0, 0, 1, -1, 0, 0, 0), 1)
11341134
Output:
11351135

11361136
```
1137-
14.0, 204.0, 14.571428571428571, 11.509091348732502, 1.0, 25.0
1137+
{14.0, 204.0, 14.571428571428571, 11.509091348732502, 1.0, 25.0}
11381138
```
11391139

11401140
### RS_ZonalStats
@@ -1207,17 +1207,17 @@ Output:
12071207

12081208
### RS_ZonalStatsAll
12091209

1210-
Introduction: Returns an array of statistic values, where each statistic is computed over a region defined by the `zone` geometry. The array contains the following values:
1210+
Introduction: Returns a struct of statistic values, where each statistic is computed over a region defined by the `zone` geometry. The struct has the following schema:
12111211

1212-
- 0: Count of the pixels.
1213-
- 1: Sum of the pixel values.
1214-
- 2: Arithmetic mean.
1215-
- 3: Median.
1216-
- 4: Mode.
1217-
- 5: Standard deviation.
1218-
- 6: Variance.
1219-
- 7: Minimum value of the zone.
1220-
- 8: Maximum value of the zone.
1212+
- count: Count of the pixels.
1213+
- sum: Sum of the pixel values.
1214+
- mean: Arithmetic mean.
1215+
- median: Median.
1216+
- mode: Mode.
1217+
- stddev: Standard deviation.
1218+
- variance: Variance.
1219+
- min: Minimum value of the zone.
1220+
- max: Maximum value of the zone.
12211221

12221222
!!!note
12231223
If the coordinate reference system (CRS) of the input `zone` geometry differs from that of the `raster`, then `zone` will be transformed to match the CRS of the `raster` before computation.
@@ -1258,7 +1258,7 @@ RS_ZonalStatsAll(rast1, geom1, 1, false)
12581258
Output:
12591259

12601260
```
1261-
[184792.0, 1.0690406E7, 57.851021689230684, 0.0, 0.0, 92.13277429243035, 8488.448098819916, 0.0, 255.0]
1261+
{184792.0, 1.0690406E7, 57.851021689230684, 0.0, 0.0, 92.13277429243035, 8488.448098819916, 0.0, 255.0}
12621262
```
12631263

12641264
SQL Example
@@ -1270,7 +1270,7 @@ RS_ZonalStatsAll(rast2, geom2, 1, true)
12701270
Output:
12711271

12721272
```
1273-
[14184.0, 3213526.0, 226.55992667794473, 255.0, 255.0, 74.87605357255357, 5606.423398599913, 1.0, 255.0]
1273+
{14184.0, 3213526.0, 226.55992667794473, 255.0, 255.0, 74.87605357255357, 5606.423398599913, 1.0, 255.0}
12741274
```
12751275

12761276
## Raster Predicates
@@ -1541,18 +1541,18 @@ Output (Shown as heatmap):
15411541

15421542
### RS_MetaData
15431543

1544-
Introduction: Returns the metadata of the raster as an array of double. The array contains the following values:
1544+
Introduction: Returns the metadata of the raster as a struct. The struct has the following schema:
15451545

1546-
- 0: upper left x coordinate of the raster, in terms of CRS units
1547-
- 1: upper left y coordinate of the raster, in terms of CRS units
1548-
- 2: width of the raster, in terms of pixels
1549-
- 3: height of the raster, in terms of pixels
1550-
- 4: ScaleX: the scaling factor in the x direction
1551-
- 5: ScaleY: the scaling factor in the y direction
1552-
- 6: skew in x direction (rotation x)
1553-
- 7: skew in y direction (rotation y)
1554-
- 8: srid of the raster
1555-
- 9: number of bands
1546+
- upperLeftX: upper left x coordinate of the raster, in terms of CRS units
1547+
- upperLeftX: upper left y coordinate of the raster, in terms of CRS units
1548+
- gridWidth: width of the raster, in terms of pixels
1549+
- gridHeight: height of the raster, in terms of pixels
1550+
- scaleX: ScaleX: the scaling factor in the x direction
1551+
- scaleY: ScaleY: the scaling factor in the y direction
1552+
- skewX: skew in x direction (rotation x)
1553+
- skewY: skew in y direction (rotation y)
1554+
- srid: srid of the raster
1555+
- numSampleDimensions: number of bands
15561556

15571557
For more information about ScaleX, ScaleY, SkewX, SkewY, please refer to the [Affine Transformations](Raster-affine-transformation.md) section.
15581558

@@ -1569,7 +1569,7 @@ SELECT RS_MetaData(raster) FROM raster_table
15691569
Output:
15701570

15711571
```
1572-
[-1.3095817809482181E7, 4021262.7487925636, 512.0, 517.0, 72.32861272132695, -72.32861272132695, 0.0, 0.0, 3857.0, 1.0]
1572+
{-1.3095817809482181E7, 4021262.7487925636, 512.0, 517.0, 72.32861272132695, -72.32861272132695, 0.0, 0.0, 3857.0, 1.0}
15731573
```
15741574

15751575
### RS_NormalizeAll

flink/src/main/java/org/apache/sedona/flink/Catalog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public static UserDefinedFunction[] getFuncs() {
184184
new Functions.ST_ForceCollection(),
185185
new Functions.ST_ForcePolygonCW(),
186186
new Functions.ST_ForceRHR(),
187+
new Functions.ST_GeneratePoints(),
187188
new Functions.ST_NRings(),
188189
new Functions.ST_IsPolygonCCW(),
189190
new Functions.ST_ForcePolygonCCW(),

0 commit comments

Comments
 (0)