Skip to content

Commit

Permalink
Add automatic conversion of QGIS symbology to FSL
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored May 15, 2024
1 parent 6e943b9 commit 055998d
Show file tree
Hide file tree
Showing 42 changed files with 4,218 additions and 554 deletions.
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

0 comments on commit 055998d

Please sign in to comment.