OpenStreetMap

osmimgur : See tagged imgur images on OSM

Posted by rtnf on 19 January 2023 in English. Last updated on 20 January 2023.

First, download all OSM objects that contain the substring “imgur” inside the “image:” tag. I use Overpass API on JOSM.

[out:xml][timeout:90];
(
  nwr[~"image"~"https://i.imgur.*"];
);
(._;>;);
out meta;

Then, export the downloaded OSM objects as GeoJSON file for further processing.

Next, for the sake of simplicity, filter everything except OSM point node. Also trim all of the OSM tag except the image to minimize the GeoJSON filesize.

import json
f = open('imgur.json',encoding='utf-8')
data = json.load(f)
allobj = data['features']
newdata = {}
newdata['type'] = "FeatureCollection"
newdata['generator'] = "rtnf"
newdata['features'] = []

for i in allobj:
	if i['geometry']['type'] == "Point":
		prop = i['properties']
		for j in prop:
			if "image" in j:
				#print(prop[j])
				newy = {}
				newy['type'] = "Feature"
				newy['properties'] = {}
				newy['properties']['image'] = prop[j]
				newy['geometry'] = i['geometry']
				newdata['features'].append(newy)
print(json.dumps(newdata))

Finally, show this preprocessed geojson file by using Leaflet frontend. Since the dataset is quite massive, use MarkerCluster plugin. I tried it before without this plugin, and my browser was crashed.

var map = L.map('mapid',{ preferCanvas:true, zoomControl: false }).setView({lat: -6.2, lng:  107.0},1)

// Basemap
L.tileLayer(
  'https://tile.tracestrack.com/_/{z}/{x}/{y}.png', {
    maxZoom: 18,
    attribution: 'Data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>
  }).addTo(map);

// Marker cluster
var markers = L.markerClusterGroup();
markers.addLayer(L.geoJSON(a, {
    onEachFeature: onEachFeature
}));
map.addLayer(markers)

// Pop-up on click
function onEachFeature(feature, layer) {
    if (feature.properties && feature.properties.image) {
        layer.bindPopup("<img src='"+feature.properties.image+"'><br><a target='_blank' href='"+feature.properties.image+"'>Image license</a>");
    }
}

Discussion

Comment from Pieter Vander Vennet on 19 January 2023 at 16:40

Really cool!

A fun observation: all images reported are from europe. This is certainly a bug, here is an example of a point which has an imgur image.

The overpass-script is:

``` [out:json][timeout:25]; // gather results ( // query part for: “image~/https:\/\/i.imgur.[…]” nwr“image”~”https://i.imgur.*”;

); // print results out body; >; out skel qt; ```

The only two non-european images (japan) are false-positives (I’ve removed the ‘redirect’ in OSM by now).

AT last, the link to the license is slightly incorrect and gives the image, not the imgur page. An image link such as https://i.imgur.com/ABC.jpg should be transformed into https://imgur.com/ABC (thus without i. at the start and without .jpg at the end).

But still, the end result is very interesting! I’m honoured that other people are using the results of MapComplete to make their own stuff with it :) That’s very motivating for me.

Comment from rtnf on 20 January 2023 at 03:00

Thank you for the overpass-script. Here’s the update :

Log in to leave a comment