Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for QGIS symbol -> FSL symbol conversion #64

Merged
merged 60 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2e8c311
Start on symbol to FSL converter
nyalldawson Apr 29, 2024
0bb7e31
Simple fill conversion
nyalldawson Apr 29, 2024
f956ca2
Shapeburst fill
nyalldawson Apr 29, 2024
82e737d
Gradient fill
nyalldawson Apr 29, 2024
5f424b2
Line pattern fill
nyalldawson Apr 30, 2024
95119de
More symbol layer types
nyalldawson Apr 30, 2024
0d0ded2
Ellipse marker
nyalldawson Apr 30, 2024
9fff3f7
Font marker, svg marker
nyalldawson Apr 30, 2024
50e86b9
Finish fill support, marker line
nyalldawson Apr 30, 2024
d1badd0
Complete QGIS -> FSL symbol conversion
nyalldawson Apr 30, 2024
ce89af0
Lint
nyalldawson Apr 30, 2024
12d90ae
Lint
nyalldawson Apr 30, 2024
228034f
Lint
nyalldawson Apr 30, 2024
0a9911f
Refine test matrix
nyalldawson May 1, 2024
5bf319f
Start on renderer conversion
nyalldawson May 2, 2024
9a630c4
Convert categorized renderers
nyalldawson May 2, 2024
88d5689
Convert graduated renderers
nyalldawson May 2, 2024
c6d86ef
Lint
nyalldawson May 2, 2024
9294023
Add text format conversion
nyalldawson May 3, 2024
0034f13
Start on label settings conversion
nyalldawson May 3, 2024
8c4307f
Add note
nyalldawson May 3, 2024
f3aea19
Convert label zoom range
nyalldawson May 3, 2024
b4f8095
Use v2 API for uploading layers
nyalldawson May 3, 2024
4ea3a16
Attempt to patch layer style
nyalldawson May 3, 2024
2e51891
Fix patch data
nyalldawson May 3, 2024
f1cbee9
s/category/categorical
nyalldawson May 3, 2024
8586dc2
Support labels
nyalldawson May 3, 2024
f3e78ab
labelAttribute should be an array
nyalldawson May 9, 2024
1f31a5b
Skip test on older qgis
nyalldawson May 9, 2024
dbb48e3
Skip other test on old qgis
nyalldawson May 9, 2024
3414038
Lint
nyalldawson May 9, 2024
6929ee9
Lint
nyalldawson May 9, 2024
7115ebb
Handle hairline stroke sizes
nyalldawson May 9, 2024
3a9e6db
Fix oversized point markers
nyalldawson May 9, 2024
1d369c6
Convert scale based visibility
nyalldawson May 9, 2024
9eba830
Lint
nyalldawson May 9, 2024
6161f9d
Convert simple rule based renderer setups
nyalldawson May 9, 2024
6efa17d
Lint
nyalldawson May 9, 2024
b6a7dbb
Start on raster style conversion
nyalldawson May 9, 2024
f824102
Try to upload converted psuedo color raster styling
nyalldawson May 9, 2024
ff3ee37
Fix conversion of fills with no fill color but stroke
nyalldawson May 10, 2024
27fad09
Hide upload as styled action
nyalldawson May 10, 2024
75fe2fb
Convert paletted raster renderer
nyalldawson May 10, 2024
a104c1d
Paletted should use categorical type
nyalldawson May 10, 2024
053f693
Tweak categorial raster fsl
nyalldawson May 10, 2024
95aec15
Short term workaround to get paletted uploads working
nyalldawson May 13, 2024
88523f5
Fix uploading styled rasters which cannot be converted to fsl
nyalldawson May 13, 2024
4ae83a6
Update tests
nyalldawson May 13, 2024
1b069c3
Lint
nyalldawson May 13, 2024
ddee6ed
Remove extraneous content from headers
nyalldawson May 13, 2024
8eee8de
Remove unused import
nyalldawson May 13, 2024
fce87ff
Update tests
nyalldawson May 13, 2024
958d2a6
Handle singleband gray renderer
nyalldawson May 13, 2024
aa56c82
Lint
nyalldawson May 13, 2024
d2bbb08
Fix exception when labels can be converted but not renderer
nyalldawson May 15, 2024
3f1dba5
Don't endless loop when rate limit is triggered
nyalldawson May 15, 2024
0c75f63
Fix stroke showing for categorized fills when it should be transparent
nyalldawson May 15, 2024
c80f18f
Convert qgis raster resampling setting
nyalldawson May 15, 2024
04bb182
Lint
nyalldawson May 15, 2024
0b19bd3
Lint
nyalldawson May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

strategy:
matrix:
docker_tags: [release-3_22, release-3_28, release-3_30, latest]
docker_tags: [release-3_22, release-3_28, release-3_34, release-3_36]

steps:

Expand Down
1 change: 1 addition & 0 deletions felt/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
from .thumbnail_manager import AsyncThumbnailManager # noqa
from .workspaces_model import WorkspacesModel # noqa
from .workspace import Workspace # noqa
from .fsl_converter import FslConverter, ConversionContext # noqa
82 changes: 64 additions & 18 deletions felt/core/api_client.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# -*- coding: utf-8 -*-
"""Felt API client

.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

__author__ = '(C) 2023 by Nyall Dawson'
__date__ = '1/06/2023'
__copyright__ = 'Copyright 2022, North Road'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
Felt API client
"""

