0

I am using geospark 1.1.3 with scala and I am trying to split into lines a polygon shapefile dataset which contains 189 polygons. I am expecting to get each side of each polygon as a LineString, therefore I am trying to create a LineStringRDD which will contain all the streets.

I already executed successfully this process by creating an intermediate csv file where each line represents the pair of coordinates X1,Y1,X2,Y2 from each one of the lines extracted from each one of the 189 polygons.

However, I do not want to access the disk during the process due to I/O latency. So, I want to do it during the execution, so I created this method:

//Splitting the Cadastral polygons in Lines.   
  def creatingPolylinesRam (sc:SparkContext, path:String, cadastralRDD:PolygonRDD): LineStringRDD = {  
    val result = cadastralRDD.getRawSpatialRDD
    val polygons = result.count() - 1
    for( p <- 0 to polygons.toInt){      
      val coordinates = result.collect().get(p).getCoordinates().count(x => true) - 1 
      for( c <- 0 to coordinates){
        if (c != coordinates){
          val geometryFactory = new GeometryFactory()
          val coordinates = new Array[Coordinate](3)
          coordinates(0) = new Coordinate(result.collect().get(p).getCoordinates.apply(c).getOrdinate(0),result.collect().get(p).getCoordinates.apply(c).getOrdinate(1))
          coordinates(1) = new Coordinate(result.collect().get(p).getCoordinates.apply(c+1).getOrdinate(0),result.collect().get(p).getCoordinates.apply(c+1).getOrdinate(1))
          val linestringObject = geometryFactory.createLineString(coordinates)
//HERE I SHOULD DO SOMETHING TO PROCESS EACH LineString AND CREATE A LineStringRDD
        }
       }
          }
  }

Can anyone give me a clue about how I can create my final LineStringRDD or if an easy way exists to do that?

Some overall information, I am starting with a shapefile of polygons which was previously transformed into a PolygonRDD.

def creatingCadPolygons (sc:SparkContext, path:String): PolygonRDD = {
    val cadastralRDD = ShapefileReader.readToPolygonRDD(sc, path)
    println("creatingCadPolygons executed")
    return cadastralRDD    
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.