Comments (6)
Hello, I have the same request, it will be very helpful to have this feature :)
@jpd-defra for now I am using this to compute it :
data = [
("a", "LINESTRING (0 0, 1 1, 1 0)", "POINT (0.5 0.5)"),
("b", "LINESTRING (0 0, 1 0, 2 1, 2 2)", "POINT (1 1)"),
]
df = spark_session.createDataFrame(data, ["id", "line_wkt", "point_wkt"])
df = df.withColumn("line", expr("ST_GeomFromWKT(line_wkt)")).withColumn(
"point", expr("ST_GeomFromWKT(point_wkt)")
)
df = df.withColumn("closest_point", expr("ST_ClosestPoint(line, point)"))
df = df.withColumn("line_vertices", expr("ST_DumpPoints(line)"))
df = df.withColumn(
"vertex_distances",
expr(
"transform(line_vertices, vertex -> ST_Distance(vertex, closest_point))"
),
)
df = df.withColumn(
"closest_vertex_index",
expr("array_position(vertex_distances, array_min(vertex_distances)) - 1"),
)
df = df.withColumn(
"line_locate_point",
when(
col("closest_vertex_index") == 0,
expr(
"ST_Distance(line_vertices[closest_vertex_index + 1], closest_point) / ST_Length(line)"
),
).otherwise(
expr(
"ST_Length(ST_LineFromMultiPoint(ST_Collect(slice(line_vertices, 1, closest_vertex_index+1)))) + ST_Distance(line_vertices[closest_vertex_index + 1], closest_point) / ST_Length(line)"
)
),
)
from sedona.
This function can be easily implemented by
public static double lineLocatePoint(Geometry geom, Geometry point) {
double length = geom.getLength();
LengthIndexedLine indexedLine = new LengthIndexedLine(geom);
return indexedLine.indexOf(point.getCoordinate()) / length;
}
If you are interested, please refer to the implementation of ST_LineInterpolatePoint: https://github.com/apache/sedona/blob/master/common/src/main/java/org/apache/sedona/common/Functions.java#L635
Then create your PR to Sedona
from sedona.
Thanks @jiayuasu. Have never written any Java before, but if its just a case of dropping your suggested code into the Functions.java
file and submitting the PR, then I could do that.
from sedona.
Thanks. In fact, it is more than that. We need to add more test cases and wrappers.
from sedona.
@jpd-defra @ojabri1 Hi folks, Sedona 1.5.1 has been released. ST_LineLocatePoint is included! See: https://sedona.apache.org/1.5.1/api/sql/Function/#st_linelocatepoint
Please give it a try!
from sedona.
@jiayuasu - thanks for the heads up. I spun up a Databricks cluster with 1.5.1 but found I was getting a REDACTED_LOCAL_PART type error when trying to read any parquets I had made prior to the upgrade. Not quite sure what is going on, but given a tight deadline for some work, have had to drop back to 1.5.0 for now.
from sedona.
Related Issues (20)
- H3 functions missing methods on Databricks: `java.lang.NoSuchMethodError: com.uber.h3core.H3Core...` HOT 5
- RS_AsBase64 returns empty string HOT 3
- rs_setbandnodatavalue not working as expected HOT 2
- Error reading file greater than 2GB HOT 1
- Installing apache-sedona Python package does not install all dependencies (Sedona 1.5.0) HOT 2
- [Feature] Add ST_IsValidDetail as built-in function.
- 1.5.0 spark shaded protobuf version conflict with application HOT 2
- Support of 3D?
- Feature request: ST_Snap HOT 1
- Microsoft Fabric HOT 26
- Apache Sedona backend for Ibis project?
- Save / Load indexed spatial & partitioned Rdd HOT 2
- Clarify SedonaUtils documentation HOT 1
- Write a geotiff raster , but just found _SUCCESS file in output HDFS dir HOT 3
- Noisy warnings on optional imports
- Map RDD and GeometryType (not an instance of type GeometryType()) HOT 2
- When I resample a raster to very width*height raster , Serde.serialize is limited in 2GB HOT 2
- When I use Bicubic alg to resample a raster with no data pixel , the output raster would be filled unexpected data in no data pixel HOT 3
- fieldNames - AttributeError: Not available before 1.0.0 sedona version HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sedona.