def create_in_group(cls, name, ngw_group_resource, wms_url, version="1.1.1", auth=(None, None)): connection = ngw_group_resource._res_factory.connection url = ngw_group_resource.get_api_collection_url() params = dict(resource=dict(cls=cls.type_id, display_name=name, parent=dict( id=ngw_group_resource.common.id))) params[cls.type_id] = dict( url=wms_url, username=auth[0], password=auth[1], version=version, capcache="query", ) result = connection.post(url, params=params) ngw_resource = cls( ngw_group_resource._res_factory, NGWResource.receive_resource_obj(connection, result['id'])) return ngw_resource
def create_in_group(cls, name, ngw_group_resource, ngw_webmap_items, ngw_base_maps=[], bbox=[-180, 180, 90, -90]): connection = ngw_group_resource._res_factory.connection url = ngw_group_resource.get_api_collection_url() base_maps = [] for ngw_base_map in ngw_base_maps: base_maps.append( { "display_name": ngw_base_map.common.display_name, "resource_id": ngw_base_map.common.id, "enabled": True, "opacity": None, } ) web_map_base_maps = dict( basemaps=base_maps, ) web_map = dict( extent_left=bbox[0], extent_right=bbox[1], extent_top=bbox[2], extent_bottom=bbox[3], root_item=dict( item_type="root", children=ngw_webmap_items ) ) params = dict( resource=dict( cls=NGWWebMap.type_id, display_name=name, parent=dict( id=ngw_group_resource.common.id ) ), webmap=web_map, basemap_webmap=web_map_base_maps, ) result = connection.post(url, params=params) ngw_resource = NGWWebMap( ngw_group_resource._res_factory, NGWResource.receive_resource_obj( connection, result['id'] ) ) return ngw_resource
def create_style(self): """Create default style for this layer """ connection = self._res_factory.connection style_name = self.generate_unique_child_name(self.common.display_name + '-style') params = dict(resource=dict(cls="raster_style", parent=dict(id=self.common.id), display_name=style_name), ) url = self.get_api_collection_url() result = connection.post(url, params=params) ngw_resource = NGWResource( self._res_factory, NGWResource.receive_resource_obj(connection, result['id'])) return ngw_resource
def create_empty(cls, ngw_resource_parent, display_name): display_name_uniq = ngw_resource_parent.generate_unique_child_name( display_name) parameters = { "resource": { "cls": cls.type_id, "parent": { "id": ngw_resource_parent.common.id }, "display_name": display_name_uniq, "keyname": None, "description": None }, "resmeta": { "items": {} }, "vector_layer": { "srs": { "id": 3857 }, "geometry_type": "POINT", "fields": [ { "keyname": "attr", "datatype": "STRING" }, ] } } connection = ngw_resource_parent._res_factory.connection url = cls.get_api_collection_url() result = connection.post(url, params=parameters) ngw_resource = NGWVectorLayer( ngw_resource_parent._res_factory, NGWResource.receive_resource_obj( ngw_resource_parent._res_factory.connection, result['id'])) return ngw_resource
def create_in_group(cls, name, ngw_group_resource, ngw_layers_with_style): connection = ngw_group_resource._res_factory.connection url = ngw_group_resource.get_api_collection_url() params_layers = [] for ngw_layer, ngw_style_id in ngw_layers_with_style: params_layer = dict( display_name=ngw_layer.common.display_name, keyname="ngw_id_%d" % ngw_layer.common.id, resource_id=ngw_style_id, min_scale_denom=None, max_scale_denom=None, ) params_layers.append(params_layer) params = dict( resource=dict( cls=cls.type_id, display_name=name, parent=dict( id=ngw_group_resource.common.id ) ) ) params[cls.type_id] = dict( layers=params_layers ) result = connection.post(url, params=params) ngw_resource = cls( ngw_group_resource._res_factory, NGWResource.receive_resource_obj( connection, result['id'] ) ) return ngw_resource
def create_in_group(cls, name, ngw_group_resource, base_map_url, qms_ext_settings=None): connection = ngw_group_resource._res_factory.connection params = dict(resource=dict(cls=cls.type_id, display_name=name, parent=dict( id=ngw_group_resource.common.id))) qms_parameters = None if qms_ext_settings is not None: qms_parameters = qms_ext_settings.toJSON() params[cls.type_id] = dict(url=base_map_url, qms=qms_parameters) result = connection.post(ngw_group_resource.get_api_collection_url(), params=params) ngw_resource = cls( ngw_group_resource._res_factory, NGWResource.receive_resource_obj(connection, result['id'])) return ngw_resource
def create_qml_style(self, qml, callback): """Create QML style for this layer qml - full path to qml file callback - upload file callback """ connection = self._res_factory.connection style_name = self.generate_unique_child_name(self.common.display_name + '-style') style_file_desc = connection.upload_file(qml, callback) params = dict(resource=dict(cls=NGWQGISVectorStyle.type_id, parent=dict(id=self.common.id), display_name=style_name), ) params[NGWQGISVectorStyle.type_id] = dict(file_upload=style_file_desc) url = self.get_api_collection_url() result = connection.post(url, params=params) ngw_resource = NGWQGISVectorStyle( self._res_factory, NGWResource.receive_resource_obj(connection, result['id'])) return ngw_resource
def create_in_group(cls, name, ngw_group_resource, ngw_wms_connection_id, wms_layers, wms_format): connection = ngw_group_resource._res_factory.connection url = ngw_group_resource.get_api_collection_url() params = dict(resource=dict(cls=cls.type_id, display_name=name, parent=dict( id=ngw_group_resource.common.id))) params[cls.type_id] = dict( connection=dict(id=ngw_wms_connection_id), wmslayers=",".join(wms_layers), imgformat=wms_format, srs=dict(id=3857), ) result = connection.post(url, params=params) ngw_resource = cls( ngw_group_resource._res_factory, NGWResource.receive_resource_obj(connection, result['id'])) return ngw_resource
def get_resource(self, resource_id): res_json = NGWResource.receive_resource_obj(self.__conn, resource_id) return self.get_resource_by_json(res_json)