1

I would like to take raster (say a JPG) cut it in subregions and associate each reagion to a row in a pandas dataframe, so that the image can be visualized according to some filters on the data. I see this is pretty standard using bokeh in python, but I do not find tutorial on how to prepare the raster for this. All explanation somehow use premade data such as the counties of texas example in bokeh ...

So, what should I do to my custom image to transform it into something can be used with bokeh to make an interactive map?

Rho Phi
  • 1,182
  • 1
  • 12
  • 21
  • Did you take a look at the texas exemple data and tried to understand how the example works? – Niklas Mertsch Jun 20 '19 at 13:00
  • premade? `from bokeh.sampledata.us_counties import data as counties` – Rho Phi Jun 20 '19 at 16:04
  • and just to be clear, I am looking for a tutorial, not a dive into source-code ... call me a wuss if you like : ) – Rho Phi Jun 20 '19 at 16:04
  • After calling `from bokeh.sampledata.us_counties import data as counties` you could `print(counties)` to see how the dataset is structured. It is just a dictionary containing all the data needed. Then take a look at the texas example code to see how they managed to do the job. If I understand you correctly, you more or less want to do exactly what they did, just with a different dataset. And if you don't understand it, consider taking a look at the official Bokeh Tutorial and learn some basics. – Niklas Mertsch Jun 22 '19 at 13:11
  • Guys, I may not be asking in a way that is clear enough ... I get that I need the X,Y coordinates, I want to know `how to prepare the raster` (quoting the OP). For instance in the epoch of html `image maps` there where tools like [ImageReady](https://en.wikipedia.org/wiki/Adobe_ImageReady) but they are dead since 10 years. How do I get the coordinates in a simple way (without dying in code or cut-paste) ? (I hope you see why premade data does not help here) – Rho Phi Jun 24 '19 at 14:24
  • What is your input and what exactly is the desired output? You want to convert an image file to a "raster"? What do you mean by that? [This question](https://stackoverflow.com/questions/34646270/how-do-i-work-with-images-in-bokeh-python) has multiple answers, maybe it helps you. – Niklas Mertsch Jun 24 '19 at 18:12
  • Input JPEG file, output something I can import and plot. My current solution: 1) Ploygons can be traced in a human way in Photoshop and exported as `ImageMap` HTML with [this](https://github.com/andyhawkes/ps-paths-to-imagemap), 2) then a bit of BeautifulSoup and some Numpy massage to extract the coordinates. – Rho Phi Jun 25 '19 at 16:05
  • You can use the Python library `cv2` to read an image file as a Numpy array. Then this array can be shown in bokeh by using the method `image_rgba(...)` of bokeh's `Figure` objects (see [here](https://stackoverflow.com/a/52434555/9568847)). – Niklas Mertsch Jun 25 '19 at 18:26

0 Answers0