7

I have a coordinate, and I want to know what Commons categories are nearby.

For instance, for 40.7576,-73.9857 I would get Category:Times Square and probably Category:Broadway and a few others nearby.

Is there an API that gives this?

If not, is there a way to get the same via several APIs calls? 50% of false positives is OK.

Note: Once again, my question is about Wikimedia Commons categories.

5

There is a more direct way to get this from Wikidata, if you want an API. That's the API used by AutoList. Returns JSON or JSONP.

Example query to retrieve all Commons categories within 0.1 kilometer from 40.7576,-73.9857:

  • http://wdq.wmflabs.org/api?q=claim[373]%20and%20around[625,40.7576,-73.9857,0.1]&props=373
  • Live

Explanation of the request:

  • 373 is the property id of the Commons category item
  • around takes as arguments: PROPERTY,LATITUDE,LONGITUDE,RADIUS
  • 625 is the property id of the coordinate location item
  • The &props=373 part can be removed if only identifiers are needed

Response:

{
    "status": {
        "error": "OK",
        "items": 8,
        "querytime": "1333ms",
        "parsed_query": "(CLAIM[373] AND AROUND[625,40.7576,-73.9857,0.1])"
    },
    "items": [11259, 626926, 659652, 827638, 1756846, 1973105, 3062716, 3363532],
    "props": {
        "373": [
            [1973105, "string", "2010 Times Square car bombing attempt"],
            [827638, "string", "Bertelsmann Building"],
            [1756846, "string", "Lyceum Theatre (Broadway)"],
            [3062716, "string", "Minskoff Theatre"],
            [659652, "string", "One Astor Plaza"],
            [3363532, "string", "Paramount Building (New York City)"],
            [11259, "string", "Times Square"],
            [626926, "string", "V-J Day in Times Square (Alfred Eisenstaedt)"]
        ]
    }
}

The server response is rather slow, and seems to increase with the number of categories returned.

See the full documentation.

  • Your example return mostly articles, whereas my question asks for Wikimedia Commons categories. By the way, Commons categories are different from Wikipedia categories, they follow different hierarchy/granularity rules. – Nicolas Raoul Oct 5 '15 at 3:21
  • @NicolasRaoul Those are categories - scroll down to the "props":{"373": section, and all the text after that point is category strings. Q655136 is a good demonstration, as the returned P373 label is appended with (Manhattan) while the Wikidata label doesn't have it. – Andrew Oct 5 '15 at 7:40
  • (This is a much more efficient approach than my answer, which generates a human-readable list rather than an API-readable one.) – Andrew Oct 5 '15 at 7:42
  • @Andrew: What directly follows "props":{"373": is 1859121, 209017, 284013, none of which are Commons categories, they are actually just Wikipedia articles. The text "1 Hanover Square"/etc are the same Wikipedia articles. – Nicolas Raoul Oct 5 '15 at 8:11
  • 1
    @Andrew: I somehow expected a "commons" section and did not think to look for a property, now I understand, thanks! – Nicolas Raoul Oct 5 '15 at 8:49
4

Wikidata can do it!

Using autolist, run the query claim[373] and around[625,40.7576,-73.9857,50] [link].

This will give you all items with a commons category property (P373) and a location (P625) up to 50km from 40.7576,-73.9857.

At the time of writing, this is 1900 entries. Dropping it to 10km is 1146, and 1km is 141.

(This won't get subcategories of these Commons categories unless they also have properties with geocoordinates, but it's certainly a start.)

To get a list of all commons categories from this set, ask it to generate a PagePile listing, then from the next page select item properties, and then property 373 and 625 when it loads the TABernacle tool. This will give you a nice little downloadable text file with item, commons category, & coordinates. For the 1km set (141 places), this will give you the following results.

1

There does not seem to be a Wikipedia API. It looks like geonames.org has some of this functionality though.

For example, take a look at the results of this page: http://www.geonames.org/maps/google_40.7576_-73.9857.html

I took a look at the API requests on that page and it called the following:

http://www.geonames.org/servlet/geonames?&srv=2&lat=40.7576&lng=-73.9857&north=40.762963512194894&east=-73.96087347335816&south=40.752236055031354&west=-74.01052652664185&maxRows=100&type=json&q=&P=1&A=1&V=1&T=1&L=1&R=1&S=1&H=1&U=1

That being said, it looks like this Wikipedia Search with a Bounding Box geonames.org API at http://www.geonames.org/export/wikipedia-webservice.html#wikipediaBoundingBox is what you would want though you may need to programatically filter out anything not a category.

Hope this helps.

  • It seems to return only articles, no categories... Also, I am looking for Wikimedia Commons categories. Commons categories are different from Wikipedia categories, they follow different hierarchy/granularity rules. – Nicolas Raoul Oct 2 '15 at 4:31
  • @NicolasRaoul - sorry, didnt understand that nuance. My bad :) – Mark Silverberg Oct 2 '15 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.