Skip to content

re-ws.pl

ReverseEngineering WorkStation

  • Home
  • Tutorials
  • Random
  • About

Connecting WMS services to apps able to handle only OpenStreetMap format like OsmAnd Android app

Posted on July 1, 2023 by Kamil (aka. v3l0c1r4pt0r)
osm-logo

So thing is that there is a lot of interesting map data provided by state institutions (at least here in Europe), but at the same time viewer that at least Polish Geoportal provides does not provide experience good enough for everyone (that is my personal opinion) and at the same time there exist cool Android app that is able to integrate many different map providers and for some reason include neither WMS, nor WMTS support. And these two are core of services like mentioned Geoportal and seems like a standard for GIS purposes. As this seemed to me like a nice, little and easy side project, I took an opportunity. What I did is basically a wrapper that takes format used by OSM (called Slippy Map) and generates WMS-compatible request under the hood. But as you, the user, are here, you probably are not interested that much in technical details, but rather seek a solution to the problem that I had. So, here it is.

How to set this up

There are two possible approaches. First is to host the wrapper that I wrote as a daemon on your Android device. Second is to host it somewhere else (like your private server). I use Termux to have it directly on my phone. I would expect there are other ways to access Python from inside Android device, so if for some reason you are not willing to use Termux, then you are on your own in learning your Python environment. In Termux it should be as easy as typing this into terminal:

apt install python python-pip

And you end up with working Python with its usual package manager – pip. There is one more package that we need and conveniently it is also provided by Termux and it called proj. This one is backend for all computations that my adapter does. It can be installed with:

apt install proj

Once we have all the dependencies, we can clone the repo with:

git clone git@github.com:v3l0c1r4pt0r/adaptwms.git

Enter to its root dir with cd adaptwms and install all its dependencies:

pip install -r requirements.txt

And finally you are ready to start temporary django server with:

./manage.py runserver

By default it starts on port 8000, so you should now be able navigate your phone’s browser to localhost:8000 and see generator page.

For Polish Geoportal I needed one more step – reconfigure OpenSSL to handle insecure connections. For some reason it fails with SSL error otherwise. If you encounter similar problems, all you have to do is to create openssl.cnf file with this as a contents:

openssl_conf = openssl_init

[openssl_init]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
Options = UnsafeLegacyRenegotiation

And then instead of the above command for starting server, issue:

OPENSSL_CONF=openssl.cnf ./manage.py runserver

Generating URLs

Easiest method to configure things properly is to use generator supplied with adaptwms. After completing previous chapter, you should have already seen it.

First step that will make setup a lot easier to debug is to get parameters of at least one tile where you expect your target WMS service to have coverage. Just navigate your browser to OpenStreetMap, open developer tools of your browser (Ctrl-Shoft-E in Firefox), find the place on a map and check details of one of the requests:

openstreetmap-tile
Example OpenStreetMap tile with its URL

This URL is in format https://tile.openstreetmap.org/<z>/<x>/<y>.png, so now we know our values of x,y,z and can type them into adaptwms generator. The only parameter missing is URL and we can use the same method to find some tile request. Let’s say I want to adapt WMS service at URL:

https://integracja01.gugik.gov.pl/cgi-bin/KrajowaIntegracjaEwidencjiGruntow?REQUEST=GetMap&TRANSPARENT=TRUE&FORMAT=image%2Fpng&VERSION=1.3.0&LAYERS=dzialki&STYLES=&EXCEPTIONS=xml&amp;BBOX=683295.0215900433%2C186007.86762340198%2C683779.2100584202%2C187023.86965540604&CRS=EPSG%3A2180&WIDTH=1920&HEIGHT=915&SERVICE=WMS

