scially / geosparkbook Goto Github PK
View Code? Open in Web Editor NEWSedona(GeoSpark)系列教程
Sedona(GeoSpark)系列教程
SparkConf conf = new SparkConf();
conf.setAppName("GeoSpark03");
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);
SpatialRDD parkRdd = ShapefileReader.readToGeometryRDD(sc, "D:/bigdata/data/parks");
// 构建索引
boolean buildOnSpatialPartitionedRDD = false; // 如果只需要在做空间分析的时候构建索引,则设置为true
// 临近查询(KNN)
parkRdd.buildIndex(IndexType.RTREE, buildOnSpatialPartitionedRDD); // QTREE不支持KNN查询
//写入
parkRdd.indexedRawRDD.saveAsObjectFile("hdfs://localhost:8020/parkrdd");
//读取
SpatialRDD savedRDD = new SpatialRDD<Geometry>();
savedRDD.indexedRawRDD = sc.objectFile("hdfs://localhost:8020/parkrdd");
GeometryFactory geometryFactory = new GeometryFactory();
boolean usingIndex = true; // 使用索引
Point pointObject = geometryFactory.createPoint(new Coordinate(-123.1,49.2));
int K = 5; // K Nearest Neighbors
List<Geometry> result = KNNQuery.SpatialKnnQuery(savedRDD, pointObject, K, usingIndex); 这里报错
// 输出结果
System.out.println("距离点(-123.1,49.2)最近的五个公园是:");
for (int i = 0; i < result.size(); i++){
System.out.println(String.format("%d: %s",i+1, result.get(i).toString()));
}
sc.stop();
Exception in thread "main" org.apache.spark.SparkException: Job aborted due to stage failure: Task 1 in stage 0.0 failed 1 times, most recent failure: Lost task 1.0 in stage 0.0 (TID 1, localhost, executor driver): java.util.NoSuchElementException: next on empty iterator
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.