def prepare_children(self, obj): children = [] url = url_slash_join(settings.GISCUBE_URL, '/layerserver/databaselayers/%s/' % obj.name) if obj.geom_field is not None: references = [] for reference in obj.references.all(): service = reference.service service_url = url_slash_join(settings.GISCUBE_URL, '/qgisserver/services/%s/' % service.name) references.append({ 'title': service.title or service.name, 'description': service.description, 'url': service_url, 'projection': '3857' }) children.append({ 'title': _('DataBase Layer'), 'description': None, 'group': False, 'type': 'DataBaseLayer', 'format': 'GeoJSON', 'url': url, 'projection': '4326', 'references': references }) else: children.append({ 'title': _('DataBase Layer'), 'description': None, 'group': False, 'type': 'DataBaseLayer', 'format': 'JSON', 'url': url }) return children + super().prepare_children(obj)
def prepare_children(self, obj): children = [] service = { 'title': obj.title or obj.name, 'description': obj.description, 'group': False } if obj.tilecache_enabled: url = '%s{z}/{x}/{y}.png' % reverse('qgisserver-tilecache', args=(obj.name, )) url = url_slash_join(settings.GISCUBE_URL, url) service.update({'type': 'TMS', 'url': url}) else: url = url_slash_join(settings.GISCUBE_URL, '/qgisserver/services/%s' % obj.name) service.update({ 'type': 'WMS', 'url': url, 'layers': obj.default_layer or '', 'projection': '3857', 'giscube': { 'single_image': obj.wms_single_image, } }) children.append(service) return children + super().prepare_children(obj)
def patch_qgis_project(service): file_path = service.project_file.path tree = ET.parse(file_path) root = tree.getroot() properties = root.find('properties') wms_url = properties.find('WMSUrl') if wms_url is None: wms_url = ET.SubElement(properties, 'WMSUrl') wms_url.set('type', 'QString') giscube_url = getattr(settings, 'GISCUBE_URL', 'http://localhost:8080') wms_url.text = url_slash_join(giscube_url, '/qgisserver/services/%s/' % service.name) project_file = os.path.basename(file_path) filename, _ = os.path.splitext(project_file) wms_service_capabilities = properties.find('WMSServiceCapabilities') if wms_service_capabilities is None: wms_service_capabilities = ET.SubElement(properties, 'WMSServiceCapabilities') wms_service_capabilities.set('type', 'bool') wms_service_capabilities.text = 'true' wms_root_name = properties.find('WMSRootName') if wms_root_name is None: wms_root_name = ET.SubElement(properties, 'WMSRootName') wms_root_name.set('type', 'QString') wms_root_name.text = filename tree.write(file_path)
def test_url_slash_join(self): url = url_slash_join('http://localhost/apps/giscube', 'imageserver/services/streets') url_ok = 'http://localhost/apps/giscube/imageserver/services/streets' self.assertEqual(url, url_ok) url = url_slash_join('http://localhost/apps/giscube/', 'imageserver/services/streets') url_ok = 'http://localhost/apps/giscube/imageserver/services/streets' self.assertEqual(url, url_ok) url = url_slash_join('http://localhost/apps/giscube', '/imageserver/services/streets') url_ok = 'http://localhost/apps/giscube/imageserver/services/streets' self.assertEqual(url, url_ok) url = url_slash_join('http://localhost/apps/giscube/', '/imageserver/services/streets') url_ok = 'http://localhost/apps/giscube/imageserver/services/streets' self.assertEqual(url, url_ok) url = url_slash_join('http://localhost/apps/giscube/', '/imageserver/services/streets/') url_ok = 'http://localhost/apps/giscube/imageserver/services/streets/' self.assertEqual(url, url_ok) url = url_slash_join('http://localhost/', '/apps/giscube/', '/imageserver/services/streets') url_ok = 'http://localhost/apps/giscube/imageserver/services/streets' self.assertEqual(url, url_ok) url = url_slash_join('http://localhost/', '', '/apps/giscube/', '/imageserver/services/streets') url_ok = 'http://localhost/apps/giscube/imageserver/services/streets' self.assertEqual(url, url_ok)
def write(self, service, layers): a = [] # MAP item a.append('MAP') a.append(' NAME "%s"' % service.name) a.append(' PROJECTION') a.append(' "init=epsg:%s"' % service.projection) a.append(' END') a.append('') if service.extent: extent = service.extent.clone() # transform service extent to desired service srid ct = CoordTransform(SpatialReference('WGS84'), SpatialReference(service.projection)) extent.transform(ct) a.append(' EXTENT %s %s %s %s' % extent.extent) a.append('') srss = service.supported_srs.split(',') srss = [('EPSG:%s' % x.strip()) for x in srss] srss = ' '.join(srss) server = getattr(settings, 'GISCUBE_URL', 'http://localhost') a.append(' WEB') a.append(' METADATA') a.append(' "wms_title" "%s"' % service.title) a.append(' "wms_srs" "%s"' % srss) a.append(' "wms_enable_request" "GetCapabilities GetMap"') a.append( ' "wms_onlineresource" "%s"' % url_slash_join(server, 'imageserver/services/%s/?' % service.name)) a.append(' "wms_bbox_extended" "true"') a.append(' END') a.append(' END') a.append('') lw = MapserverLayerWriter() named_masks = set() for layer in layers: if layer.named_mask and layer.named_mask not in named_masks: mw = MapserverMaskWriter() mask, _ = mw.write(layer.named_mask.name, layer.named_mask.mask_path, layer.named_mask.projection) a.extend(mask) named_masks.add(layer.named_mask) a.append(lw.write(layer, service.supported_srs)) a.append('') # MAP END a.append('END') # Force newline at end a.append('') return '\n'.join(a)
def prepare_children(self, obj): children = [] url = url_slash_join( settings.GISCUBE_URL, remove_app_url(reverse('geojsonlayer', kwargs={'name': obj.name}))) children.append({ 'title': _('GeoJSON Layer'), 'description': None, 'group': False, 'type': 'GeoJSON', 'url': url, 'projection': '4326', }) return children + super().prepare_children(obj)
def to_representation(self, obj): data = super().to_representation(obj) data['pagination'] = { 'page_size': obj.get_page_size(), 'max_page_size': obj.get_max_page_size() } data['design'] = { 'list_fields': obj.list_fields, 'form_fields': obj.form_fields } if obj.geom_field is None: data['geom_type'] = None self.format_options_json(obj, data) else: Layer = create_dblayer_model(obj) field = Layer._meta.get_field(obj.geom_field) data['geom_type'] = field.geom_type data['design']['popup'] = obj.popup if obj.interactive else None self.format_options_geojson(obj, data) data['style'] = style_representation(obj) data['style_rules'] = style_rules_representation(obj) data['design']['interactive'] = obj.interactive data['design'][ 'tooltip'] = obj.tooltip if obj.interactive else None data['design']['cluster'] = json.loads( obj.cluster_options or '{}') if obj.cluster_enabled else None if obj.wms_as_reference and obj.shapetype: path = reverse('content-wms', kwargs={'name': obj.name}) url = url_slash_join(settings.GISCUBE_URL, remove_app_url(path)) reference = { 'title': data['title'], 'url': url, 'type': 'WMS', 'auth': 'token' if not obj.anonymous_view else None, 'options': { 'layers': data['name'], 'format': 'image/png', 'transparent': True, 'uppercase': True }, 'refresh': True } data['references'].insert(0, reference) return data
def service_url(self): return url_slash_join(settings.GISCUBE_URL, '/qgisserver/services/%s' % self.name)
def get_url(self, obj): if obj.service is None: return serializers.empty return url_slash_join(settings.GISCUBE_URL, '/qgisserver/services/%s/' % obj.service.name)