Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Ilwis::Resource Class Reference

#include <resource.h>

Inheritance diagram for Ilwis::Resource:
Ilwis::Identity Ilwis::OperationResource

Public Member Functions

 Resource ()
 
 Resource (const Resource &resource)
 
 Resource (const QUrl &url, quint64 tp, bool isNew=true)
 
 Resource (const QString &name, quint64 tp, bool isNew=true)
 
 Resource (quint64 tp, const QUrl &url=INTERNAL_OBJECT)
 
 Resource (const QSqlRecord &rec)
 
void setName (const QString &nm, bool adaptUrl=true)
 
QVariant operator[] (const QString &property) const
 
bool hasProperty (const QString &property) const
 
void addProperty (const QString &key, const QVariant &value)
 
QUrl url () const
 
void setUrl (const QUrl &url)
 
QUrlQuery urlQuery () const
 
bool hasUrlQuery () const
 
QString toLocalFile (bool relative=false) const
 
QUrl container (int level=0) const
 
void addContainer (const QUrl &url, int level=0)
 
quint64 size () const
 
QString dimensions () const
 
IlwisTypes ilwisType () const
 
IlwisTypes extendedType () const
 
void setIlwisType (IlwisTypes tp)
 
void setExtendedType (IlwisTypes tp)
 
void prepare ()
 
bool store (QSqlQuery &queryItem, QSqlQuery &queryProperties) const
 
bool isValid () const
 
bool operator() (const Ilwis::Resource &resource)
 
void setId (quint64 newid)
 
Resource copy (quint64 id) const
 
bool isRoot () const
 
- Public Member Functions inherited from Ilwis::Identity
virtual void setCode (const QString &code)
 sets the code for this instance More...
 
QString code () const
 code returns the code of the identity. If no code is attached it will return sUNDEF ("?"). More...
 
quint64 id () const
 id returns a unsigned 64-bit number unique for the objects using the identity More...
 
virtual QString name () const
 name returns the name of an object. All objects have names though names need not to be unique More...
 
void setName (const QString &n)
 setName sets the name of an object. All objects have names though names need not to be unique More...
 
virtual QString description () const
 
void setDescription (const QString &desc)
 

Static Public Member Functions

static QString toLocalFile (const QUrl &url, bool relative=false, const QString &ext=sUNDEF)
 
static bool isRoot (const QString &txt)
 

Protected Member Functions

void stringAsUrl (const QString &txt, IlwisTypes tp, bool isNew)
 
void checkUrl (IlwisTypes tp)
 
- Protected Member Functions inherited from Ilwis::Identity
 Identity (const QString &name, qint64 id=i64UNDEF, const QString &cde=sUNDEF, const QString &descr=sUNDEF)
 
void prepare (quint64 base=0)
 
void setId (quint64 newid)
 

Protected Attributes

QHash< QString, QVariant > _properties
 
QUrl _resource
 
QUrlQuery _urlQuery
 
std::vector< QUrl > _container
 
quint64 _size
 
QString _dimensions
 
IlwisTypes _ilwtype
 
IlwisTypes _extendedType
 

Detailed Description

Design In Ilwis a Resource is a unique definition of data or processing that can be translated
into a single IlwisObject or Catalog. For example the location to a shape file or a query
on a certain database. A Resource is identified by a unique combination of location
(an url) and type. Often a single data source can be mapped to several resources. E.g
a GeoTiff can be mapped to a GridCoverage obviously but it can also be mapped to a
CoordinateSystem as the data for a full definition of the CoordinateSystem is also part
of the GeoTiff file. Resources can be sub divided into three categories: data objects,
operation objects and catalogs. The data objects can be seen as “Ilwis objects light”
and the catalogs are the containers for these data objects. Containers are defined as
queries on the MasterCatalog).

Resources expose the following properties

Constructor & Destructor Documentation

Resource::Resource ( )

Constructs an empty Resource

Resource::Resource ( const Resource resource)

Copy constructor, other resource must not be null

Parameters
resourcethe Resource that should be copied
Resource::Resource ( const QUrl &  url,
quint64  tp,
bool  isNew = true 
)

Creates a resource from an url and a type Will fail if the url or the type is invalid/undefined

Parameters
urlthe url that should be used to create this resource
tpthe type of the resource
isNewset to false if you are not making a new Resource defaults to true (singletons)
Resource::Resource ( const QString &  name,
quint64  tp,
bool  isNew = true 
)

Creates a Resource from a description in the form of a namespace name

Parameters
namename of the resource can be an url or a code
tpthe type of the resource
isNewset to false if you are not making a new Resource defaults to true (singletons)
Resource::Resource ( quint64  tp,
const QUrl &  url = INTERNAL_OBJECT 
)

Creates an resource from a file, the file has to be specified with a valid url

Parameters
tpthe type of the resource
urlThe url to the file you want to load in this resource
Resource::Resource ( const QSqlRecord &  rec)