import json
from typing import (
Expand Down Expand Up @@ -42,7 +31,8 @@
from .s3_upload_parameters import S3UploadParameters
from .enums import UsageType
from .constants import (
FELT_API_URL
FELT_API_URL,
FELT_APIV2_URL
)

PLUGIN_VERSION = "0.7.0"
Expand All @@ -61,6 +51,8 @@ class FeltApiClient:
URL_IMPORT_ENDPOINT = '/maps/{}/layers/url_import'
USAGE_ENDPOINT = '/internal/reports'
RECENT_MAPS_ENDPOINT = '/maps/recent'
UPLOAD_V2_ENDPOINT = '/maps/{}/upload'
PATCH_STYLE_ENDPOINT = '/maps/{}/layers/{}/style'

def __init__(self):
# default headers to add to all requests
Expand All @@ -84,11 +76,14 @@ def set_token(self, token: Optional[str]):
pass

@staticmethod
def build_url(endpoint: str) -> QUrl:
def build_url(endpoint: str, version: int = 1) -> QUrl:
"""
Returns the full url of the specified endpoint
"""
return QUrl(FELT_API_URL + endpoint)
if version == 1:
return QUrl(FELT_API_URL + endpoint)
elif version == 2:
return QUrl(FELT_APIV2_URL + endpoint)

@staticmethod
def _to_url_query(parameters: Dict[str, object]) -> QUrlQuery:
Expand All @@ -104,12 +99,13 @@ def _to_url_query(parameters: Dict[str, object]) -> QUrlQuery:
query.addQueryItem(name, str(value))
return query

def _build_request(self, endpoint: str, headers=None, params=None) \
def _build_request(self, endpoint: str, headers=None, params=None,
version: int = 1) \
-> QNetworkRequest:
"""
Builds a network request
"""
url = self.build_url(endpoint)
url = self.build_url(endpoint, version)

if params:
url.setQuery(FeltApiClient._to_url_query(params))
Expand Down Expand Up @@ -281,6 +277,33 @@ def prepare_layer_upload(self,
json_data.encode()
)

def prepare_layer_upload_v2(self,
map_id: str,
name: str,
feedback: Optional[QgsFeedback] = None) \
-> Union[QNetworkReply, QgsNetworkReplyContent]:
"""
Prepares a layer upload, using v2 api
"""
request = self._build_request(
self.UPLOAD_V2_ENDPOINT.format(map_id),
{'Content-Type': 'application/json'},
version=2
)

request_params = {
'name': name
}

json_data = json.dumps(request_params)
reply = QgsNetworkAccessManager.instance().blockingPost(
request,
json_data.encode(),
feedback=feedback
)

return reply

def create_upload_file_request(self,
filename: str,
content: bytes,
Expand Down Expand Up @@ -385,6 +408,29 @@ def finalize_layer_upload(self,
json_data.encode()
)

def patch_style(self,
map_id: str,
layer_id: str,
fsl: Dict) \
-> QNetworkReply:
"""
Patches a layer's style
"""
request = self._build_request(
self.PATCH_STYLE_ENDPOINT.format(map_id, layer_id),
{'Content-Type': 'application/json'}
)

style_post_data = {
'style': json.dumps(fsl)
}

return QgsNetworkAccessManager.instance().sendCustomRequest(
request,
b"PATCH",
json.dumps(style_post_data).encode()
)

def report_usage(self,
content: str,
usage_type: UsageType = UsageType.Info) -> QNetworkReply:
Expand Down
15 changes: 2 additions & 13 deletions felt/core/auth.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# -*- coding: utf-8 -*-
"""Felt QGIS plugin

.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

__author__ = '(C) 2023 by Nyall Dawson'
__date__ = '1/06/2023'
__copyright__ = 'Copyright 2022, North Road'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
Felt QGIS plugin
"""

import json
import urllib
Expand Down
16 changes: 3 additions & 13 deletions felt/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
# -*- coding: utf-8 -*-
"""Felt plugin constants

.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

__author__ = '(C) 2022 by Nyall Dawson'
__date__ = '22/11/2022'
__copyright__ = 'Copyright 2022, North Road'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
Felt plugin constants
"""

FELT_API_BASE = "https://felt.com"
FELT_API_URL = f'{FELT_API_BASE}/api/v1'
FELT_APIV2_URL = f'{FELT_API_BASE}/api/v2'
SIGNUP_URL = f'{FELT_API_BASE}/signup'
TOS_URL = f'{FELT_API_BASE}/terms'
PRIVACY_POLICY_URL = f'{FELT_API_BASE}/privacy'
12 changes: 0 additions & 12 deletions felt/core/enums.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
# -*- coding: utf-8 -*-
"""
Enums

.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

__author__ = '(C) 2023 by Nyall Dawson'
__date__ = '1/06/2023'
__copyright__ = 'Copyright 2022, North Road'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from enum import (
Enum,
auto
Expand Down
12 changes: 0 additions & 12 deletions felt/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
# -*- coding: utf-8 -*-
"""
Custom exceptions

.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""

__author__ = '(C) 2023 by Nyall Dawson'
__date__ = '1/06/2023'
__copyright__ = 'Copyright 2022, North Road'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


class LayerPackagingException(Exception):
"""
Expand Down
Loading
Loading