本文介绍了Wikimedia Commons API搜索图片由(纬度,经度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从维基共享资源中检索图像以显示在地图上。这意味着给定一对(纬度,经度),我想找到围绕这一点的图片。
经过一天的搜索和尝试后,我仍然不知道这是否可行。特别是我已阅读,和。



所以我的问题是:是否可以用一对地理坐标检索图片?如果是的话,怎么样?

解决方案

是的,那是可能的。在Commons上,安装了。使用 action = query& list = geosearch& gscoord = lat | lon & gsradius = & gsnamespace = 6& gsprimary = all p 摘录自API文档

  gscoord  - 要搜索的坐标:由管道分隔的两个浮点值(|)
gspage - 要搜索的页面标题
gsradius - 以米为单位的搜索半径
该参数是必需的
该值必须介于10和10000之间
gsmaxdim - 限制搜索到对象no以米为单位
gslimit - 返回的最大页数
允许不超过500(机器人为5000)
默认值:10
gsnamespace - 名称空间搜索
值(与' |'):0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,100,101, 107,460,
461,490,491,1198,1199,828,829
最大值为50(对于机器人为500)
默认值:0
gsprop - 额外的坐标属性返回
值(与'|'分开):类型,名称,暗淡,国家,地区,地球仪
默认值:globe

默认情况下,MediaWiki中的文件名称空间为NS 6。


$ b

示例:


结果:

  {
query:{
pages:{
28971703:{
pageid :28971703,
ns:6,
title:File:RiveuferHerbst.JPG,
imagerepository:local,
imageinfo: [
{
thumburl:https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/RiveuferHerbst.JPG/200px-RiveuferHerbst.JPG,
thumbwidth:200,
thumbheight:150,
url:https://upload.wikimedia.org/wikipedia/commons/b/b2/RiveuferHerbst.JPG ,
descriptionurl:https://commons.wikimedia.org/wiki/File:RiveuferHerbst.JPG
}
]
}
}
}
}


I would like to retrieve images from Wikimedia Commons to display on a map. This means that given a pair (latitude, longitude) I would like to find pictures around this point.After a day of searching and trying I have still no idea whether this is possible or not. In particular I have read MediaWiki API Main page, the API reference and some examples.

So my question is: is it possible to retrieve pictures with a pair of geographical coordinates? If yes, how?

解决方案

Yeah, that's possible. On Commons, Extension:GeoData is installed. Use action=query&list=geosearch&gscoord=lat|lon&gsradius=meters&gsnamespace=6&gsprimary=all

Excerpt from the API documentation

  gscoord             - Coordinate around which to search: two floating-point values separated by pipe (|)
  gspage              - Title of page around which to search
  gsradius            - Search radius in meters
                        This parameter is required
                        The value must be between 10 and 10000
  gsmaxdim            - Restrict search to objects no larger than this, in meters
  gslimit             - Maximum number of pages to return
                        No more than 500 (5000 for bots) allowed
                        Default: 10
  gsnamespace         - Namespace(s) to search
                        Values (separate with '|'): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103, 104, 105, 106, 107, 460,
                            461, 490, 491, 1198, 1199, 828, 829
                        Maximum number of values 50 (500 for bots)
                        Default: 0
  gsprop              - What additional coordinate properties to return
                        Values (separate with '|'): type, name, dim, country, region, globe
                        Default: globe

File namespace is NS 6 in MediaWiki by default.

Example:https://commons.wikimedia.org/w/api.php?format=jsonfm&action=query&list=geosearch&gsprimary=all&gsnamespace=6&gsradius=500&gscoord=51.5|11.95

Result:

{
    "query": {
        "geosearch": [
            {
                "pageid": 28971703,
                "ns": 6,
                "title": "File:RiveuferHerbst.JPG",
                "lat": 51.501042,
                "lon": 11.948794,
                "dist": 142.8
            },
            {
                "pageid": 32760810,
                "ns": 6,
                "title": "File:Pei\u00dfnitznordspitze4.JPG",
                "lat": 51.499675,
                "lon": 11.947992,
                "dist": 143.6
            }
        ]
    }
}

If you additionally want to optain thumbnail urls with your API request, use list=geosearch as a generator:

Example:https://commons.wikimedia.org/w/api.php?format=jsonfm&action=query&generator=geosearch&ggsprimary=all&ggsnamespace=6&ggsradius=500&ggscoord=51.5|11.95&ggslimit=1&prop=imageinfo&iilimit=1&iiprop=url&iiurlwidth=200&iiurlheight=200

Result:

{
    "query": {
        "pages": {
            "28971703": {
                "pageid": 28971703,
                "ns": 6,
                "title": "File:RiveuferHerbst.JPG",
                "imagerepository": "local",
                "imageinfo": [
                    {
                        "thumburl": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/RiveuferHerbst.JPG/200px-RiveuferHerbst.JPG",
                        "thumbwidth": 200,
                        "thumbheight": 150,
                        "url": "https://upload.wikimedia.org/wikipedia/commons/b/b2/RiveuferHerbst.JPG",
                        "descriptionurl": "https://commons.wikimedia.org/wiki/File:RiveuferHerbst.JPG"
                    }
                ]
            }
        }
    }
}

这篇关于Wikimedia Commons API搜索图片由(纬度,经度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:13