27 #include "../../../../core/filesystem/FileSystem.h" 28 #include "../../../../common/StringUtils.h" 29 #include "../../../../dataaccess/datasource/DataSource.h" 30 #include "../../../../dataaccess/datasource/DataSourceFactory.h" 31 #include "../../../../dataaccess/datasource/DataSourceTransactor.h" 32 #include "../../../../dataaccess/dataset/DataSetAdapter.h" 33 #include "../../../../dataaccess/dataset/DataSetTypeConverter.h" 34 #include "../../../../dataaccess/utils/Utils.h" 35 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h" 36 #include "../../../../datatype/SimpleData.h" 37 #include "../../../../geometry/GeometryProperty.h" 38 #include "../../../../gdal/Utils.h" 39 #include "../../../../maptools/DataSetLayer.h" 40 #include "../../../../memory/DataSet.h" 41 #include "../../../../memory/DataSetItem.h" 42 #include "../../../../raster/Interpolator.h" 43 #include "../../../../raster/RasterFactory.h" 44 #include "../../../../rp/Functions.h" 45 #include "../../../../rp/RasterHandler.h" 46 #include "../core/form/Serializer.h" 47 #include "../geopackage/Utils.h" 51 #include <boost/uuid/random_generator.hpp> 52 #include <boost/uuid/uuid_io.hpp> 57 int inputSRID = layer->getSRID();
58 int outputSRID = 4326;
71 std::vector<te::dt::Property* > props = dsTypeResult->
getProperties();
72 std::map<std::size_t, std::string> invalidNames;
73 for (std::size_t i = 0; i < props.size(); ++i)
77 invalidNames[i] = props[i]->getName();
81 if (!invalidNames.empty())
83 std::map<std::size_t, std::string>::iterator it = invalidNames.begin();
84 while (it != invalidNames.end())
89 props[it->first]->setName(newName);
96 std::map<std::string, std::string> nopt;
100 if (dataset->moveBeforeFirst())
108 std::auto_ptr<te::rst::Raster> raster = dataset->getRaster(rpos);
110 bool extValid = extent.
isValid();
111 int inputSRID = raster->getSRID();
112 int bandType = raster->getBandDataType(0);
113 int multiResLevel = raster->getMultiResLevelsCount();
121 std::map<std::string, std::string> connInfo = info->getConnInfo();
122 std::string uri = connInfo[
"SOURCE"];
127 std::map<std::string, std::string> rinfo;
128 rinfo[
"SOURCE"] = uri;
129 rinfo[
"FORCE_MEM_DRIVER"] =
"TRUE";
135 if (inputSRID != 4326 || extValid)
137 if (extValid && raster->getExtent()->contains(extent) && (inputSRID != 4326))
139 else if (extValid && raster->getExtent()->contains(extent))
142 raster.reset(raster->transform(4326, rinfo));
147 size_t bands = raster->getNumberOfBands();
149 std::vector< te::rst::BandProperty* > bandsProperties;
151 for (bandIdx = 0; bandIdx <
bands; ++bandIdx)
156 *(raster->getBand(bandIdx)->getProperty())));
173 const unsigned int inNRows = raster->getNumberOfRows();
174 const unsigned int inNCols = raster->getNumberOfColumns();
176 for (bandIdx = 0; bandIdx < bandsProperties.size(); ++bandIdx)
181 for (row = 0; row < inNRows; ++row)
183 for (col = 0; col < inNCols; ++
col)
187 band.
getValue((
unsigned int)col, (
unsigned int)row, value);
188 outRaster->setValue((
unsigned int)col, (
unsigned int)row, value, bandIdx);
199 if (multiResLevel > 0)
215 std::map<std::string, std::string> connInfo;
216 connInfo[
"URI"] = gpkgName;
219 dsGPKG->setConnectionInfo(connInfo);
225 std::string sql1 =
"CREATE TABLE IF NOT EXISTS tm_layer_settings";
226 sql1 +=
"(layer_name TEXT PRIMARY KEY NOT NULL, enabled BOOLEAN NOT NULL, position INTEGER NOT NULL UNIQUE, datasource_uri TEXT, modified INTEGER NOT NULL DEFAULT(0), ";
227 sql1 +=
"CONSTRAINT fk_layer_name FOREIGN KEY(LAYER_NAME) REFERENCES gpkg_contents(table_name)); ";
230 std::string sql2 =
"CREATE TABLE IF NOT EXISTS tm_style(layer_name TEXT PRIMARY KEY NOT NULL, sld_xml TEXT); ";
233 std::string sql3 =
"CREATE TABLE IF NOT EXISTS tm_layer_form ";
234 sql3 +=
"(tm_conf_id INTEGER PRIMARY KEY AUTOINCREMENT, gpkg_layer_identify TEXT NOT NULL, tm_form TEXT, tm_media_table TEXT, ";
235 sql3 +=
"CONSTRAINT fk_layer_identify_id FOREIGN KEY (gpkg_layer_identify) REFERENCES gpkg_contents(table_name));";
238 std::string sql4 =
"CREATE TABLE IF NOT EXISTS tm_settings(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, key TEXT, value TEXT); ";
250 std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
251 std::auto_ptr<te::da::DataSet> dataset;
254 if (dsType->hasRaster())
256 dataset = layer->getData();
262 std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
267 dataset = layer->getData(geomName, &extent);
270 dataset = layer->getData();
274 std::string name = dsType->getName();
276 std::string
insert =
"INSERT INTO tm_style ('layer_name', 'sld_xml' ) values('" + name +
"', '" + sldString +
"');";
289 double minValue = std::numeric_limits< double >::max();
290 double maxValue = std::numeric_limits< double >::min();
296 std::vector<size_t> colorbands;
298 for (bandIdx = 0; bandIdx <
bands; ++bandIdx)
307 colorbands.push_back(bandIdx);
311 for (bandIdx = 0; bandIdx < colorbands.size(); ++bandIdx)
316 for (row = 0; row < inNRows; ++row)
318 for (col = 0; col < inNCols; ++
col)
320 band.
getValue((
unsigned int)col, (
unsigned int)row, value);
321 if (value != noDataValue)
323 if (value < minValue)
326 if (value > maxValue)
333 double gain = (double)(nmax - nmin) / (maxValue - minValue);
334 double offset = -1 * gain*minValue + nmin;
337 std::vector<te::rst::BandProperty*> bandsProperties;
339 for (bandIdx = 0; bandIdx < colorbands.size(); ++bandIdx)
345 bandsProperties.push_back(bandProp);
353 for (bandIdx = 0; bandIdx < colorbands.size(); ++bandIdx)
359 for (row = 0; row < inNRows; ++row)
361 for (col = 0; col < inNCols; ++
col)
365 band.
getValue((
unsigned int)col, (
unsigned int)row, value);
367 if (value == noDataValue)
369 rasterNormalized->
setValue((
unsigned int)col, (
unsigned int)row, value, bandIdx);
373 double normalizeValue = (value * gain + offset);
374 rasterNormalized->
setValue((
unsigned int)col, (
unsigned int)row, normalizeValue, bandIdx);
385 std::auto_ptr<te::rst::Raster> rOut(rasterNormalized);
392 std::auto_ptr<te::da::DataSourceTransactor> transactor = dsGPKG->
getTransactor();
396 transactor->execute(query);
400 transactor->rollBack();
407 std::auto_ptr<te::da::DataSourceTransactor> transactor = dsGPKG->
getTransactor();
408 std::vector<std::string> names;
410 std::string select =
"SELECT name FROM sqlite_master WHERE type = '" + type +
"' AND name LIKE 'rtree%'; ";
412 std::auto_ptr<te::da::DataSet> tupleNames;
414 tupleNames = transactor->query(select);
416 tupleNames->moveBeforeFirst();
418 while (tupleNames->moveNext())
420 std::string trigger = tupleNames->getString(
"name");
421 names.push_back(trigger);
429 std::auto_ptr<te::da::DataSetType> dsType = ds->
getDataSetType(dataSetName);
433 std::auto_ptr<te::da::DataSet> dataSet = ds->
getDataSet(dataSetName);
435 dataSet->moveBeforeFirst();
437 while (dataSet->moveNext())
441 for (std::size_t t = 0; t < dataSet->getNumProperties(); ++t)
445 if (dataSet->isNull(t))
448 boost::uuids::basic_random_generator<boost::mt19937> gen;
449 boost::uuids::uuid u = gen();
450 std::string id_ds = boost::uuids::to_string(u);
465 dsItem->
setValue(dataSet->getPropertyName(t), dataSet->getValue(t).release());
468 dataSetMem->
add(dsItem);
471 std::vector<size_t> ids;
474 std::vector< std::set<int> > properties;
475 std::size_t dsSize = dataSetMem->
size();
477 for (std::size_t t = 0; t < dsSize; ++t)
479 std::set<int> setPos;
492 properties.push_back(setPos);
495 ds->
update(dataSetName, dataSetMem, properties, ids);
Property * getProperty(std::size_t i) const
It returns the i-th property.
std::size_t size() const
It returns the collection size, if it is known.
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
virtual bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
TERRAMOBILEPLUGINSDLLEXPORT void copyToGeopackage(te::rst::Raster *raster, std::string outFileName)
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Near neighborhood interpolation method.
std::string WriteStyle(const te::se::Style *style, std::string path="style.xml")
Alpha channel color interpretation.
virtual std::unique_ptr< DataSourceTransactor > getTransactor()=0
It returns the set of parameters used to set up the access channel to the underlying repository...
static bool isDirectory(const std::string &path)
Checks if a given path in UTF-8 is a directory.
Index into a lookup table.
void exportVectortoGPKG(te::map::AbstractLayerPtr layer, te::da::DataSource *dsGPKG, te::da::DataSetType *dataType, std::auto_ptr< te::da::DataSet > dataset, std::string outFileName)
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
ColorInterp
Color model component use.
A raster band description.
A class that models the description of a dataset.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
void queryGPKG(std::string query, te::da::DataSource *dsGPKG)
std::vector< std::string > getItemNames(std::string type, te::da::DataSource *dsGPKG)
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
DataSetType * getResult() const
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
Red channel color interpretation.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
std::auto_ptr< te::da::DataSource > createGeopackage(std::string gpkgName)
std::string ReplaceSpecialChars(const std::string &str, bool &changed)
It replace special characters of a string.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
virtual te::core::EncodingType getEncoding()
It return the DataSource current encoding.
An converter for DataSetType.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void setName(const std::string &name)
It sets the property name.
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
static std::string absolutePath(const std::string &path)
Retrives the absolute path for the given path in UTF-8.
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
static bool remove(const std::string &path)
Removes a file or directory from a given path in UTF-8.
void exportToGPKG(te::map::AbstractLayerPtr layer, te::da::DataSource *dsGPKG, std::string outFileName, const te::gm::Envelope extent)
void exportRastertoGPKG(te::map::AbstractLayerPtr layer, te::da::DataSource *dsGPKG, std::auto_ptr< te::da::DataSet > dataset, std::string outFileName, const te::gm::Envelope extent)
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
BandProperty * getProperty()
Returns the band property.
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
Utility functions for the data access module.
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
void fillExtraColumns(te::da::DataSource *ds, std::string dataSetName)
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
std::string getPropertyName(std::size_t pos) const
It returns the property name at position pos.
#define LAYER_GATHERING_STATUS_COLUMN
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
const std::string & getDataSetName() const
void remove(const std::string &propertyName)
This method removes a property of DataSetTypeConverter.
static Raster * make()
It creates and returns an empty raster with default raster driver.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
#define LAYER_GATHERING_OBJID_COLUMN
te::rst::Raster * getRasterPtr()
Returns a pointer the the handled raster instance or NULL if no instance is handled.
A layer with reference to a dataset.
bool CreateNewGdalRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, const std::string &fileName, RasterHandler &outRasterHandler)
Create a new raster into a GDAL datasource.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
A template for atomic data types (integers, floats, strings and others).
Blue channel color interpretation.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
A rectified grid is the spatial support for raster data.
Green channel color interpretation.
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
ColorInterp m_colorInterp
The color interpretation.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual void update(const std::string &datasetName, DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
std::auto_ptr< te::rst::Raster > NormalizeRaster(te::rst::Raster *inraster, double nmin, double nmax, std::map< std::string, std::string > rInfo, std::string type)
virtual const std::string & getDataSourceId() const
TERRAMOBILEPLUGINSDLLEXPORT void createGeopackage(std::string outFileName)
bool isValid() const
It tells if the rectangle is valid or not.
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
const std::string & getName() const
It returns the property name.