Returns the K nearest elements to a given geometry.

post

/spatialviewer/api/v1/spark/nearestNeighbors

Returns a list containing the K nearest elements from an RDD or distributed spatial index to a given geometry. Note that for none asynchronous jobs you can use the service response as data source for the Map API to display the results on map.

Request

Supported Media Types
Query Parameters
Body ()
Job details
Root Schema : NearestNeighborsJobInfo
Type: object
Show Source
  • Path of the file or files in HDFS. Specify this property if useIndex is false.
    Example: /user/oracle/spatialviewer/tweetsJune.json
  • The geometry to determine the nearest neighbors. The geometry has to be in GeoJSON format.
    Example: {"type":"Point", "coordinates":[2.33139, 48.86864]}
  • The index path in HDFS. Specify this property if useIndex is true.
    Example: /user/oracle/spatialviewer/TweetsJune
  • The input format class. Optional property that can be set if useIndex is false. If the input format class is not specified then the SparkContext's textFile is used.
    Example: oracle.spatial.hadoop.vector.geojson.mapred.GeoJsonInputFormat
  • jar name with the user-defined classes like custom RecordInfoProvider or InputFormat. If the InputFormat class or the RecordInfoProvider class is not in the API, or in the hadoop API classes, then a jar with the user-defined classes must be provided. To be able to use this jar the user must add it in the /opt/oracle/oracle-spatial-graph/spatial/web-server/spatialviewer/WEB-INF/lib directory and restart the server. Optional property that can be set if useIndex is false.
    Example: myjar.jar
  • Number of nearest neighbors.
    Example: 10
  • Class of the input format keys. This property is required if an input format is defined.
    Example: org.apache.hadoop.io.LongWritable
  • The job output path. Specify this property if asynchronous is true.
    Example: /user/oracle/spatialviewer/NNResult
  • The class that provides the spatial information. Specify this property if useIndex is false.
    Example: oracle.spatial.spark.vector.recordinfoprovider.GeoJsonRecordInfoProvider
  • SRID of the geometries.
    Example: 8307
  • Double value that represents the tolerance used when performing spatial operations.
    Example: 0.05
  • true if an index is used as input, false otherwise
    Example: true
  • Class of the input format values. This property is required if an input format is defined.
    Example: org.apache.hadoop.io.Text
Back to Top

Response

Supported Media Types

200 Response

successful request
Body ()
Root Schema : RecordsInfo
Type: object
Show Source
Nested Schema : features
Type: array
Show Source
Nested Schema : Feature
Type: object
Show Source
Nested Schema : Geometry
Type: object
Show Source
Nested Schema : coordinates
Type: array
Show Source
Example:
[
    -73.86659,
    50.41706
]
Nested Schema : properties
Type: object
Extra fields of the filtered records (see 2.8.2.1 Spatial Indexing Class Structure). For example we can have extra fields named followers_count, friends_count, location and user_id
Show Source

202 Response

accepted asynchronous request
Body ()
Root Schema : AsyncNearestNeighborsJobResponse
Type: object
Show Source
Back to Top

Examples

The following example shows how to perform a nearest neighbors analysis by submitting a POST request on the REST resource using cURL.

curl -v -X POST "http://localhost:8045/spatialviewer/api/v1/spark/nearestNeighbors" -H  "accept: application/json" -H  "content-type: application/json" -d "{  \"useIndex\": true,  \"k\": 10,  \"geometry\": \"{\\\"type\\\":\\\"Point\\\", \\\"coordinates\\\":[2.33139, 48.86864]}\",  \"srid\": 8307,  \"tolerance\": 0.05,  \"indexPath\": \"/user/oracle/HOL/tweetsJune\"}" 

Example of Response Header

The following shows an example of the response header.

HTTP/1.1 200 OK Date: Wed, 15 Nov 2017 17:50:38 GMT Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, POST, DELETE, PUT Access-Control-Allow-Headers: Content-Type, Accept Transfer-Encoding: chunked  Content-Type: application/json

Example of Response Body

The following example shows the contents of the response body in JSON format, including one record:

{"type":"FeatureCollection","copyright":"Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.","srs":8307,"geodetic":true,"features":[{"type":"Feature","_id":"e8fd9cb3-8d1a-4c54-8583-9a4b682de2fd","geometry":{"type":"Point","coordinates":[-105.49998,28.19997]},"properties":{"RECORD_ID":"4789","followers_count":"13","friends_count":"199","location":"Chihuahua","user_id":"4092140"}}]} 
Back to Top