How to insert GEOJSON using Aerospike Rest Client

A record is successfully inserted using this query:

INSERT INTO test.geoPSGC (PK,PSGC,NAME,COORDINATES) VALUES ("PH042103059","PH042103059","P.F. ESPIRITU VIII", GEOJSON('{"type": "Polygon", "coordinates": [[[120.963819085,14.4360609570001],[120.963508642,14.437767122],[120.963132639,14.4396434060001],[120.963030111,14.4401597790001],[120.962205408,14.4399052410001],[120.960393097,14.439447073],[120.960260737,14.4401495980001],[120.96018129,14.440132872],[120.959486942,14.439986693],[120.959097233,14.4411254360001],[120.959038955,14.441300109],[120.960790176,14.441788822],[120.960572028,14.4424181910001],[120.959700188,14.4445419810001],[120.960098399,14.4447199690001],[120.960774416,14.4450736870001],[120.960692088,14.4452229070001],[120.960470831,14.4456654210001],[120.960321611,14.445969007],[120.958550232,14.4448707610001],[120.958129094,14.443015749],[120.955905609,14.4426806610001],[120.955608883,14.443570838],[120.955346395,14.4434795380001],[120.955289332,14.4437420260001],[120.954969781,14.443696376],[120.954889894,14.4440045150001],[120.954225114,14.443719201],[120.953954066,14.443696376],[120.952336035,14.444176962],[120.952255088,14.443998277],[120.953521745,14.443688057],[120.953902021,14.4424971950001],[120.954722615,14.442737369],[120.954912753,14.4421769630001],[120.955873449,14.442287043],[120.956533927,14.440325622],[120.956223702,14.440255571],[120.95590347,14.440245564],[120.955142919,14.4402956],[120.954782659,14.440255571],[120.954332332,14.4400954550001],[120.954452419,14.439054701],[120.953801948,14.438904592],[120.952911303,14.438774498],[120.952965697,14.438500543],[120.952985959,14.4382396770001],[120.953011179,14.4381358630001],[120.953277921,14.4369847450001],[120.953318707,14.4368087330001],[120.956736645,14.436828264],[120.956768379,14.4362091220001],[120.956779247,14.435895783],[120.956804391,14.4355445270001],[120.956772893,14.435371087],[120.956809539,14.4351651270001],[120.956836543,14.434532458],[120.956863741,14.4340464310001],[120.956467101,14.4338641910001],[120.9557208,14.4338163350001],[120.955738353,14.4330264620001],[120.955744235,14.4323139710001],[120.957669155,14.4323067990001],[120.957844682,14.4326051960001],[120.96010627,14.4329594650001],[120.961732768,14.4327991060001],[120.962557471,14.4326845640001],[120.964088989,14.4329410820001],[120.96407482,14.433125068],[120.964044954,14.433513331],[120.964071138,14.433868956],[120.964138908,14.434272455],[120.964139531,14.4343794550001],[120.963928361,14.435506225],[120.963819085,14.4360609570001]]]}'));

But throwing an error "Unrecognized token ‘GEOJSON’ when using Aerospike Rest Client v1.10.4 (latest)

Request body:

{
    "PSGC": "PH042103059",
    "NAME": "P.F. ESPIRITU VIII",
    "COORDINATES": GEOJSON('{"type": "Polygon", "coordinates": [[[120.963819085,14.4360609570001],[120.963508642,14.437767122],[120.963132639,14.4396434060001],[120.963030111,14.4401597790001],[120.962205408,14.4399052410001],[120.960393097,14.439447073],[120.960260737,14.4401495980001],[120.96018129,14.440132872],[120.959486942,14.439986693],[120.959097233,14.4411254360001],[120.959038955,14.441300109],[120.960790176,14.441788822],[120.960572028,14.4424181910001],[120.959700188,14.4445419810001],[120.960098399,14.4447199690001],[120.960774416,14.4450736870001],[120.960692088,14.4452229070001],[120.960470831,14.4456654210001],[120.960321611,14.445969007],[120.958550232,14.4448707610001],[120.958129094,14.443015749],[120.955905609,14.4426806610001],[120.955608883,14.443570838],[120.955346395,14.4434795380001],[120.955289332,14.4437420260001],[120.954969781,14.443696376],[120.954889894,14.4440045150001],[120.954225114,14.443719201],[120.953954066,14.443696376],[120.952336035,14.444176962],[120.952255088,14.443998277],[120.953521745,14.443688057],[120.953902021,14.4424971950001],[120.954722615,14.442737369],[120.954912753,14.4421769630001],[120.955873449,14.442287043],[120.956533927,14.440325622],[120.956223702,14.440255571],[120.95590347,14.440245564],[120.955142919,14.4402956],[120.954782659,14.440255571],[120.954332332,14.4400954550001],[120.954452419,14.439054701],[120.953801948,14.438904592],[120.952911303,14.438774498],[120.952965697,14.438500543],[120.952985959,14.4382396770001],[120.953011179,14.4381358630001],[120.953277921,14.4369847450001],[120.953318707,14.4368087330001],[120.956736645,14.436828264],[120.956768379,14.4362091220001],[120.956779247,14.435895783],[120.956804391,14.4355445270001],[120.956772893,14.435371087],[120.956809539,14.4351651270001],[120.956836543,14.434532458],[120.956863741,14.4340464310001],[120.956467101,14.4338641910001],[120.9557208,14.4338163350001],[120.955738353,14.4330264620001],[120.955744235,14.4323139710001],[120.957669155,14.4323067990001],[120.957844682,14.4326051960001],[120.96010627,14.4329594650001],[120.961732768,14.4327991060001],[120.962557471,14.4326845640001],[120.964088989,14.4329410820001],[120.96407482,14.433125068],[120.964044954,14.433513331],[120.964071138,14.433868956],[120.964138908,14.434272455],[120.964139531,14.4343794550001],[120.963928361,14.435506225],[120.963819085,14.4360609570001]]]}'))
}