Creates a new Resource from a Database record, this record should come from the mastercatalog

Parameters
rec

Member Function Documentation

void Resource::addContainer ( const QUrl &  url,
int  level = 0 
)

adds a container to this resource, defines the container this resource is in inside ilwis

Parameters
urlThe container that has to be set
levelThe level of the new container
void Resource::addProperty ( const QString &  key,
const QVariant &  value 
)

Adds a property to this resource, a propert is a combination of a key and a value.
the key can also be seen as the name of the property.

Parameters
key
value
Resource Resource::copy ( quint64  id) const

Copies this resource, only difference is the id, since Resources are always singletons.

The new Resource will be prepared and than returned

Parameters
idthe id of the copy
Returns
the copy
QString Resource::dimensions ( ) const

Query this Resource for its dimensions.
the dimension of a Resource is in general some form of size, could be in bytes, but stuff like XxY pixels is also possible

Returns
IlwisTypes Resource::extendedType ( ) const

Returns the extended IlwisType

See Also
IlwisObject
Returns
The correct IlwisType
bool Resource::hasProperty ( const QString &  property) const

Checks whether this Resource has a certain property, a resource always has a "name" and a "id"

Parameters
propertythe property that should be checked
Returns
true if the property excists within this resource
bool Resource::hasUrlQuery ( ) const

Indicates if the Resource has been created with a url containing a query string. If so it can be accessed by urlQuery().

Returns
true if the Resource url has query parameters, false otherwise.
IlwisTypes Resource::ilwisType ( ) const

Returns the ilwis type of this Resource, anything is possible

See Also
IlwisObject
Returns
The correct IlwisType
bool Resource::isValid ( ) const

Checks if this Resource is valid a resource is valid if it has a valid name, a valid IlwisType and the url to the resource is valid

Returns
true if this resource is valid
bool Resource::operator() ( const Ilwis::Resource resource)

override of the operater, checks whether this Resource is smaller than the supplied resource, returns true if this is the case.
This method is for sorting purposes, it gets sorted first on url, and afterwards on ilwistype

Parameters
resourcethe resource this should be compared with
Returns
true if this<resource
QVariant Resource::operator[] ( const QString &  property) const

override of the [] operator, allows you to query this resource for some of its data.

You can query either for an "id" or an "name", these will always work, any other property might fail.

Parameters
propertythe property that should be retrieved from the attributetable
Returns
the Value of the property or iUNDEF
void Resource::prepare ( )

Prepares this Resource

void Resource::setExtendedType ( IlwisTypes  tp)

Sets the extendedType of this Resource

See Also
IlwisObject
Parameters
tpthe new extended type of this resource
void Resource::setId ( quint64  newid)

Sets a new id on this Resource. A new id has to be unique, and not registered in the catalog

Parameters
newidthe new id of this resource
void Resource::setIlwisType ( IlwisTypes  tp)

Sets the ilwistype of this Resource.

usefull in the case the type of this resource can not be resolved from the filename / extension

See Also
IlwisObject
Parameters
tpthe new ilwistype of this resource
void Resource::setName ( const QString &  nm,
bool  adaptUrl = true 
)

Changes the name of this resource, can adapt the file name on the disk

Parameters
nmthe new name of this Resource
adaptUrlset to false if you do not want to change the file name
void Resource::setUrl ( const QUrl &  url)

Changes The url of this Resource, and thus changes this whole Resource, as it will read the new file and refill all the fields using that.

The url has to be valid though.

Parameters
urlThe new url, must be valid
quint64 Resource::size ( ) const

Query for the size of this Resource

Returns
the size of this Resource, cannot be <0
bool Resource::store ( QSqlQuery &  queryItem,
QSqlQuery &  queryProperties 
) const

Store this resource in the sql database

Parameters
queryItemThe item that should be stored
queryPropertiesThe properties of the item that should be stored
Returns
true if stored succelful
QString Resource::toLocalFile ( bool  relative = false) const

Generates the path to the local file of this Resource (C://etc/etc/etc)

Parameters
relativeset to true if you want to generate the path relative to the current working directory
Returns
the path to the local file, returns sUNDEF if something goes wrong
QString Resource::toLocalFile ( const QUrl &  url,
bool  relative = false,
const QString &  ext = sUNDEF 
)
static

Creates a localfile path representing this Resource.
The url must be valid.

Parameters
urlThe location of the file
relativeset to true if you want a path relative to the workingcatalog
Returns
A Qurl to the file if succesful, or else a sUNDEF
QUrl Resource::url ( ) const

Query for the url of this Resource, the url points to the file used to created this Resource

Returns
An url to the file of this Resource
QUrlQuery Resource::urlQuery ( ) const

Gives access to the query when this Resource has been created with a url containing a query string. If there the url did not contain a query string the returned QUrlQuery is empty. This however can be checked via hasUrlQuery() beforehand.

Returns
the query part of the resource url.

The documentation for this class was generated from the following files: