How to deal with GeoJson in CKAN DataStore?

半城伤御伤魂 提交于 2020-04-30 07:25:46

问题


Is it true CKAN DataStore is able to deal with GeoJson? I've not seen any reference in the documentation except for this link about the DataStore Map visualization, saying:

Shows data stored on the DataStore in an interactive map. It supports plotting markers from a pair of latitude / longitude fields or from a field containing a GeoJSON representation of the geometries.

Thus, I'm supossing GeoJson is accepted in DataStore columns. Anyway, I've not found any GeoJson CKAN type, thus, again, I'm guessing the simple Json type must be use for this purpose.

Can anybody confirm this? Thanks!

EDIT 1

I've created a resource and a datastore and a "recline_map_view" associated to the resource. Then, I've upserted a value, which is shown by this datastore_search operation:

$ curl -X POST "https://host:port/api/3/action/datastore_search" -d '{"resource_id":"14418d40-de42-4fdd-84f7-3c51244c7469"}' -H "Authorization: xxx" -k
{"help": "https://host:port/api/3/action/help_show?name=datastore_search", "success": true, "result": {"resource_id": "14418d40-de42-4fdd-84f7-3c51244c7469", "fields": [{"type": "int4", "id": "_id"}, {"type": "text", "id": "label"}, {"type": "json", "id": "geojson"}], "records": [{"_id": 1, "geojson": {"type": "Point", "coordinates": [48.856699999999996, 2.3508]}, "label": "Paris"}], "_links": {"start": "/api/3/action/datastore_search", "next": "/api/3/action/datastore_search?offset=100"}, "total": 1}}

Nevertheless, nothing is shown in CKAN :(

EDIT 2

It was a problem with my CKAN. I've tested Ifurini's solution at demo.ckan.org and it works.


回答1:


GeoJSON is just a (particular kind of) JSON, so it does not have a particular treatment as a database field.

So, you can create a resource with a GeoJSON field from a simple CSV file like this:

Name,Position
"Paris","{""type"":""Point"",""coordinates"":[2.3508,48.8567]}"

(note the double double quotes "" instead of just a single double quote ")

If you call the column "GeoJSON" (or "geojson", "gEoJsOn", etc., as capitalization is not important) the Map View will automatically use that field to mark the data in the map, instead of just letting you manually select which field to use.



来源:https://stackoverflow.com/questions/39700914/how-to-deal-with-geojson-in-ckan-datastore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!