35 int& numberOfEntities)
37 SHPHandle hSHP = SHPOpen(filename.c_str(),
"rb");
43 double padfMinBound[4];
44 double padfMaxBound[4];
49 SHPGetInfo(hSHP, &numberOfEntities, &shapeType, padfMinBound, padfMaxBound);
56 const std::string& listName,
57 std::string
const& gmsh_path)
61 double padfMinBound[4];
62 double padfMaxBound[4];
64 SHPHandle hSHP = SHPOpen(filename.c_str(),
"rb");
65 SHPGetInfo(hSHP, &numberOfElements, &shapeType, padfMinBound, padfMaxBound);
71 if (((shapeType - 1) % 10 == 0) &&
76 if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
81 if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
84 readPolygons(hSHP, numberOfElements, listName, gmsh_path);
91 if (numberOfElements > 0)
93 auto points = std::make_unique<std::vector<GeoLib::Point*>>();
94 SHPObject* hSHPObject;
96 for (
int i = 0; i < numberOfElements; i++)
98 hSHPObject = SHPReadObject(hSHP, i);
101 new GeoLib::Point(*(hSHPObject->padfX), *(hSHPObject->padfY),
102 *(hSHPObject->padfZ));
103 points->push_back(pnt);
107 SHPDestroyObject(hSHPObject);
112 std::string listName)
114 if (numberOfElements > 0)
116 auto stations = std::make_unique<std::vector<GeoLib::Point*>>();
117 stations->reserve(numberOfElements);
118 SHPObject* hSHPObject;
120 for (
int i = 0; i < numberOfElements; i++)
122 hSHPObject = SHPReadObject(hSHP, i);
125 *(hSHPObject->padfX),
126 *(hSHPObject->padfY),
127 *(hSHPObject->padfZ));
128 stations->push_back(stn);
132 SHPDestroyObject(hSHPObject);
137 std::string listName)
139 if (numberOfElements <= 0)
143 auto pnts = std::make_unique<std::vector<GeoLib::Point*>>();
144 auto lines = std::make_unique<std::vector<GeoLib::Polyline*>>();
146 std::size_t pnt_id(0);
148 for (
int i = 0; i < numberOfElements; ++i)
150 SHPObject* hSHPObject = SHPReadObject(hSHP, i);
151 int const noOfPoints = hSHPObject->nVertices;
152 int const noOfParts = hSHPObject->nParts;
154 for (
int p = 0; p < noOfParts; ++p)
156 int const firstPnt = *(hSHPObject->panPartStart + p);
157 int const lastPnt = (p < (noOfParts - 1))
158 ? *(hSHPObject->panPartStart + p + 1)
162 for (
int j = firstPnt; j < lastPnt; ++j)
165 *(hSHPObject->padfX + j), *(hSHPObject->padfY + j),
166 *(hSHPObject->padfZ + j), pnt_id));
170 SHPDestroyObject(hSHPObject);
175 std::vector<std::size_t>
const& pnt_id_map(points.
getIDMap());
178 for (
int i = 0; i < numberOfElements; ++i)
180 SHPObject* hSHPObject = SHPReadObject(hSHP, i);
181 int const noOfPoints = hSHPObject->nVertices;
182 int const noOfParts = hSHPObject->nParts;
184 for (
int p = 0; p < noOfParts; ++p)
187 if (noOfParts > 1 && p == 0)
190 "Polygon {:d} consists of {:d} parts (PolylineIDs "
192 i, noOfParts, lines->size(), lines->size() + noOfParts - 1);
195 int const firstPnt = *(hSHPObject->panPartStart + p);
196 int const lastPnt = (p < (noOfParts - 1))
197 ? *(hSHPObject->panPartStart + p + 1)
203 for (
int j = firstPnt; j < lastPnt; ++j)
205 line->addPoint(pnt_id_map[pnt_id]);
209 lines->push_back(line);
211 SHPDestroyObject(hSHPObject);
217 const std::string& listName,
218 std::string
const& gmsh_path)
224 for (
auto const* polyline : *polylines)
226 INFO(
"Creating a surface by triangulation of the polyline ...");
234 "\t Creating a surface by triangulation of the polyline "
245 ERR(
"SHPInterface::write2dMeshToSHP(): Mesh to Shape conversion is "
246 "only working for 2D Meshes.");
253 ERR(
"SHPInterface::write2dMeshToSHP(): Mesh contains no elements.");
260 std::size_t
const max_exp = 8;
261 if (n_elements >= std::pow(10, max_exp))
263 ERR(
"SHPInterface::write2dMeshToSHP(): Mesh contains too many elements "
264 "for currently implemented DBF-boundaries.");
268 SHPHandle hSHP = SHPCreate(file_name.c_str(), SHPT_POLYGON);
269 DBFHandle hDBF = DBFCreate(file_name.c_str());
270 int const elem_id_field =
271 DBFAddField(hDBF,
"Elem_ID", FTInteger, max_exp, 0);
274 std::size_t shp_record(0);
275 std::vector<MeshLib::Element*>
const& elems = mesh.
getElements();
283 SHPWriteObject(hSHP, -1,
object);
284 SHPDestroyObject(
object);
287 DBFWriteIntegerAttribute(hDBF, shp_record, elem_id_field,
295 int const n_recs = DBFGetRecordCount(hDBF);
300 int const field = DBFAddField(hDBF,
name.c_str(), FTInteger, 16, 0);
301 for (
int i = 0; i < n_recs; ++i)
303 std::size_t
const elem_idx =
304 DBFReadIntegerAttribute(hDBF, i, elem_id_field);
305 DBFWriteIntegerAttribute(hDBF, i, field, (*p)[elem_idx]);
311 int const field = DBFAddField(hDBF,
name.c_str(), FTDouble, 33, 16);
312 for (
int i = 0; i < n_recs; ++i)
314 std::size_t
const elem_idx =
315 DBFReadIntegerAttribute(hDBF, i, elem_id_field);
316 DBFWriteDoubleAttribute(hDBF, i, field, (*p)[elem_idx]);
321 INFO(
"Shape export of 2D mesh '{:s}' finished.", mesh.
getName());
326 std::size_t
const shp_record)
329 double* padfX =
new double[nNodes + 1];
330 double* padfY =
new double[nNodes + 1];
331 double* padfZ =
new double[nNodes + 1];
332 for (
unsigned j = 0; j < nNodes; ++j)
339 padfX[nNodes] = (*e.
getNode(0))[0];
340 padfY[nNodes] = (*e.
getNode(0))[1];
341 padfZ[nNodes] = (*e.
getNode(0))[2];
344 return SHPCreateObject(SHPT_POLYGON, shp_record, 0,
nullptr,
nullptr,
345 nNodes + 1, padfX, padfY, padfZ,
nullptr);
Definition of analytical geometry functions.
Definition of the Element class.
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... args)
Definition of the Mesh class.
Definition of the Node class.
Definition of the PolyLine class.
Definition of the Quad class.
Implementation of the SHPInterface class.
Definition of the Tri class.
void readPolylines(const SHPHandle &hSHP, int numberOfElements, std::string listName)
Reads lines into a vector of Polyline objects.
static bool readSHPInfo(const std::string &filename, int &shapeType, int &numberOfEntities)
Reads the header of the shape file.
void readPoints(const SHPHandle &hSHP, int numberOfElements, std::string listName)
Reads points into a vector of Point objects.
OGSType
Connection between ESRI type system for shape files and OGS GeoLib.
void readStations(const SHPHandle &hSHP, int numberOfElements, std::string listName)
Reads points into a vector of Point objects and marks them as Station.
void readSHPFile(const std::string &filename, OGSType choice, const std::string &listName, std::string const &gmsh_path)
Reads data from the shape file.
GeoLib::GEOObjects & _geoObjects
static bool write2dMeshToSHP(const std::string &file_name, const MeshLib::Mesh &mesh)
static SHPObject * createShapeObject(MeshLib::Element const &e, std::size_t const shp_record)
Creates a shape object polygon out of a 2D mesh element.
void readPolygons(const SHPHandle &hSHP, int numberOfElements, const std::string &listName, std::string const &gmsh_path)
Reads lines into a vector of Polyline and Surface objects.
void addStationVec(std::unique_ptr< std::vector< Point * >> stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
const PointVec * getPointVecObj(const std::string &name) const
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
This class manages pointers to Points in a std::vector along with a name. It also handles the deletin...
const std::vector< std::size_t > & getIDMap() const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
A Station (observation site) is basically a Point with some additional information.
static Station * createStation(const std::string &line)
Creates a Station-object from information contained in a string (assuming the string has the right fo...
const std::vector< T * > * getVector() const
virtual const Node * getNode(unsigned idx) const =0
virtual unsigned getNumberOfBaseNodes() const =0
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
const std::string getName() const
Get name of the mesh.
Properties & getProperties()
std::size_t getNumberOfElements() const
Get the number of elements.
bool createSurface(GeoLib::Polyline const &ply, GeoLib::GEOObjects &geometries, std::string const &geometry_name, std::string const &gmsh_binary)
TemplateElement< PointRule1 > Point