def get_layergroup(self, name=None): try: group_url = url(self.service_url, ["layergroups", name + ".xml"]) group = self.get_xml(group_url) return LayerGroup(self, group.find("name").text) except FailedRequestError: return None
def get_styles(self): styles_url = url(self.service_url, ["styles.xml"]) description = self.get_xml(styles_url) return [ Style(self, s.find('name').text) for s in description.findall("style") ]
def add_data_to_store(self, store, name, data, workspace=None, overwrite = False, charset = None): if isinstance(store, basestring): store = self.get_store(store, workspace=workspace) if workspace is not None: workspace = _name(workspace) assert store.workspace.name == workspace, "Specified store (%s) is not in specified workspace (%s)!" % (store, workspace) else: workspace = store.workspace.name store = store.name if isinstance(data, dict): bundle = prepare_upload_bundle(name, data) else: bundle = data params = dict() if overwrite: params["update"] = "overwrite" if charset is not None: params["charset"] = charset message = open(bundle) headers = { 'Content-Type': 'application/zip', 'Accept': 'application/xml' } upload_url = url(self.service_url, ["workspaces", workspace, "datastores", store, "file.shp"], params) try: headers, response = self.http.request(upload_url, "PUT", message, headers) self._cache.clear() if headers.status != 201: raise UploadError(response) finally: unlink(bundle)
def get_style(self, name): try: style_url = url(self.service_url, ["styles", name + ".xml"]) dom = self.get_xml(style_url) return Style(self, dom.find("name").text) except FailedRequestError: return None
def get_resources(self): res_url = url(self.catalog.service_url, ["workspaces", self.workspace.name, "datastores", self.name, "featuretypes.xml"]) xml = self.catalog.get_xml(res_url) def ft_from_node(node): return featuretype_from_index(self.catalog, self.workspace, self, node) return [ft_from_node(node) for node in xml.findall("featureType")]
def create_style(self, name, data, overwrite = False): if overwrite == False and self.get_style(name) is not None: raise ConflictingDataError("There is already a style named %s" % name) headers = { "Content-type": "application/vnd.ogc.sld+xml", "Accept": "application/xml" } if overwrite: style_url = url(self.service_url, ["styles", name + ".sld"]) headers, response = self.http.request(style_url, "PUT", data, headers) else: style_url = url(self.service_url, ["styles"], dict(name=name)) headers, response = self.http.request(style_url, "POST", data, headers) self._cache.clear() if headers.status < 200 or headers.status > 299: raise UploadError(response)
def get_resources(self): res_url = url(self.catalog.service_url, ["workspaces", self.workspace.name, "coveragestores", self.name, "coverages.xml"]) xml = self.catalog.get_xml(res_url) def cov_from_node(node): return coverage_from_index(self.catalog, self.workspace, self, node) return [cov_from_node(node) for node in xml.findall("coverage")]
def get_layers(self, resource=None): if isinstance(resource, basestring): resource = self.get_resource(resource) layers_url = url(self.service_url, ["layers.xml"]) description = self.get_xml(layers_url) lyrs = [Layer(self, l.find("name").text) for l in description.findall("layer")] if resource is not None: lyrs = [l for l in lyrs if l.resource.href == resource.href] # TODO: Filter by style return lyrs
def create_featurestore(self, name, data, workspace=None, overwrite=False, charset=None): if not overwrite: try: store = self.get_store(name, workspace) msg = "There is already a store named " + name if workspace: msg += " in " + str(workspace) raise ConflictingDataError(msg) except FailedRequestError: # we don't really expect that every layer name will be taken pass if workspace is None: workspace = self.get_default_workspace() workspace = _name(workspace) params = dict() if charset is not None: params['charset'] = charset ds_url = url(self.service_url, ["workspaces", workspace, "datastores", name, "file.shp"], params) # PUT /workspaces/<ws>/datastores/<ds>/file.shp headers = { "Content-type": "application/zip", "Accept": "application/xml" } if isinstance(data, dict): logger.debug('Data is NOT a zipfile') archive = prepare_upload_bundle(name, data) else: logger.debug('Data is a zipfile') archive = data message = open(archive) try: headers, response = self.http.request(ds_url, "PUT", message, headers) self._cache.clear() if headers.status != 201: raise UploadError(response) finally: unlink(archive)
def create_coveragestore(self, name, data, workspace=None, overwrite=False): if not overwrite: try: store = self.get_store(name, workspace) msg = "There is already a store named " + name if workspace: msg += " in " + str(workspace) raise ConflictingDataError(msg) except FailedRequestError: # we don't really expect that every layer name will be taken pass if workspace is None: workspace = self.get_default_workspace() headers = {"Content-type": "image/tiff", "Accept": "application/xml"} archive = None ext = "geotiff" if isinstance(data, dict): archive = prepare_upload_bundle(name, data) message = open(archive) if "tfw" in data: headers['Content-type'] = 'application/archive' ext = "worldimage" elif isinstance(data, basestring): message = open(data) else: message = data cs_url = url(self.service_url, [ "workspaces", workspace.name, "coveragestores", name, "file." + ext ]) try: headers, response = self.http.request(cs_url, "PUT", message, headers) self._cache.clear() if headers.status != 201: raise UploadError(response) finally: if archive is not None: unlink(archive)
def create_coveragestore(self, name, data, workspace=None, overwrite=False): if not overwrite: try: store = self.get_store(name, workspace) msg = "There is already a store named " + name if workspace: msg += " in " + str(workspace) raise ConflictingDataError(msg) except FailedRequestError: # we don't really expect that every layer name will be taken pass if workspace is None: workspace = self.get_default_workspace() headers = { "Content-type": "image/tiff", "Accept": "application/xml" } archive = None ext = "geotiff" if isinstance(data, dict): archive = prepare_upload_bundle(name, data) message = open(archive) if "tfw" in data: headers['Content-type'] = 'application/archive' ext = "worldimage" elif isinstance(data, basestring): message = open(data) else: message = data cs_url = url(self.service_url, ["workspaces", workspace.name, "coveragestores", name, "file." + ext]) try: headers, response = self.http.request(cs_url, "PUT", message, headers) self._cache.clear() if headers.status != 201: raise UploadError(response) finally: if archive is not None: unlink(archive)
def create_featurestore(self, name, data, workspace=None, overwrite=False, charset=None): if not overwrite: try: store = self.get_store(name, workspace) msg = "There is already a store named " + name if workspace: msg += " in " + str(workspace) raise ConflictingDataError(msg) except FailedRequestError: # we don't really expect that every layer name will be taken pass if workspace is None: workspace = self.get_default_workspace() workspace = _name(workspace) params = dict() if charset is not None: params['charset'] = charset ds_url = url(self.service_url, ["workspaces", workspace, "datastores", name, "file.shp"], params) # PUT /workspaces/<ws>/datastores/<ds>/file.shp headers = { "Content-type": "application/zip", "Accept": "application/xml" } if isinstance(data,dict): logger.debug('Data is NOT a zipfile') archive = prepare_upload_bundle(name, data) else: logger.debug('Data is a zipfile') archive = data message = open(archive) try: headers, response = self.http.request(ds_url, "PUT", message, headers) self._cache.clear() if headers.status != 201: raise UploadError(response) finally: unlink(archive)
def get_styles(self): styles_url = url(self.service_url, ["styles.xml"]) description = self.get_xml(styles_url) return [Style(self, s.find('name').text) for s in description.findall("style")]
def body_href(self): return url(self.catalog.service_url, ["styles", self.name + ".sld"])
def href(self): return url(self.catalog.service_url, ["workspaces", self.name + ".xml"])
def datastore_url(self): return url(self.catalog.service_url, ["workspaces", self.name, "datastores.xml"])
def reload(self): reload_url = url(self.service_url, ['reload']) response = self.http.request(reload_url, "POST") self._cache.clear() return response
def href(self): return url(self.catalog.service_url, ["workspaces", self.workspace.name, "datastores", self.store.name, "featuretypes", self.name + ".xml"])
def href(self): return url(self.catalog.service_url, ["workspaces", self.workspace.name, "coveragestores"], dict(name=self.name))
def href(self): return url(self.catalog.service_url, ["layergroups", self.name + ".xml"])
def coveragestore_url(self): return url(self.catalog.service_url, ["workspaces", self.name, "coveragestores.xml"])
def href(self): path = [ "workspaces", self.workspace.name, "datastores"] query = dict(name=self.name) return url(self.catalog.service_url, path, query)
def href(self): return url(self.catalog.service_url, ["layers", self.name + ".xml"])
def href(self): return url(self.catalog.service_url, ["workspaces", self.workspace.name, "coveragestores", self.store.name, "coverages", self.name + ".xml"])
def href(self): return url(self.catalog.service_url, ["styles", self.name + ".xml"])