Giter VIP home page Giter VIP logo

Comments (11)

MikeChenfu avatar MikeChenfu commented on May 23, 2024

Thanks for the great tool.

I am trying to find intersection area between each polygon in RDD1 and each polygon in RDD2.

I just want know if this function is working. I check the SpatialJoinShp.scala file and see some comments .
//val query = JoinQuery.SpatialJoinQuery(wdpa, species, false, false) // val join_result = query.rdd.map((tuple: (Polygon, util.HashSet[Polygon])) => (tuple._1, tuple._2.asScala.map(tuple._1.intersection(_).getArea)) ) // val intersections = join_result.collect()

I try to compile and run them but get errors. If possible, could you provide a sample code ? Thank you so much.

from sedona.

jiayuasu avatar jiayuasu commented on May 23, 2024

@MikeChenfu

I suggest you use JoinQuery.SpatialJoinQueryFlat() API. This is a flatMap version of SpatialJoinQuery API. This will make it easier for you to return all intersection.

It will return a <Polygon, Polygon> pair RDD. The two polygons intersect each other.

The following sentence is the correct code to return the intersection of each <Polygon,Polygon> pair. I have tested it.

val resultSize = JoinQuery.SpatialJoinQueryFlat(objectRDD,queryWindowRDD,true,false).rdd.map[Double](f =>f._1.intersection(f._2).getArea)

from sedona.

MikeChenfu avatar MikeChenfu commented on May 23, 2024

@jiayuasu
Thanks for your help. It works well.
Could you tell me where to define the "getArea“ function? I look through the code but get nothing. (It is my first time to use Geospark library, please forgive me if the question is stupid)
Next step, I plan to find the intersection polygon between any two polygons in RDD1 and RDD2. Many thanks if you have any suggestions.

from sedona.

jiayuasu avatar jiayuasu commented on May 23, 2024

Hi @MikeChenfu ,

To get the intersection polygon, you just don't call getArea.
The code is something like this:

val result = JoinQuery.SpatialJoinQueryFlat(objectRDD,queryWindowRDD,true,false).rdd.map[Geometry](f =>f._1.intersection(f._2))

getArea code is in JTSplus, a customized JTS library for GeoSpark. It is not GeoSpark repository. Its own repo is here:
https://github.com/jiayuasu/JTSplus

Original JTS repo is here:
https://github.com/locationtech/jts

from sedona.

MikeChenfu avatar MikeChenfu commented on May 23, 2024

@jiayuasu
JoinQuery.SpatialJoinQueryFlat returns nothing when I use csv File instead of Shapefile. I may make something wrong.

The code is to get data from CSV file(WKT format).
val objectRDD = new PolygonRDD(sc, PolygonRDDInputLocation, PolygonRDDStartOffset, PolygonRDDEndOffset, PolygonRDDSplitter, true) val queryWindowRDD = new PolygonRDD(sc, PolygonRDDInputLocationT, PolygonRDDStartOffset, PolygonRDDEndOffset, PolygonRDDSplitter, true)
And I analyze them according to the mention of compiler.

objectRDD.analyze(); queryWindowRDD.analyze(); objectRDD.spatialPartitioning(GridType.QUADTREE) queryWindowRDD.spatialPartitioning(wdpa.partitionTree)

The return value is NULL when I use JoinQuery.SpatialJoinQueryFlat. I think it should be return a <Polygon, Polygon> pair RDD.
val result1 = JoinQuery.SpatialJoinQueryFlat(objectRDD,queryWindowRDD,false,false) result1.take(1).foreach(line => println(line))

from sedona.

jiayuasu avatar jiayuasu commented on May 23, 2024

@MikeChenfu
Why did you partition your queryWindowRDD using wdpa.partitionTree instead of objectDD.getPartitioner?

from sedona.

MikeChenfu avatar MikeChenfu commented on May 23, 2024

@jiayuasu
It is a typo. "wapa" is the used name of objectDD. I am so sorry for that.

objectRDD.spatialPartitioning(GridType.QUADTREE) queryWindowRDD.spatialPartitioning(objectRDD.getPartitioner)
objectDD contains 6 polygons and queryWindowRDD also contains 6 polygons. I am trying to find the problems. I really appreciate it if you have any suggestions.

from sedona.

jiayuasu avatar jiayuasu commented on May 23, 2024

@MikeChenfu Are you sure your polygons have intersection? We can chat over GeoSpark GitterChat for a faster communication.

from sedona.

MikeChenfu avatar MikeChenfu commented on May 23, 2024

@jiayuasu
Thanks for your kind help. I am still working on it and may find the problems.
When JoinQuery.SpatialJoinQueryFlat(objectRDD,queryWindowRDD,true,true) is used, I will get correct result.

from sedona.

jiayuasu avatar jiayuasu commented on May 23, 2024

@MikeChenfu

Ohhhh! I forgot to tell you, the last parameter in SpatialJoinQueryFlat is ConsiderBoundaryIntersection.

You must set it as "true" in order to find intersected polygon. Otherwise it will only return polygon that are full contained by the other one.

The API explanation is here: http://www.public.asu.edu/~jiayu2/geospark/javadoc/0.9.1/

from sedona.

MikeChenfu avatar MikeChenfu commented on May 23, 2024

@jiayuasu
Got it. Many thanks for your kind help.

from sedona.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.