Geospark从Shapefile中加载RDD
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Geospark从Shapefile中加载RDD
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                title: ‘(二)Geospark從Shapefile中加載RDD’
 date: 2021-04-29 19:09:48
 tags: []
 published: true
 hideInList: false
 #feature: /post-images/(二)Geospark從Shapefile中加載RDD.png
 isTop: false
從Shapefile中加載RDD
我們從Shapefile中創建一個Spark的RDD,本次要導入的Shapefile是廣州全市的公交站點.
Geospark從Shapefile中加載RDD
從Shapefile中加載RDD
image.png
image.png
查詢
1. 使用Envelop查詢
//Envelop Envelope rangeQueryWindow = new Envelope(-123.1, -123.2, 49.2, 49.3); boolean considerBoundaryIntersection = false;// Only return gemeotries fully covered by the window boolean usingIndex = false; JavaRDD<Geometry> queryResult = RangeQuery.SpatialRangeQuery(rdd, rangeQueryWindow, considerBoundaryIntersection, usingIndex); System.out.println(String.format("查詢結果總數為: %d",queryResult.count())); 查詢結果總數為: 622. 使用Geomtery查詢
GeoSpark提供了GeomtryFactory來構造Polygon、Line、Point等Geometry。
// Geometry GeometryFactory geometryFactory = new GeometryFactory(); Coordinate[] coordinates = new Coordinate[5]; coordinates[0] = new Coordinate(-123.1,49.2); coordinates[1] = new Coordinate(-123.1,49.3); coordinates[2] = new Coordinate(-123.2,49.3); coordinates[3] = new Coordinate(-123.2,29.2); coordinates[4] = coordinates[0]; // The last coordinate is the same as the first coordinate in order to compose a closed ring Polygon polygonObject = geometryFactory.createPolygon(coordinates); queryResult = RangeQuery.SpatialRangeQuery(rdd, polygonObject, considerBoundaryIntersection, usingIndex); System.out.println(String.format("查詢結果總數為: %d",queryResult.count())); 查詢結果總數為: 623. 輸出查詢結果
// 遍歷查詢結果 queryResult.foreach(new VoidFunction<Geometry>() {@Overridepublic void call(Geometry geometry) throws Exception {System.out.println(geometry);} }); POLYGON ((-123.15566057081632 49.26206733490204, -123.15564728017853 49.26241791476514, -123.15548939905344 49.262415429329856, -123.15550257747702 49.26206484963618, -123.15566057081632 49.26206733490204)) 1 -9999 Kitsilano N POLYGON ((-123.15760176703519 49.261936547646954, -123.15718706338478 49.2619299178749, -123.15719832396375 49.26162160945501, -123.15761313807661 49.26162814910161, -123.15760218456263 49.26192530535148, -123.15760176703519 49.261936547646954)) 2 208 Rosemary Brown Park Kitsilano W 11th Avenue Vine Street N N N ................................. POLYGON ((-123.12325003271694 49.290529597005786, -123.12325184999034 POLYGON ((-123.11921795166444 49.288179012132034, -123.11889234917355 49.28806261407178, -123.11905901714364 49.28781953241384, -123.11954592548769 49.28796238352621, -123.11921795166444 49.288179012132034)) 80 27 Portal Park Downtown W Hastings Street Thurlow Street N N N參考鏈接:https://www.jianshu.com/p/4b9e875227aa
總結
以上是生活随笔為你收集整理的Geospark从Shapefile中加载RDD的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: GeoMesa-空间数据存储引擎入门学习
- 下一篇: Geospark空间查询