I posted the same question in stackoverflow 
here's the link: https://stackoverflow.com/questions/70945453/how-to-insert-geojson-using-aerospike-rest-client

It looks like you received an answer over on stackoverflow. Thanks for sharing!

@aanderson I found out that it was successfully inserted using rest client but still not working as GeoJSON.

This query below only returns a record when using insert query.

SELECT * FROM test.geoPSGC WHERE COORDINATES CONTAINS GeoJSON('{"type":"Point","coordinates":[120.9559,14.44024]}') 

Do you get an error back with that query? Have you created a Geospatial index?

Yes geospatial index is already created, thats why it works when GeoJSON is inserted using insert query.

From the post on Stackoverflow, it looks like you’re sending the record with JSON. MessagePack is the recommended format to send GeoJSON data with the REST client.

Have you tried formatting with MessagePack? Note that the GeoJSON object is represented with MessagePack extension type 23.

Oh, I just want to align that for now I am manually using the rest client using swagger UI and not in any programming language.

Also, I prefer using JSON instead of MessagePack as it is more commonly used for testing purposes including the creation of test automation framework.

Ok, then using the JSON format from the Stackoverflow post, are you encoding your coordinate string?

I spun up a container and through the swagger UI sent this:

{
  "PSGC": "PH042103059",
  "NAME": "P.F. ESPIRITU VIII",
  "COORDINATES": {
    "type": "GEO_JSON",
    "value": "eyJ0eXBlIjogIlBvbHlnb24iLCAiY29vcmRpbmF0ZXMiOiBbW1sxMjAuOTYzODE5MDg1LDE0LjQzNjA2MDk1NzAwMDFdLFsxMjAuOTYzNTA4NjQyLDE0LjQzNzc2NzEy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csMTQuNDM1ODk1NzgzXSxbMTIwLjk1NjgwNDM5MSwxNC40MzU1NDQ1MjcwMDAxXSxbMTIwLjk1Njc3Mjg5MywxNC40MzUzNzEwODddLFsxMjAuOTU2ODA5NTM5LDE0LjQzNTE2NTEyNzAwMDFdLFsxMjAuOTU2ODM2NTQzLDE0LjQzNDUzMjQ1OF0sWzEyMC45NTY4NjM3NDEsMTQuNDM0MDQ2NDMxMDAwMV0sWzEyMC45NTY0NjcxMDEsMTQuNDMzODY0MTkxMDAwMV0sWzEyMC45NTU3MjA4LDE0LjQzMzgxNjMzNTAwMDFdLFsxMjAuOTU1NzM4MzUzLDE0LjQzMzAyNjQ2MjAwMDFdLFsxMjAuOTU1NzQ0MjM1LDE0LjQzMjMxMzk3MTAwMDFdLFsxMjAuOTU3NjY5MTU1LDE0LjQzMjMwNjc5OTAwMDFdLFsxMjAuOTU3ODQ0NjgyLDE0LjQzMjYwNTE5NjAwMDFdLFsxMjAuOTYwMTA2MjcsMTQuNDMyOTU5NDY1MDAwMV0sWzEyMC45NjE3MzI3NjgsMTQuNDMyNzk5MTA2MDAwMV0sWzEyMC45NjI1NTc0NzEsMTQuNDMyNjg0NTY0MDAwMV0sWzEyMC45NjQwODg5ODksMTQuNDMyOTQxMDgyMDAwMV0sWzEyMC45NjQwNzQ4MiwxNC40MzMxMjUwNjhdLFsxMjAuOTY0MDQ0OTU0LDE0LjQzMzUxMzMzMV0sWzEyMC45NjQwNzExMzgsMTQuNDMzODY4OTU2XSxbMTIwLjk2NDEzODkwOCwxNC40MzQyNzI0NTVdLFsxMjAuOTY0MTM5NTMxLDE0LjQzNDM3OTQ1NTAwMDFdLFsxMjAuOTYzOTI4MzYxLDE0LjQzNTUwNjIyNV0sWzEyMC45NjM4MTkwODUsMTQuNDM2MDYwOTU3MDAwMV1dXX0="
  }
}

I was then able to use your query and return the record. Using that, are you still unable to get the expected result?

It is now working. Sorry I forgot to remove the escape character for double quotes before converting to base64.

Thank you @aanderson

1 Like

This topic was automatically closed 84 days after the last reply. New replies are no longer allowed.