Skip to content

Fix handling of apikey keyword for services with variants#12

Merged
rafaqz merged 4 commits intoJuliaGeo:mainfrom
mathieu17g:Fix_GeoPortail_apikey_handling
May 29, 2023
Merged

Fix handling of apikey keyword for services with variants#12
rafaqz merged 4 commits intoJuliaGeo:mainfrom
mathieu17g:Fix_GeoPortail_apikey_handling

Conversation

@mathieu17g
Copy link
Copy Markdown
Contributor

@mathieu17g mathieu17g commented May 27, 2023

I had an issue with GeoPortailFrance not taking in account the apikey keyword.

Now it works. I had to convert the options JSON3.object to Dict via copy

I added a test on the URL returned by geturl

@mathieu17g mathieu17g marked this pull request as ready for review May 27, 2023 17:49
Copy link
Copy Markdown
Member

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

keyword = _access(first(values(v)))
keyword_docs = _keyword_docs(keyword, name)
variants = keys(v)
keyword_expr = isnothing(keyword) ? nothing : :(options[$(QuoteNode(keyword))] = $(Symbol(lowercase(string(keyword)))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change doing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In options, it modifies the keyword corresponding value of the variant, instead of adding a new variant named keyword

If I add the two pieces of code below in both main and the CR:

...
            contents = quote
                provider_name = $name
                options = copy($v)
                variant in keys(options) || throw(ArgumentError("$provider_name variant must be from $(keys(options)), got $variant"))
                $keyword_expr
                # Showing variants and selected variant value
                @show keys(options)
                println("\noptions = ")
                JSON3.pretty(options[variant])
                println("\n")
                #####
                Provider(options[variant][:url], options[variant])
            end
...
            else
                clean_keyword = Symbol(lowercase(string(keyword))) 
                # Showing keyword_expr
                name == :GeoportailFrance && (@show keyword_expr; println())
                #####
                @eval begin
                    @doc $docstring
                    function $name(variant::Symbol; $clean_keyword)
                        $contents
                    end
                end
                @eval $name(; $clean_keyword) = $name($(QuoteNode(first(variants))); $clean_keyword=$clean_keyword)
            end
...

In main, you get a new variant :apikey, and the "apikey" is not modified and stays set to a default unusable value "choisirgeoportail":

julia> geturl(TileProviders.GeoportailFrance(:plan; apikey="cartes"), 1, 2, 3)
keyword_expr = :(options[:apikey] = apikey)

keys(options) = [:parcels, :plan, :apikey, :orthos]

options = 
{
    "url": "https://wxs.ign.fr/{apikey}/geoportail/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE={style}&TILEMATRIXSET=PM&FORMAT={format}&LAYER={variant}&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}",
    "html_attribution": "<a target=\"_blank\" href=\"https://www.geoportail.gouv.fr/\">Geoportail France</a>",
    "attribution": "Geoportail France",
    "bounds": [
        [
            -75,
            -180
        ],
        [
            81,
            180
        ]
    ],
    "min_zoom": 2,
    "max_zoom": 18,
    "apikey": "choisirgeoportail",
    "format": "image/png",
    "style": "normal",
    "variant": "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2",
    "name": "GeoportailFrance.plan"
}

"https://wxs.ign.fr/choisirgeoportail/geoportail/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE=normal&TILEMATRIXSET=PM&FORMAT=image/png&LAYER=GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2&TILEMATRIX=3&TILEROW=2&TILECOL=1"

And with the CR, you get no new variant, and the "apikey" is set to the apikey arg:

ulia> geturl(TileProviders.GeoportailFrance(:plan; apikey="cartes"), 1, 2, 3)
keyword_expr = :((options[variant])[:apikey] = apikey)

keys(options) = [:parcels, :plan, :orthos]

options = 
{
    "min_zoom": 2,
    "html_attribution": "<a target=\"_blank\" href=\"https://www.geoportail.gouv.fr/\">Geoportail France</a>",
    "attribution": "Geoportail France",
    "variant": "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2",
    "max_zoom": 18,
    "url": "https://wxs.ign.fr/{apikey}/geoportail/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE={style}&TILEMATRIXSET=PM&FORMAT={format}&LAYER={variant}&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}",
    "name": "GeoportailFrance.plan",
    "format": "image/png",
    "apikey": "cartes",
    "bounds": [
        [
            -75,
            -180
        ],
        [
            81,
            180
        ]
    ],
    "style": "normal"
}

"https://wxs.ign.fr/cartes/geoportail/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE=normal&TILEMATRIXSET=PM&FORMAT=image/png&LAYER=GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2&TILEMATRIX=3&TILEROW=2&TILECOL=1"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh ok seems I messes up where the key is set.

I dont think there are many people using the providers that need api keys, I didn't test most of them because I dont have access

.gitignore Outdated
*.jl.mem
/Manifest.toml
/docs/build/
.vscode/settings.json
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha sorry I didnt mean to be so blunt

@rafaqz
Copy link
Copy Markdown
Member

rafaqz commented May 28, 2023

Ok the question now is what to do about those Juilia 1.6 test failures.

@mathieu17g
Copy link
Copy Markdown
Contributor Author

Ok the question now is what to do about those Juilia 1.6 test failures.

I do not have Linux, but macOS on Intel. I will run the tests locally with Julia 1.6 to see if I can reproduce the error

@rafaqz
Copy link
Copy Markdown
Member

rafaqz commented May 28, 2023

Maybe we used new syntax for replace that 1.6 doesnt have...

@mathieu17g
Copy link
Copy Markdown
Contributor Author

Thanks, I’m following this lead. I have reviewed Julia 1.6.7 replace code, but have not found the root cause yet.

@mathieu17g
Copy link
Copy Markdown
Contributor Author

Thanks, I’m following this lead. I have reviewed Julia 1.6.7 replace code, but have not found the root cause yet.

Well, no need to review the code, it was in docs.
Support for multiple patterns requires version 1.7.
I will adapt the code for VERSION < v"1.7"

@mathieu17g
Copy link
Copy Markdown
Contributor Author

I guess I still have to raise the coverage a bit

@mathieu17g
Copy link
Copy Markdown
Contributor Author

I guess I still have to raise the coverage a bit

Well, I can't see an easy way to enhance the coverage.
@rafaqz, is it OK for you to leave it like this?

@rafaqz
Copy link
Copy Markdown
Member

rafaqz commented May 29, 2023

Perfect! no worries sbout coverage

Thanks for fixing the tests

@rafaqz rafaqz merged commit b69235a into JuliaGeo:main May 29, 2023
@mathieu17g mathieu17g deleted the Fix_GeoPortail_apikey_handling branch May 29, 2023 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants