Cannot write geojson data in go-client

go
geo
geoindex
#1
func main() {
	runRecord_Entry(shared.Client)
	runOptimal_Location(shared.Client)

	log.Println("Application ran successfully GrandMaster")
}
func runRecord_Entry(client *as.Client) {

	// define a client to connect to

	client, err := as.NewClient("127.0.0.1",3000)
	PanicOnError(err)


	key, err := as.NewKey("jolar","jolardest","dert")

	PanicOnError(err)
	binName := "gjsn"

	// queries only work on indices
	client.DropIndex("writepolicy", "jolar", "jolardest", "set+binName")

	idxTask, err := client.CreateIndex("writepolicy", "jolar", "jolardest","set+binName","gjsn","as.GEO2DSPHERE")

	// The Data
	points := []as.GeoJSONValue{
		`{
		    "type": "feature",
			"geometry": {
				"type": "Point",
		    	"coordinates": [13.009318762,80.003157854]
				},
			"properties": {
				"name": "workshop block",
				"Demand": "49589",
				"capacity":"808"}
		}`}
	// define some bins
	ptsb:=  points
	bin := as.NewBin(binName, as.NewGeoJSONValue(points))

	// write the bins
	client.PutBins(shared.WritePolicy, key, bin)
	record, err := client.Get(shared.Policy, key, binName)
	shared.PanicOnError(err)

	fmt.Println("The records are wriiten !!")
}
#2

This is a server error. Your GeoJson is malformed. "type": "feature" should be "type": "Feature". (Case-Sensitive).

Here is the full example:

package main

import (
	"fmt"
	"log"
	"time"

	as "github.com/aerospike/aerospike-client-go"
)

func main() {
	runRecord_Entry()

	log.Println("Application ran successfully GrandMaster")
}

func runRecord_Entry() {

	// define a client to connect to

	client, err := as.NewClient("vmu1604", 3000)
	if err != nil {
		log.Fatalln(err)
	}

	key, err := as.NewKey("test", "jolardest", "dert")

	if err != nil {
		log.Fatalln(err)
	}
	binName := "gjsn"

	// queries only work on indices
	client.DropIndex(nil, "test", "jolardest", "set+binName")

	idxTask, err := client.CreateIndex(nil, "test", "jolardest", "set+binName", "gjsn", as.GEO2DSPHERE)
	if err != nil {
		log.Fatalln(err)
	}
	<-idxTask.OnComplete()

	time.Sleep(time.Second)

	// The Data
	point := as.GeoJSONValue(`{
		    "type": "Feature",
			"geometry": {
				"type": "Point",
		    	"coordinates": [13.009318762,80.003157854]
				},
			"properties": {
				"name": "workshop block",
				"Demand": "49589",
				"capacity":"808"
			}
		}`)
	// define some bins
	bin := as.NewBin(binName, point)

	// write the bins
	err = client.PutBins(nil, key, bin)
	if err != nil {
		log.Fatalln(err)
	}

	record, err := client.Get(nil, key, binName)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println("The record is written:", record.Bins)
}
#3

Thanks a lot, It worked now !!

#4

Hey but still im unnable to enter collection of data,

    `{"type": "FeatureCollection",
			"features": [
				{
					"type": "Feature",
					"geometry" : {
						"type" : "Point",
						"coordinates": [13.009318762,80.003157854]
					},
					"properties" : {
						"name" :"Work shop",
						"demand":"49589",
						"capacity":"4231"
					}
				},
				{
					"type": "Feature",
					"geometry" : {
						"type" : "Point",
						"coordinates": [13.00961276, 80.003422154]
					},
					"properties" : {
						"name" :"main block",
						"demand":"247859",
						"capacity":"2974"
					}
				}
				{
					"type": "Feature",
					"geometry" : {
						"type" : "Point",
						"coordinates": [13.009318762,80.003157854]
					},
					"properties" : {
						"name" :"acadamics",
						"demand":"49589",
						"capacity":"4231"
					}
				},
				{
					"type": "Feature",
					"geometry" : {
						"type" : "Point",
						"coordinates": [13.00961276, 80.003422154]
					},
					"properties" : {
						"name" :"i blk",
						"demand":"247879",
						"capacity":"174"
					}
				}
			]
			}`

like this instead of a single point This is the out put im getting, go run zarpin.go 2019/03/27 20:53:09 hosts: 127.0.0.1 2019/03/27 20:53:09 port: 3000 2019/03/27 20:53:09 namespace: test 2019/03/27 20:53:09 set: testset 2019/03/27 20:53:09 Invalid GeoJSON on insert/update exit status 1

Thanks in advance

#5

Your GeoJSON is invalid. In this case, it looks like you have forgotten one comma after the second feature.

#6

Yea fixed it, still the same error persists. Checked the format with “http://geojson.org/geojson-spec.html#geometry-objects

#7

Then you have to take this up in the server section of the forum.

#8

This is how you do it:

package main

import (
	"log"

	as "github.com/aerospike/aerospike-client-go"
)

func main() {
	// define a client to connect to
	client, err := as.NewClient("vmu1804", 3000)
	PanicOnError(err)

	// The Data
	bins := []as.BinMap{
		{
			"name":     "Work shop",
			"demand":   "49589",
			"capacity": "4231",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.009318762,80.003157854]}`),
		},
		{
			"name":     "main block",
			"demand":   "247859",
			"capacity": "2974",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.00961276, 80.003422154]}`),
		},
		{
			"name":     "Work shop",
			"demand":   "49589",
			"capacity": "4231",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.009318762,80.003157854]}`),
		},
		{
			"name":     "main block",
			"demand":   "247859",
			"capacity": "2974",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.00961276, 80.003422154]}`),
		},
	}

	// write the records to the database
	for i, b := range bins {
		// define some bins
		key, _ := as.NewKey("test", "testset", i)
		err = client.Put(nil, key, b)
		PanicOnError(err)
	}

	log.Println("The records are written !!")

	// queries only work on indices; you should create the index only once
	// The index is created on the namespace, set and bin that should be indexed.
	client.CreateIndex(nil, "test", "testset", "ma_geo_index", "coord", as.GEO2DSPHERE)

	stm := as.NewStatement("test", "testset")
	// there are multiple different types of filters. You can find the list in the docs.
	stm.SetFilter(as.NewGeoWithinRadiusFilter("coord", float64(13.009318762), float64(80.003157854), float64(50000)))
	recordset, err := client.Query(nil, stm)
	PanicOnError(err)

	count := 0
	for res := range recordset.Results() {
		PanicOnError(res.Err)
		log.Println(res.Record.Bins)
		count++
	}

	// 1 region should be found
	log.Println("Records found: ", count)

	log.Println("Application ran successfully GrandMaster")
}

func PanicOnError(err error) {
	if err != nil {
		log.Fatalln(err)
	}
}