Search code examples
c#hyperlinkwikipediawikipedia-apimediawiki-api

Find link of the place which contain Coordinates in Wikipedia using C#


For my project, I need to make a list of many interesting places within City. Such as in Berlin wikipedia page 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 and so on. And all of this place hasCoordinates on the upperright corner like this Coordinates 52°30′30″N 13°20′15″ECoordinates: 52°30′30″N 13°20′15″E. So what I want to do, I want to get only the link from Wikipedia article which contain the co-ordinates information. Well I have read some articles but have got any api to extract the link which contain the geocordinate information. So I would like what is the way to get all the places link which contain Geoinformation.


Solution

  • Wikipedia has a nice Geo Search API that will let you search for nearby pages:

    https://en.wikipedia.org/w/api.php?action=query&list=geosearch&gsradius=10000&gspage=Berlin&gslimit=500&gsprop=type|name|dim|country|region|globe&format=json

    {
    "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"
            },
            ...
    

    You can use gspage to search using the title of any Wikipedia article with geographic coordinates. You'll see some geotagged historical events, landmarks, and other features, so you can add gsprop=type to add properties to help you filter articles you aren't interested in.

    A few notes:

    • The API can (currently) only return a maximum of 500 items that are within a 10,000 meter radius of the point you are searching. You may want to try a series of more narrow searches or using a small bounding box (with the gsbbox parameter) if you don't get everything you want.

    • Each language of Wikipedia has its own API endpoint. You can try the same query on the German language Wikipedia and you may see slightly different results.

    • Wikidata has extensive data across languages with a 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).