CreatingDataSetTypeInMemory.cpp
Go to the documentation of this file.
1 // Examples
2 #include "DataAccessExamples.h"
3 
4 // TerraLib
5 #include <terralib/dataaccess.h>
6 #include <terralib/datatype.h>
7 #include <terralib/geometry.h>
8 
9 te::da::DataSetType* CreateDataSetTypeInMemory(const std::string& datasettypename)
10 {
11  //============= (1) Create a new data set type in memory
12 
13  //te::da::DataSetType* dt = new te::da::DataSetType("SoilMeasures");
14  te::da::DataSetType* dt = new te::da::DataSetType(datasettypename);
15 
16  //first property: measure_id
18  prop01->setAutoNumber(true);
19 
20  //second property: sensor_id
22 
23  //third property: location
24  te::gm::GeometryProperty* prop03 = new te::gm::GeometryProperty("location", 0, te::gm::PointType, true);
25  prop03->setSRID(4326);
26 
27  //fourth property: measure_date
29 
30  //fifth property: measure_value
31  te::dt::NumericProperty* prop05 = new te::dt::NumericProperty("value", 7, 4, true);
32 
33  //add properties into data set type
34  dt->add(prop01);
35  dt->add(prop02);
36  dt->add(prop03);
37  dt->add(prop04);
38  dt->add(prop05);
39 
40  //define a primary key
41  std::string namepk = datasettypename+ "_pk";
42  te::da::PrimaryKey* pk = new te::da::PrimaryKey(namepk, dt);
43  pk->add(prop01);
44 
45  //define a check constraint
46  te::da::CheckConstraint* cc = new te::da::CheckConstraint("measurevaluecc", dt);
47  cc->setExpression("measure_value>0");
48 
49  //create index
50  te::da::Index* index01 = new te::da::Index("measure_date_idx", te::da::B_TREE_TYPE, dt);
51  index01->add(prop04);
52 
53  //create spatial index
54  te::da::Index* index02 = new te::da::Index("measure_location_idx", te::da::R_TREE_TYPE, dt);
55  index02->add(prop03);
56 
57  return dt;
58 }
59 
This file contains include headers for the Data Type module of TerraLib.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Geometric property.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
An atomic property like an integer or double.
A class that models the description of a dataset.
Definition: DataSetType.h:72
te::da::DataSetType * CreateDataSetTypeInMemory(const std::string &datasettypename)
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
A class that describes a check constraint.
The type for arbitrary precison numbers, like numeric(p, q).
Examples on how to access/manipulate DataSources in TerraLib.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void add(Constraint *c)
It adds a new constraint.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void setExpression(const std::string &e)
It sets the check constraint expression.
The type for date and time types: date, date period, date duration, time duration, time instant, time period, time instant with time zone or time period with time zone.
This file contains include headers for the Vector Geometry model of TerraLib.
This file contains include headers for the Data Access module of TerraLib.
It describes an index associated to a DataSetType.