GithubHelp home page GithubHelp logo

lmikolajczak / wms-tiles-downloader Goto Github PK

View Code? Open in Web Editor NEW
72.0 4.0 8.0 2.25 MB

CLI for downloading map tiles from WMS server with given bbox and zoom.

License: MIT License

Go 98.98% Dockerfile 1.02%
gis wms tiles spherical-coordinates mercator golang

wms-tiles-downloader's Introduction

๐ŸŒ wms-tiles-downloader

Command line application for downloading map tiles from given WMS server.

Installation

go install github.com/lmikolajczak/[email protected]

Go will automatically install it in your $GOPATH/bin directory which should be in your $PATH.

Command Line Usage

Download tiles from WMS server based on provided options.

Usage:
    wms-tiles-downloader get [flags]

Flags:
        --auth        string         Basic HTTP auth credentials separated by semicolon (username:password)
    -b, --bbox        float64Slice   Comma-separated list of bbox coords (default [])
        --concurrency int            Limit of concurrent requests to the WMS server (default 16)
        --format      string         Tile format (default "image/png")
        --height      int            Tile height (default 256)
    -h, --help                       Help for get
    -l, --layer       string         Layer name
    -o, --output      string         Output directory for downloaded tiles
        --params      stringToString Custom query string params (default [])
    -s, --style       string         Layer style
    -t, --timeout     int            HTTP request timeout (in milliseconds) (default 10000)
    -u, --url         string         WMS server url
        --version     string         WMS server version (default "1.3.0")
        --width       int            Tile width (default 256)
    -z, --zoom        ints           Comma-separated list of zooms

Examples

demo

Command above will produce following output - tree of folders with files in Z/X/Y format:

root@df62f3f34fef:/tiles# tree
.
|-- 10
|   |-- 524
|   |   |-- 336.png
|   |   `-- 337.png
|   |-- 525
|   |   |-- 336.png
|   |   `-- 337.png
|   `-- 526
|       |-- 336.png
|       `-- 337.png
|-- 11
|   |-- 1049
|   |   |-- 672.png
|   |   |-- 673.png
|   |   `-- 674.png
|   |-- 1050
|   |   |-- 672.png
|   |   |-- 673.png
|   |   `-- 674.png
|   |-- 1051
|   |   |-- 672.png
|   |   |-- 673.png
|   |   `-- 674.png
|   `-- 1052
|       |-- 672.png
|       |-- 673.png
|       `-- 674.png
...more directories...

Alternative - use as a library (pkg.go.dev)

go get github.com/lmikolajczak/[email protected]

Disclaimer

Please keep in mind terms and conditions of any tile provider (WMS server) from which you plan to download tiles.

wms-tiles-downloader's People

Contributors

dbussert avatar lmikolajczak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wms-tiles-downloader's Issues

How to download Tiles from x/y/z Tile URL?

I'm trying to download map tiles from the following endpoint https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile but I'm getting the following error
Screen Shot 2023-02-27 at 4 52 05 PM

The full URL with x/y/z is as follows
https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}

The command I'm trying to run
./wms-tiles-downloader get --url https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/x/y/z --layer OSM_WMS --zoom 3 --bbox -90,-200,90,200

Set basic HTTP authentification

First of all, thanks for this simple and great tool. I need to access a WMS server that has basic HTTP authentication. I had to add an extra line in the request function from wms/client.go to make it work:

func (c *Client) request(ctx context.Context, method string, url string, timeout int) ([]byte, error) {
	ctx, cancel := context.WithTimeout(ctx, time.Duration(timeout)*time.Millisecond)
	defer cancel()

	req, err := http.NewRequestWithContext(ctx, method, url, nil)
	req.SetBasicAuth("username", "password") // <-- what I needed to add
	if err != nil {
		return nil, err
	}

	res, err := c.httpClient.Do(req)
	if err != nil {
		return nil, err
	}

	if res.StatusCode >= 400 || res.StatusCode < 200 {
		return nil, fmt.Errorf("error making HTTP request (%v): %s", res.StatusCode, http.StatusText(res.StatusCode))
	}

	resBody, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return nil, err
	}

	return resBody, nil
}

It would be nice to have an optional argument passing a username and password for this case, unless you see any better way of doing it? I can propose a PR for this. ๐Ÿ˜„

Install Issue

I tried to install on my Mac using go get -u github.com/Luqqk/wms-tiles-downloader... and got this error package github.com/Luqqk/wms-tiles-downloader...: invalid github.com/ import path "github.com/Luqqk"

However go get -u github.com/Luqqk/wms-tiles-downloader/... worked. Should the readme be updated or is this something platform specific?

Transparent color in tiles

Hi and nice job!
Only one thing that would be good would be to preserve the transparent color for png files. I am currently pulling png files from a geoserver instance and the transparent color is white..

Allow to specify output path

Hello. Thanks for this awesome tool.

I was wondering if there is a way to specify a custom output path where the tiles will be saved and not where the command is being invoked from ?

Thanks!

Authenticate on mapserver

Hi, is there a way to authenticate on the mapserver? My WMS needs authentication with token generation and using the token to perform requests on the mapserver. I don't see how to do it with the script right now.
Thank you.

Can't install wms, does not contain package

I tried to install in my debian 10

# go install github.com/lmikolajczak/wms-tiles-downloader@latest
go: downloading github.com/lmikolajczak/wms-tiles-downloader v2.0.0+incompatible
go: github.com/lmikolajczak/wms-tiles-downloader@latest: module github.com/lmikolajczak/wms-tiles-downloader@latest found (v2.0.0+incompatible), but does not contain package github.com/lmikolajczak/wms-tiles-downloader

debian 10, go version: 1.18.5

Refactoring

This project was created as a proof of concept and I neglected its maintenance for a long time. I plan to refactor it to match current Go's standards and make it more configurable and flexible. Some basic things to do at the very beginning:

  1. Refactor project structure
  2. Start using go modules
  3. Use context to provide granular control over each issued request and support client defined request timeouts
  4. Use cobra package to provide more robust CLI (still to consider if that's suitable solution)
  5. Handle other issues opened by people that tried to use this project
  6. ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.