There are few important values that needs to be adjusted here. Most obvious is BBOX argument. This is the one that will be generated by adapter and in order to allow it to do so, it needs to be replaced with {bbox}. Next is CRS, which in this case is set to EPSG:2180, which is not supported by adaptwms and needs to be switched to EPSG:3857. And last two values are WIDTH and HEIGHT. Slippy Map format allows tiles to be only 256×256 pixels and we must set it here. So the final URL will look like this:

https://integracja01.gugik.gov.pl/cgi-bin/KrajowaIntegracjaEwidencjiGruntow?REQUEST=GetMap&TRANSPARENT=TRUE&FORMAT=image%2Fpng&VERSION=1.3.0&LAYERS=dzialki&STYLES=&EXCEPTIONS=xml&amp;BBOX={bbox}&CRS=EPSG%3A3857&WIDTH=256&HEIGHT=256&SERVICE=WMS

One last step is to choose adapter mode of operation. Test mode is just for testing and will simply show you generated URL. You can use it at first to validate your input. For OsmAnd we will need to use fetch mode. It fetches image from URL and serve as a proxy. There is also redirect mode, but OsmAnd version that I have does not support redirections and will not show anything, when it gets 302 error redirect. For other programs it is better idea to access tile servers directly.

So now you can click submit button and in fetch, or test mode will see proper URL in your browser. Then you can use it in OsmAnd.

Usage with OsmAnd

Once you have your URL generated, open OsmAnd and from the three-dot menu tap following options:

Configure map -> Map source... -> Add

You should have landed on ‘Add online source’ window, where you can paste URL, having x. y and z values that you used for testing replaced with {0}, {1} and {2} respectively:

OsmAnd-add-source
Filled Add online source window

Worth noting is that for many services only small set of zoom levels will be supported and its better to start with range like above (17-19) and then maybe add one level at a time instead of trying full range and generate whole bunch of invalid requests that will be rejected by WMS service. Also ensure that you did not switch mercator to the other option. Now you can click save, switch map source to your new service and check if it works.

In case of problems, you can try reading Django logs. By default it prints every request with error code server returned to console, so you can try checking it, or even navigating your browser to it to see what happens.

And that’s all I wanted to show. Happy GIS hacking!

Posted in TutorialsTagged GIS, hacking, WMS

Post navigation

Pinout of laser driver for CPRI SFP+ module – GN1157
How to recover torrent from rtorrent meta files

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tags

Android assembly busybox C CAN can-hacking cc-factory cmake compiler docker Dreamspark electronics English gcc hacking hardware JavaCard JCOP kernel KiCAD library Linux PC PCB pinout PKI polski programming Python radio Raspberry Pi Reverse Engineering RTL-SDR SDC SDM SDR smart card software tor tty UART UEFi Windows X.509 Xperia Pro

Recent Posts

  • PHP build for use bundled in Android applications
  • Running graphical apps inside Docker containers
  • Plugin architecture demo for Python projects
  • Authorizing adb connections from Android command line (and making other service calls from cli)
  • How to recover torrent from rtorrent meta files

Recent Comments

  • pomi on Playing with GF-07 GPS device
  • pomi on Playing with GF-07 GPS device
  • Hamdy Abumgata on Playing with GF-07 GPS device
  • Mousum Gogoi on Playing with GF-07 GPS device
  • Eason on Sniffing USB traffic with DSLogic logic analyzer into pcap file

Categories

  • News
  • Random
  • Reversing LKV373A
  • Setting up new v3 Hidden Service with ultimate security
  • Tutorials
  • Uncategorized
  • Understanding JCOP

Links

  • Me @ github
  • LKV373A Wiki
  • DevTomek

Archives

  • December 2024
  • November 2024
  • May 2024
  • July 2023
  • October 2022
  • August 2022
  • July 2021
  • June 2021
  • May 2021
  • December 2020
  • November 2020
  • October 2020
  • August 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • February 2019
  • November 2018
  • October 2018
  • June 2018
  • May 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • September 2017

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Proudly powered by WordPress | Theme: micro, developed by DevriX.