44 #include <terralib_buildconfig.h> 50 #include <boost/filesystem.hpp> 78 #include <geos/triangulate/DelaunayTriangulationBuilder.h> 86 std::size_t ntri = results->getNumGeometries();
87 std::string gtype = results->getGeometryType();
90 geos::geom::Geometry *gout = results->clone();
92 tinout->
setSRID(results.get()->getSRID());
96 std::vector<std::string> pt_value;
101 for (std::size_t i = 0; i < gpol->
getNumRings(); ++i)
105 for (std::size_t j = 0; j < lr->
getNPoints(); ++j)
107 std::unique_ptr<te::gm::Point>
p = lr->
getPointN(j);
108 pt_value.push_back(p->toString());
111 dataSetItem->
setInt32(
"TIN_ID", id_tri++);
112 dataSetItem->
setString(
"Pt1", pt_value[0]);
113 dataSetItem->
setString(
"Pt2", pt_value[1]);
114 dataSetItem->
setString(
"Pt3", pt_value[2]);
117 ds->
add(dataSetItem);
123 void SaveTIN_shp(std::string dir, std::string out, std::unique_ptr<geos::geom::Geometry> results)
134 prop4->
setSRID(results.get()->getSRID());
141 std::unique_ptr<te::da::DataSet> dataset(
create_ds_memory(out, dt.get(), std::move(results)));
143 std::string filename(dir);
144 filename.append(out);
145 filename.append(
".shp");
155 dataset->moveBeforeFirst();
167 std::string &geostype, std::string atributo)
170 double tol = 0.00018000000;
171 double maxdist = 20.*tol;
172 double minedge = tol / 5.;
181 te::da::DataSet* inDset = (datasource->getDataSet(datasetNames[0])).release();
184 const std::size_t ng = inDset->
size();
187 std::vector<std::string>pnames;
188 std::vector<int> ptypes;
189 for (std::size_t i = 0; i != np; ++i)
200 std::unique_ptr<te::gm::Geometry> gin = inDset->
getGeometry(
"OGR_GEOMETRY");
202 geostype = gin.get()->getGeometryType();
204 if (geostype ==
"MultiPoint")
208 double value = inDset->
getDouble(atributo);
209 for (std::size_t i = 0; i < np; ++i)
214 mpt.
add(dynamic_cast<te::gm::Geometry*>(pz.clone()));
217 if (geostype ==
"LineString")
220 double value = inDset->
getDouble(atributo);
221 isolines.
add(dynamic_cast<te::gm::Geometry*>(l->
clone()));
225 for (std::size_t j = 0; j < ls->
getNPoints(); ++j)
230 if (geostype ==
"MultiLineString")
234 double value = inDset->
getDouble(atributo);
235 for (std::size_t i = 0; i < np; ++i)
239 for (std::size_t il = 0; il < l->
size(); il++)
243 isolines.
add(dynamic_cast<te::gm::Geometry*>(lz));
247 for (std::size_t j = 0; j < ls->
getNPoints(); ++j)
252 isolines_simp.add(dynamic_cast<te::gm::Geometry*>(ls));
267 double tol = 0.00018000000;
268 double maxdist = 20.*tol;
269 double minedge = tol / 5.;
271 const geos::geom::GeometryFactory *geomFact = te::gm::GEOSGeometryFactory::getGeomFactory();
274 std::string geostype;
277 std::string filename(TERRALIB_DATA_DIR
"/mnt/Isolinhas.shp");
279 LoadIsolines(filename, mpt, isolines_simp, geostype,
"avg_z");
283 geos::triangulate::DelaunayTriangulationBuilder *tri =
new geos::triangulate::DelaunayTriangulationBuilder();
285 std::unique_ptr<geos::geom::Geometry> results;
287 tri->setTolerance(minedge);
290 std::string dirout(TERRALIB_DATA_DIR
"/mnt/");
291 std::string fileout(
"Isolinhas_GEOS_TIN");
294 results = tri->getTriangles(*geomFact);
295 results.get()->setSRID(SRID);
307 std::string filename_iso(TERRALIB_DATA_DIR
"/mnt/Isolinhas.shp");
308 std::string filename_pts(TERRALIB_DATA_DIR
"/mnt/Pontos_cotados.shp");
312 double maxdist = 20.*tol;
313 double minedge = tol / 5.;
314 std::string atributoz_iso(
"Avg_Z");
315 std::string atributoz_sample(
"Avg_Z");
320 std::string inDsetNameiso =
"Isolinhas";
321 if (!srcDsiso->dataSetExists(inDsetNameiso))
323 std::cout <<
"Input dataset not found: " << inDsetNameiso << std::endl;
327 std::unique_ptr<te::da::DataSetType> inDsetTypeiso(srcDsiso->getDataSetType(inDsetNameiso));
332 std::string inDsetNamepts =
"Pontos_cotados";
333 if (!srcDspts->dataSetExists(inDsetNamepts))
335 std::cout <<
"Input dataset not found: " << inDsetNamepts << std::endl;
339 std::unique_ptr<te::da::DataSetType> inDsetTypepts(srcDspts->getDataSetType(inDsetNamepts));
341 std::string file_result = TERRALIB_DATA_DIR
"/mnt/TIN.shp";
351 std::string outDS =
"TIN";
358 Tin->
setParams(tol, maxdist, minedge, atributoz_iso, atributoz_sample);
361 bool result = Tin->
run();
372 std::string filename = TERRALIB_DATA_DIR
"/mnt/TIN.shp";
377 std::vector<double> val;
378 std::vector<double> gval;
379 for (
double n = 1010; n <= 1180; n += 10)
385 std::string inDsetName =
"TIN";
386 if (!srcDs->dataSetExists(inDsetName))
388 std::cout <<
"Input dataset not found: " << inDsetName << std::endl;
392 std::unique_ptr<te::da::DataSet> inDset = srcDs->getDataSet(inDsetName);
393 std::unique_ptr<te::da::DataSetType> inDsetType(srcDs->getDataSetType(inDsetName));
395 std::string file_result = TERRALIB_DATA_DIR
"/mnt/TIN_iso.shp";
404 std::string outDS =
"TIN_iso";
408 Tin->
setInput(srcDs, inDsetName, std::move(inDsetType));
413 bool result = Tin->
run();
424 std::string filename = TERRALIB_DATA_DIR
"/mnt/TIN.shp";
428 double resx = 30, resy = 30;
433 std::string inDsetName =
"TIN";
434 if (!srcDs->dataSetExists(inDsetName))
436 std::cout <<
"Input dataset not found: " << inDsetName << std::endl;
440 std::unique_ptr<te::da::DataSet> inDset = srcDs->getDataSet(inDsetName);
441 std::unique_ptr<te::da::DataSetType> inDsetType(srcDs->getDataSetType(inDsetName));
443 boost::filesystem::path uri(TERRALIB_DATA_DIR
"/mnt/TIN_GRD_quint1.tif");
444 std::string dsName =
"TIN_GRD_quint";
455 if (dsOGR->dataSetExists(dsName))
457 std::cout <<
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.";
462 std::map<std::string, std::string> options;
463 options[
"URI"] = uri.string();
465 Tin->
setInput(srcDs, inDsetName, std::move(inDsetType));
470 bool result = Tin->
run();
480 std::string filename_iso(TERRALIB_DATA_DIR
"/mnt/Isolinhas.shp");
481 std::string filename_pts(TERRALIB_DATA_DIR
"/mnt/Pontos_cotados.shp");
482 std::string atributoz_iso(
"Avg_Z");
483 std::string atributoz_sample(
"Avg_Z");
487 double resx = 30, resy = 30;
492 std::string inDsetNameiso =
"Isolinhas";
493 if (!srcDsiso->dataSetExists(inDsetNameiso))
495 std::cout <<
"Input dataset not found: " << inDsetNameiso << std::endl;
499 std::unique_ptr<te::da::DataSet> inDsetiso = srcDsiso->getDataSet(inDsetNameiso);
500 std::unique_ptr<te::da::DataSetType> inDsetTypeiso(srcDsiso->getDataSetType(inDsetNameiso));
505 std::string inDsetNamepts =
"Pontos_cotados";
506 if (!srcDspts->dataSetExists(inDsetNamepts))
508 std::cout <<
"Input dataset not found: " << inDsetNamepts << std::endl;
512 std::unique_ptr<te::da::DataSet> inDsetpts = srcDspts->getDataSet(inDsetNamepts);
513 std::unique_ptr<te::da::DataSetType> inDsetTypepts(srcDspts->getDataSetType(inDsetNamepts));
515 boost::filesystem::path uri(TERRALIB_DATA_DIR
"/mnt/IsoPts_GRD.tif");
516 std::string dsName =
"IsoPts_GRD";
526 if (dsOGR->dataSetExists(dsName))
528 std::cout <<
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.";
535 std::map<std::string, std::string> options;
536 options[
"URI"] = uri.string();
543 bool result = grid->
run();
554 std::string filename = TERRALIB_DATA_DIR
"/mnt/TIN_GRD_quint1.tif";
560 double m_dummy = std::numeric_limits<double>::max();
561 bool m_hasDummy =
false;
563 std::vector<double> val;
564 std::vector<double> gval;
565 for (
double n = m_min; n <= m_max; n += 20)
571 std::string inDsetName =
"TIN_GRD_quint1.tif";
572 std::unique_ptr<te::da::DataSetType> inDsetType(srcDs->getDataSetType(inDsetName));
574 std::string file_result = TERRALIB_DATA_DIR
"/mnt/TIN_GRD_quint1_iso.shp";
583 std::string outDS =
"TIN_GRD_quint1_iso";
587 ci->
setInput(srcDs, inDsetName, std::move(inDsetType));
589 ci->
setParams(val, gval, m_max, m_min, m_dummy, m_hasDummy);
591 bool result = ci->
run(std::move(raster));
623 catch(
const std::exception& e)
625 std::cout << std::endl <<
"An exception has occurred: " << e.what() << std::endl;
630 std::cout << std::endl <<
"An unexpected exception has occurred!" << std::endl;
virtual std::vector< std::string > getDataSetNames()=0
It It gets the dataset names available in the data source.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType, InputType type)
It sets the Datasource that is being used to generate TIN.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType)
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
void setParams(std::vector< double > &val, std::vector< double > &gval, double tol)
te::da::DataSet * create_ds_memory(const std::string &datasetName, te::da::DataSetType *datasettype, std::unique_ptr< geos::geom::Geometry > results)
Class to generate isolines from TIN.
This file contains a class to generate isolines from a TIN. Adapted from SPRING.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
The global factory used by TerraLib in order to create GEOS geometries.
An utility class to control the startup and cleanup of the TerraLib Platform and its resources...
Include files for Core Plugin Library.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
bool run()
Calculate GRID \ return true or false.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
virtual te::dt::AbstractData * clone() const
It clones the linestring.
bool run()
Method that generates a regular Grid from a given TIN.
It models a property definition.
A point with x and y coordinate values.
std::unique_ptr< Point > getPointN(std::size_t i) const
It returns the specified point in this LineString.
Examples on how to access/manipulate a specified DatasOURCE.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
It sets the Datasource that is being used to save TIN.
static te::dt::Date ds(2010, 01, 01)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
const double & getY(std::size_t i) const
It returns the n-th y coordinate value.
Utility functions for MNT support.
virtual std::size_t size() const =0
It returns the collection size, if it is known.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
A LinearRing is a LineString that is both closed and simple.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void setParams(std::vector< double > &nval, std::vector< double > &gval, double vmax, double vmin, double dummy, bool hasDummy)
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
static PluginManager & instance()
Access the singleton.
MultiPoint is a GeometryCollection whose elements are restricted to points.
void setParams(const std::string &attriso, const std::string &attrpt, double resx, double resy, Interpolator gt, double rad, int pow)
It sets the parameters that is being used to save TIN.
An Envelope defines a 2D rectangular region.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
LineString is a curve with linear interpolation between points.
static bool remove(const std::string &path)
Removes a file or directory from a given path in UTF-8.
void finalize()
It finalizes the TerraLib Platform.
const double & getY() const
It returns the Point y-coordinate value.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
A point with x and y coordinate values.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
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...
Class to calculate grid from TIN.
TEMNTEXPORT te::gm::LineString * pointListSimplify(te::gm::LineString *ls, double snap, double maxdist, double Zvalue)
const double & getX(std::size_t i) const
It returns the n-th x coordinate value.
A class for handling system files and paths.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
A factory for data sources.
This file contains a class to generate TIN. Adapted from SPRING.
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
virtual AbstractData * clone() const =0
It returns a clone of this object.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
The type for string types: FIXED_STRING, VAR_STRING or STRING.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
void setPointZ(std::size_t i, const double &x, const double &y, const double &z)
It sets the value of the specified point.
Utility functions for the data access module.
static geos::geom::Geometry * write(const Geometry *teGeom)
It reads a TerraLib geometry and make a GEOS geometry.
A class that converts a GEOS geometry to a TerraLib geometry.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A class that converts a TerraLib geometry to a GEOS geometry.
void initialize()
It initializes the TerraLib Platform.
TIN (triangulated irregular network) is a PolyhedralSurface consisting only of Triangle patches...
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
void SaveTIN_shp(std::string dir, std::string out, std::unique_ptr< geos::geom::Geometry > results)
MultiLineString is a MultiCurve whose elements are LineStrings.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
A dataset is the unit of information manipulated by the data access module of TerraLib.
This file contains a class to calculate retangular grid from Samples. Adapted from SPRING...
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
void setSRID(int srid)
It sets the Spatial Reference System ID of the geometry collection and all its parts.
This file contains a class to calculate a grid from a TIN. Adapted from SPRING.
bool run()
Generate TIN \ return true or false.
bool run(std::unique_ptr< te::rst::Raster > raster)
This file contains utility functions used to manipulate data from a URI.
void add(Geometry *g)
It adds the geometry into the collection.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType)
It sets the Datasource that is being used to generate TIN.
An atomic property like an integer or double.
void setOutput(std::map< std::string, std::string > &dsinfo)
It sets the Datasource that is being used to save TIN.
void setSRID(int srid)
It sets the Spatial Reference System ID of the linestring.
virtual std::size_t getNPoints() const _NOEXCEPT_OP(true)=0
it returns the number of points (vertexes) in the geometry.
A class for representing an Uniform Resource Identifier (URI).
std::unique_ptr< te::rst::Raster > getPrepareRaster()
void setParams(double resx, double resy, Interpolator gt)
It sets the parameters that is being used to save TIN.
LineString is a curve with linear interpolation between points.
void LoadIsolines(const std::string &filename, te::gm::MultiPoint &mpt, te::gm::MultiLineString &isolines, std::string &geostype, std::string atributo)
void setOutput(std::map< std::string, std::string > &dsinfo)
It sets the Datasource that is being used to save TIN.
void setInput(te::da::DataSourcePtr inRasterDsrc, std::string inRasterName, std::unique_ptr< te::da::DataSetType > inDsetType)
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType, InputType type)
It sets the Datasource that is being used to generate TIN.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
void clear()
Stop and unload all plugins, then clear the internal list of plugins.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
It is a collection of other geometric objects.
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
void LoadModules()
Load terralib modules.
const double & getX() const
It returns the Point x-coordinate value.
void setParams(const double &tolerance, const double &maxdist, const double &minedgesize, const std::string &atrz_iso, const std::string &atrz_pt)
It sets the parameters to generate TIN.
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
void setZ(const double &z)
It sets the Point z-coordinate value.
std::size_t size() const
It returns the number of points (vertexes) in the geometry.