Skip to content

Commit

Permalink
#47 improved srs selection (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Planzer committed Mar 21, 2019
1 parent 807b4dc commit ef922e2
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 177 deletions.
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@ env:
matrix:
- QGIS_VERSION_TAG=master
language: python
cache:
directories:
- "$HOME/.cache/pip"
python:
- '3.6'
branches:
only:
- master_qgis3
addons:
apt:
packages:
- git
- python-software-properties
before_install:
- docker pull ${IMAGE}:${QGIS_VERSION_TAG}
install:
- pip install --upgrade pip
- docker run -d --name qgis-testing-environment -v ${TRAVIS_BUILD_DIR}:/tests_directory
-e LDI_LINZ_KEY -e LDI_MFE_KEY -e LDI_NZDF_KEY -e DISPLAY=:99 ${IMAGE}:${QGIS_VERSION_TAG}
- sleep 10
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ the plugin is started.
The left hand panel allows users to filter by service / protocol types (either, All, WFS, WMS, WMTS).
All column headers can be toggled to allow ascending or descending ordering of their data.
Text can be entered in the "Filter Data Sets" search bar to filter the datasets by keyword.
## Source Code, Further Documentation and Feedback
## Source Code and Feedback
Please see the [LINZ-Data-Importer](https://github.com/linz/linz-data-importer/) repository on GitHub.

## Dev Notes
Expand Down
4 changes: 4 additions & 0 deletions linz-data-importer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
This script initializes the plugin, making it known to QGIS.
"""

import sys
from os.path import dirname, abspath
sys.path.append(dirname(abspath(__file__)))


# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
Expand Down
21 changes: 17 additions & 4 deletions linz-data-importer/gui/Service_dialog.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#TODO// header

"""
/***************************************************************************
LINZ Data Importer
A QGIS plugin
Import LINZ (and others) OGC Datasets into QGIS
-------------------
begin : 2018-04-07
git sha : $Format:%H$
copyright : (C) 2017 by Land Information New Zealand
email : splanzer@linz.govt.nz
***************************************************************************/
/***************************************************************************
* This program is released under the terms of the 3 clause BSD license. *
* see the LICENSE file for more information *
***************************************************************************/
"""


import os

from PyQt5 import QtGui, QtWidgets, uic

FORM_CLASS, _ = uic.loadUiType(os.path.join(
Expand Down Expand Up @@ -44,4 +57,4 @@ def __init__(self, parent=None):
# }
# """
# )


13 changes: 11 additions & 2 deletions linz-data-importer/gui/Service_dialog_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
Expand All @@ -146,7 +149,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="uCRSCombo">
<widget class="ExtendedCombobox" name="uCRSCombo">
<property name="maximumSize">
<size>
<width>160</width>
Expand Down Expand Up @@ -819,9 +822,15 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ExtendedCombobox</class>
<extends>QComboBox</extends>
<header>tablemodel.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>uTextFilter</tabstop>
<tabstop>uCRSCombo</tabstop>
<tabstop>uBtnImport</tabstop>
<tabstop>uListOptions</tabstop>
<tabstop>uTableView</tabstop>
Expand Down
Empty file removed linz-data-importer/gui/__init__.py
Empty file.
25 changes: 17 additions & 8 deletions linz-data-importer/linz_data_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* see the LICENSE file for more information *
***************************************************************************/
"""
from __future__ import absolute_import

# This program is released under the terms of the 3 clause BSD license. See the
# LICENSE file for more information.
Expand All @@ -24,12 +23,12 @@
from qgis.PyQt.QtCore import QSettings, QTranslator, qVersion, QCoreApplication, Qt, QRegExp, QSize, Qt

from qgis.PyQt.QtWidgets import QAction, QListWidgetItem, QHeaderView, QMenu, QToolButton
from qgis.PyQt.QtGui import QIcon, QPixmap, QImage
from qgis.PyQt.QtGui import QIcon, QPixmap, QImage, QStandardItemModel, QStandardItem
from qgis.PyQt.QtCore import QSortFilterProxyModel
from qgis.core import (QgsRasterLayer, QgsVectorLayer, QgsProject,
QgsCoordinateReferenceSystem, Qgis)
from qgis.gui import QgsMessageBar
from .tablemodel import TableModel, TableView
from .tablemodel import TableModel
from .service_data import ServiceData, Localstore, ApiKey

import re
Expand Down Expand Up @@ -238,7 +237,9 @@ def initGui(self):
self.dlg.uListOptions.itemClicked.connect(self.showSelectedOption)
self.dlg.uListOptions.itemClicked.emit(self.dlg.uListOptions.item(0))
self.curr_list_wid_index=0


model = QStandardItemModel()
self.dlg.uCRSCombo.setModel(model)
self.dlg.uCRSCombo.currentIndexChanged.connect(self.layerCrsSelected)

self.dlg.uLabelWarning.setStyleSheet('color:red')
Expand Down Expand Up @@ -541,9 +542,17 @@ def showSelectedOption(self, item):
self.dlg.uStackedWidget.setCurrentIndex(2)

def layerCrsSelected(self):
self.selected_crs = str(self.dlg.uCRSCombo.currentText())
if self.selected_crs:
self.selected_crs_int = int(self.selected_crs.strip('EPSG:'))
"""
Track the user selected crs. Check validity to
ensure only well formed crs are provided.
"""

valid = re.compile('^EPSG\:\d+')
crs_text = self.dlg.uCRSCombo.currentText()
if valid.match(crs_text):
self.selected_crs = str(self.dlg.uCRSCombo.currentText())
if self.selected_crs:
self.selected_crs_int = int(self.selected_crs.strip('EPSG:'))

def getPreview(self, res, res_timeout):
"""
Expand Down Expand Up @@ -706,7 +715,7 @@ def importDataset(self):
Import the selected dataset to QGIS
"""

if not self.layers_loaded:
if not self.layers_loaded and not self.data_type == 'table':
self.setProjectSRID()

if self.service == "WFS":
Expand Down
6 changes: 5 additions & 1 deletion linz-data-importer/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ repository=https://github.com/linz/linz-data-importer
# Recommended items:

# Uncomment the following line and add your changelog:
changelog= Upgraded to QGIS3 API
changelog= v2.0.1-beta:
- #48 mac osx text encoding
- #47 crs filtering
<p>v2.0.0-beta:
- Upgrade to QGIS3 API

# Tags are comma separated with spaces allowed
tags=wmts, wms, wfs, webservice, web, LINZ, LDS, MFE, Stats NZ, LRIS, NZDF
Expand Down
107 changes: 0 additions & 107 deletions linz-data-importer/plugin_upload.py

This file was deleted.

42 changes: 28 additions & 14 deletions linz-data-importer/service_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from owslib.wmts import WebMapTileService
from owslib.util import ServiceException
from qgis.core import QgsMessageLog, QgsApplication
from qgis.core import QgsApplication

import os.path

Expand All @@ -40,6 +40,7 @@

from qgis.PyQt.QtCore import QSettings


class ApiKey(object):
"""
Store API Keys for each domain. Required to
Expand Down Expand Up @@ -166,8 +167,6 @@ def delAllLocalServiceXML(self, services=['wms','wfs','wmts']):
file = os.path.join(dir, f)
self.delLocalSeviceXML(file)



def purgeCache(self):
"""
Delete all cached documents but the
Expand Down Expand Up @@ -281,7 +280,7 @@ def isEnabled(self):

def getServiceData(self):
"""
Select method to obtain capbilties doc.
Select method to obtain capabilities doc.
Either via localstore or internet
"""

Expand Down Expand Up @@ -381,30 +380,45 @@ def getServiceXml(self):

elif hasattr(e, 'code'):
self.err = 'Error: ({0}) {1}'.format(self.domain, e.reason)


def sortCrs(self):
# wms returns some no valid crs values
valid = re.compile('^EPSG\:\d+')
self.crs = [s for s in self.crs if valid.match(s)]
# sort
self.crs.sort(key = lambda x: int(x.split(':')[1]))

def formatForUI(self):
"""
Format the service data to display in the UI
"""


wms_crs = []
service_data = []
cont = self.obj.contents

for dataset_id, dataset_obj in cont.items():
crs=[]
self.crs=[]
full_id = re.search(r'([aA-zZ]+\\.[aA-zZ]+\\.[aA-zZ]+\\.[aA-zZ]+\\:)?(?P<type>[aA-zZ]+)-(?P<id>[0-9]+)', dataset_obj.id)
type = full_id.group('type')
id = full_id.group('id')
# Get and standarise espg codes
if self.service == 'wmts':
crs = dataset_obj.tilematrixsets
self.crs = dataset_obj.tilematrixsets
self.sortCrs()
elif self.service in ('wfs'):
crs = dataset_obj.crsOptions
crs = ['EPSG:{0}'.format(item.code) for item in crs]
self.crs = dataset_obj.crsOptions
self.crs = ['EPSG:{0}'.format(item.code) for item in self.crs]
self.sortCrs()
elif self.service in ('wms'):
crs = dataset_obj.crsOptions
crs = ['EPSG:{0}'.format(item.strip('urn:ogc:def:crs:EPSG::')) for item in crs]
if wms_crs:
self.crs = wms_crs
else:
self.crs = dataset_obj.crsOptions
self.sortCrs()
wms_crs = self.crs

service_data.append([self.domain, type, self.service.upper(), id,
dataset_obj.title, dataset_obj.abstract, crs])
dataset_obj.title, dataset_obj.abstract, self.crs])

self.info = service_data

Loading

0 comments on commit ef922e2

Please sign in to comment.