使用 C# 在维基百科中查找 link 个包含坐标的地方
Find link of the place which contain Coordinates in Wikipedia using C#
对于我的项目,我需要列出城市中许多有趣的地方。比如在柏林的维基百科页面https://en.wikipedia.org/wiki/Berlin there are lots of interesting places link such as Berlin State Opera linked https://en.wikipedia.org/wiki/Berlin_State_Opera, Berlin Zoological Garden , linked https://en.wikipedia.org/wiki/Berlin_Zoological_Garden等等。所有这个地方都有坐标在右上角,像这样 Coordinates 52°30′30″N 13°20′15″ECoordinates: 52°30′30″N 13°20′15″E.所以我想做的是,我只想从包含坐标信息的维基百科文章中获取 link 。好吧,我已经阅读了一些文章,但有任何 api 来提取包含地理坐标信息的 link。所以我想知道如何获取所有包含地理信息的地方link。
您可以使用API获取所有链接页面,为每个页面获取坐标。然后,您可以通过忽略所有没有任何坐标的链接页面来处理它。
查询将如下所示:
请注意,链接页面包括与柏林根本不相关的页面,例如亚琛。
更好的方法可能是搜索坐标靠近柏林某个点的页面。
维基百科有一个很好的 Geo Search API 可以让您搜索附近的页面:
{
"batchcomplete": "",
"query": {
"geosearch": [
...
{
"pageid": 391156,
"ns": 0,
"title": "Berlin State Opera",
"lat": 52.516666666667,
"lon": 13.395,
"dist": 789.4,
"primary": "",
"type": "landmark",
"name": "",
"dim": 1000,
"country": "DE",
"region": "BE"
},
...
{
"pageid": 1005900,
"ns": 0,
"title": "Berlin Zoological Garden",
"lat": 52.508333333333,
"lon": 13.3375,
"dist": 3237.1,
"primary": "",
"type": "landmark",
"name": "",
"dim": 500,
"country": "DE",
"region": "BE"
},
...
您可以使用 gspage
来使用任何维基百科文章的标题进行搜索 with geographic coordinates。您会看到一些带有地理标记的历史事件、地标和其他功能,因此您可以添加 gsprop=type
添加属性以帮助您过滤您不感兴趣的文章。
一些注意事项:
API(当前)只能return最多 500 个位于您搜索点半径 10,000 米范围内的项目。如果您没有得到想要的所有内容,您可能想尝试一系列更窄的搜索或使用小边界框(使用 gsbbox
参数)。
维基百科的每种语言都有自己的 API 端点。您可以尝试 same query on the German language Wikipedia,结果可能会略有不同。
维基数据拥有广泛的跨语言数据,SPARQL interface, but it doesn't support geo coordinate searches (yet). Someday, you may be able to use Wikidata to find items based on their location (P625)。
对于我的项目,我需要列出城市中许多有趣的地方。比如在柏林的维基百科页面https://en.wikipedia.org/wiki/Berlin there are lots of interesting places link such as Berlin State Opera linked https://en.wikipedia.org/wiki/Berlin_State_Opera, Berlin Zoological Garden , linked https://en.wikipedia.org/wiki/Berlin_Zoological_Garden等等。所有这个地方都有坐标在右上角,像这样 Coordinates 52°30′30″N 13°20′15″ECoordinates: 52°30′30″N 13°20′15″E.所以我想做的是,我只想从包含坐标信息的维基百科文章中获取 link 。好吧,我已经阅读了一些文章,但有任何 api 来提取包含地理坐标信息的 link。所以我想知道如何获取所有包含地理信息的地方link。
您可以使用API获取所有链接页面,为每个页面获取坐标。然后,您可以通过忽略所有没有任何坐标的链接页面来处理它。
查询将如下所示:
请注意,链接页面包括与柏林根本不相关的页面,例如亚琛。
更好的方法可能是搜索坐标靠近柏林某个点的页面。
维基百科有一个很好的 Geo Search API 可以让您搜索附近的页面:
{
"batchcomplete": "",
"query": {
"geosearch": [
...
{
"pageid": 391156,
"ns": 0,
"title": "Berlin State Opera",
"lat": 52.516666666667,
"lon": 13.395,
"dist": 789.4,
"primary": "",
"type": "landmark",
"name": "",
"dim": 1000,
"country": "DE",
"region": "BE"
},
...
{
"pageid": 1005900,
"ns": 0,
"title": "Berlin Zoological Garden",
"lat": 52.508333333333,
"lon": 13.3375,
"dist": 3237.1,
"primary": "",
"type": "landmark",
"name": "",
"dim": 500,
"country": "DE",
"region": "BE"
},
...
您可以使用 gspage
来使用任何维基百科文章的标题进行搜索 with geographic coordinates。您会看到一些带有地理标记的历史事件、地标和其他功能,因此您可以添加 gsprop=type
添加属性以帮助您过滤您不感兴趣的文章。
一些注意事项:
API(当前)只能return最多 500 个位于您搜索点半径 10,000 米范围内的项目。如果您没有得到想要的所有内容,您可能想尝试一系列更窄的搜索或使用小边界框(使用
gsbbox
参数)。维基百科的每种语言都有自己的 API 端点。您可以尝试 same query on the German language Wikipedia,结果可能会略有不同。
维基数据拥有广泛的跨语言数据,SPARQL interface, but it doesn't support geo coordinate searches (yet). Someday, you may be able to use Wikidata to find items based on their location (P625)。