timwaters / mapwarper

free open source public map georeferencer, georectifier and warper
http://mapwarper.net
MIT License
196 stars 80 forks source link

Rectify: Thin Plate Spline #223

Closed talk-show-host closed 1 year ago

talk-show-host commented 1 year ago

I have MapWarper running locally using Vagrant.

However when warping maps, choosing the Thin Plate Spline method of rectification causes a fuzzy map. All other methods work, and all the resampling options too, so it seems that TPS is causing some issue. I uploaded the same map to the mapwarper site, placed just three points, used the same advanced settings and the map appeared fine. My local map has over 75 points on it.

Am I missing something stupid (probably) and what difference does using 3rd order poly instead make? As far as I can tell, the control points aren't placed on top of one another quite as precisely.

Local MapWarper MapWarper Website

Edit: I see that there is mention of a gdal rasterize bug of some sort. Is there a specific version of gdal I should be running? Vagrant seemed to install the most recent, which I assume is OK, as when I went to update gdal in the VM it said its running the latest version already.

Edit 2: I had a look at the command being run by MapWarper and saw gdalwarp being called when I clicked 'Warp Image' on the web page. After some tricky stuff capturing the VRT file, while it had data in it and extracting the source files too, I ran gdal_translate on the VRT file and created a TIFF from that. I then ran gdalwarp on that TIFF and got a warped image, in full quality and with no issues it seems. The TIFF created in the VM is completely messed up, which is also what I saw when viewed the image. The third image is what is created in the VM (really long, and the actual map is a tiny fragment at the top, hence the burryness when displayed) and the fourth is what I created by doing the steps above (ignore the sharpness, I had to reduce the files to upload them). When I replaced the TIFF in the VM with the one I created that fixed the issue so there is something happening when gdalwarp is run in the WM. As I said before, I tried updating gdal in the VM but it said it was on the latest version. I should mention that I'm also running the most recent version on my Mac (MacOS 11.7)

38_bad 38_extracted

Anyway, theres something strange happening with gdalwarp when it runs in the VM, and I'm close to being out of ideas. I'm not a professional programmer, I just really wanted this to work!

timwaters commented 1 year ago

Thanks for the detailed issue

Thin Plate Spline does lead to some weird effects.

Thin Plate Spline is kind of different, it likes it if there are a few points and spread across the image reasonably well distributed. It treats each point as "fixed" whereas polynomial describes the fit in terms of an equation. So you could try with less points, and make sure there are some points near the corners.

for gdal rasterize, it depends on the version of the OS that vagrant installs - Sorry to say that I've not kept up to date the vagrant installation scripts, and they might not properly work anymore. https://github.com/timwaters/mapwarper/blob/master/ubuntu18_installnotes and https://github.com/timwaters/mapwarper/blob/master/ubuntu16_installnotes might additionally give some pointers.

Also, look in log/development.log for any errors when you warp the files. It should log the standard output and the command used too.

For the future I hope to move to docker.

timwaters commented 1 year ago

If you just want to georectify images locally, I would recommend QGIS which has good georeferencing support. You can also save a bit of time by downloading the control points you created in the mapwarper (link under the control points section in the control panel of the warping page) e.g. https://mapwarper.net/maps/6949/gcps.csv and importing it into QGIS

talk-show-host commented 1 year ago

Thanks for the reply anyway, and the amazing site btw. Vagrant installed Ubuntu 16 (so says VirtualBox as the VM appeared there too). I might look into all that, I'll see how my night goes!

TBH, I only really wanted to run a local version so I could store several maps and not busy your server. I'll be using them for a website I'm in the process of creating, and would like to be able to touch up the maps when finalising them, and create basic versions as proof of concept, but didn't want you to have to store them however long.

Thanks again