日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Geospark从Shapefile中加载RDD

發布時間:2025/1/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

  • 我們從Shapefile中創建一個Spark的RDD,本次要導入的Shapefile是廣州全市的公交站點.
  • image.png

    image.png

  • 然后我們初始化一個SparkContext,并調用GeoSpark的ShapefileReader,將我們的Shape文件導入。
  • SparkConf conf = new SparkConf(); conf.setAppName("GeoSpark02"); conf.setMaster("local[*]"); conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer"); conf.set("spark.kryo.registrator", "org.datasyslab.geospark.serde.GeoSparkKryoRegistrator"); JavaSparkContext sc = new JavaSparkContext(conf);// Get SpatialRDD String shapeInputLocation = Learn02.class.getResource("/parks").toString(); SpatialRDD rdd = ShapefileReader.readToGeometryRDD(sc, shapeInputLocation);

    查詢

    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())); 查詢結果總數為: 62

    2. 使用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())); 查詢結果總數為: 62

    3. 輸出查詢結果

    // 遍歷查詢結果 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的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。