32 int& numberOfEntities)
34 SHPHandle hSHP = SHPOpen(filename.c_str(),
"rb");
40 double padfMinBound[4];
41 double padfMaxBound[4];
46 SHPGetInfo(hSHP, &numberOfEntities, &shapeType, padfMinBound, padfMaxBound);
53 const std::string& listName,
54 std::string
const& gmsh_path)
58 double padfMinBound[4];
59 double padfMaxBound[4];
61 SHPHandle hSHP = SHPOpen(filename.c_str(),
"rb");
62 SHPGetInfo(hSHP, &numberOfElements, &shapeType, padfMinBound, padfMaxBound);
68 if (((shapeType - 1) % 10 == 0) &&
73 if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
78 if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
81 readPolygons(hSHP, numberOfElements, listName, gmsh_path);
88 if (numberOfElements > 0)
90 std::vector<GeoLib::Point*> points;
91 SHPObject* hSHPObject;
93 for (
int i = 0; i < numberOfElements; i++)
95 hSHPObject = SHPReadObject(hSHP, i);
99 *(hSHPObject->padfZ));
100 points.push_back(pnt);
105 SHPDestroyObject(hSHPObject);
110 std::string listName)
112 if (numberOfElements > 0)
114 std::vector<GeoLib::Point*> stations;
115 stations.reserve(numberOfElements);
116 SHPObject* hSHPObject;
118 for (
int i = 0; i < numberOfElements; i++)
120 hSHPObject = SHPReadObject(hSHP, i);
123 *(hSHPObject->padfX),
124 *(hSHPObject->padfY),
125 *(hSHPObject->padfZ));
126 stations.push_back(stn);
130 SHPDestroyObject(hSHPObject);
135 std::string listName)
137 if (numberOfElements <= 0)
141 std::vector<GeoLib::Point*> pnts;
142 std::vector<GeoLib::Polyline*> lines;
144 std::size_t pnt_id(0);
146 for (
int i = 0; i < numberOfElements; ++i)
148 SHPObject* hSHPObject = SHPReadObject(hSHP, i);
149 int const noOfPoints = hSHPObject->nVertices;
150 int const noOfParts = hSHPObject->nParts;
152 for (
int p = 0; p < noOfParts; ++p)
154 int const firstPnt = *(hSHPObject->panPartStart + p);
155 int const lastPnt = (p < (noOfParts - 1))
156 ? *(hSHPObject->panPartStart + p + 1)
160 for (
int j = firstPnt; j < lastPnt; ++j)
163 *(hSHPObject->padfX + j), *(hSHPObject->padfY + j),
164 *(hSHPObject->padfZ + j), pnt_id));
168 SHPDestroyObject(hSHPObject);
174 std::vector<std::size_t>
const& pnt_id_map(points.
getIDMap());
177 for (
int i = 0; i < numberOfElements; ++i)
179 SHPObject* hSHPObject = SHPReadObject(hSHP, i);
180 int const noOfPoints = hSHPObject->nVertices;
181 int const noOfParts = hSHPObject->nParts;
183 for (
int p = 0; p < noOfParts; ++p)
186 if (noOfParts > 1 && p == 0)
189 "Polygon {:d} consists of {:d} parts (PolylineIDs "
191 i, noOfParts, lines.size(), lines.size() + noOfParts - 1);
194 int const firstPnt = *(hSHPObject->panPartStart + p);
195 int const lastPnt = (p < (noOfParts - 1))
196 ? *(hSHPObject->panPartStart + p + 1)
202 for (
int j = firstPnt; j < lastPnt; ++j)
204 line->addPoint(pnt_id_map[pnt_id]);
208 lines.push_back(line);
210 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);
301 DBFAddField(hDBF, std::string(name).c_str(), FTInteger, 16, 0);
302 for (
int i = 0; i < n_recs; ++i)
304 std::size_t
const elem_idx =
305 DBFReadIntegerAttribute(hDBF, i, elem_id_field);
306 DBFWriteIntegerAttribute(hDBF, i, field, (*p)[elem_idx]);
313 DBFAddField(hDBF, std::string(name).c_str(), FTDouble, 33, 16);
314 for (
int i = 0; i < n_recs; ++i)
316 std::size_t
const elem_idx =
317 DBFReadIntegerAttribute(hDBF, i, elem_id_field);
318 DBFWriteDoubleAttribute(hDBF, i, field, (*p)[elem_idx]);
323 INFO(
"Shape export of 2D mesh '{:s}' finished.", mesh.
getName());
328 std::size_t
const shp_record)
331 double* padfX =
new double[nNodes + 1];
332 double* padfY =
new double[nNodes + 1];
333 double* padfZ =
new double[nNodes + 1];
334 for (
unsigned j = 0; j < nNodes; ++j)
341 padfX[nNodes] = (*e.
getNode(0))[0];
342 padfY[nNodes] = (*e.
getNode(0))[1];
343 padfZ[nNodes] = (*e.
getNode(0))[2];
346 return SHPCreateObject(SHPT_POLYGON, shp_record, 0,
nullptr,
nullptr,
347 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(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... 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 Station 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 addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const PointVec * getPointVecObj(const std::string &name) const
void addStationVec(std::vector< Point * > &&stations, std::string &name)
Adds a vector of stations with the given name and colour to GEOObjects.
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
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)
std::map< std::string, std::size_t > NameIdMap
std::vector< T * > const & getVector() const
virtual unsigned getNumberOfBaseNodes() const =0
virtual const Node * getNode(unsigned idx) const =0
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Properties & getProperties()
const std::string getName() const
Get name of the mesh.
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)