22 int& numberOfEntities)
24 SHPHandle hSHP = SHPOpen(filename.c_str(),
"rb");
30 double padfMinBound[4];
31 double padfMaxBound[4];
36 SHPGetInfo(hSHP, &numberOfEntities, &shapeType, padfMinBound, padfMaxBound);
43 const std::string& listName,
44 std::string
const& gmsh_path)
48 double padfMinBound[4];
49 double padfMaxBound[4];
51 SHPHandle hSHP = SHPOpen(filename.c_str(),
"rb");
52 SHPGetInfo(hSHP, &numberOfElements, &shapeType, padfMinBound, padfMaxBound);
58 if (((shapeType - 1) % 10 == 0) &&
63 if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
68 if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
71 readPolygons(hSHP, numberOfElements, listName, gmsh_path);
78 if (numberOfElements > 0)
80 std::vector<GeoLib::Point*> points;
81 SHPObject* hSHPObject;
83 for (
int i = 0; i < numberOfElements; i++)
85 hSHPObject = SHPReadObject(hSHP, i);
89 *(hSHPObject->padfZ));
90 points.push_back(pnt);
93 _geoObjects.addPointVec(std::move(points), listName,
95 SHPDestroyObject(hSHPObject);
100 std::string listName)
102 if (numberOfElements > 0)
104 std::vector<GeoLib::Point*> stations;
105 stations.reserve(numberOfElements);
106 SHPObject* hSHPObject;
108 for (
int i = 0; i < numberOfElements; i++)
110 hSHPObject = SHPReadObject(hSHP, i);
113 *(hSHPObject->padfX),
114 *(hSHPObject->padfY),
115 *(hSHPObject->padfZ));
116 stations.push_back(stn);
119 _geoObjects.addStationVec(std::move(stations), listName);
120 SHPDestroyObject(hSHPObject);
125 std::string listName)
127 if (numberOfElements <= 0)
131 std::vector<GeoLib::Point*> pnts;
132 std::vector<GeoLib::Polyline*> lines;
134 std::size_t pnt_id(0);
136 for (
int i = 0; i < numberOfElements; ++i)
138 SHPObject* hSHPObject = SHPReadObject(hSHP, i);
139 int const noOfPoints = hSHPObject->nVertices;
140 int const noOfParts = hSHPObject->nParts;
142 for (
int p = 0; p < noOfParts; ++p)
144 int const firstPnt = *(hSHPObject->panPartStart + p);
145 int const lastPnt = (p < (noOfParts - 1))
146 ? *(hSHPObject->panPartStart + p + 1)
150 for (
int j = firstPnt; j < lastPnt; ++j)
153 *(hSHPObject->padfX + j), *(hSHPObject->padfY + j),
154 *(hSHPObject->padfZ + j), pnt_id));
158 SHPDestroyObject(hSHPObject);
164 std::vector<std::size_t>
const& pnt_id_map(points.
getIDMap());
167 for (
int i = 0; i < numberOfElements; ++i)
169 SHPObject* hSHPObject = SHPReadObject(hSHP, i);
170 int const noOfPoints = hSHPObject->nVertices;
171 int const noOfParts = hSHPObject->nParts;
173 for (
int p = 0; p < noOfParts; ++p)
176 if (noOfParts > 1 && p == 0)
179 "Polygon {:d} consists of {:d} parts (PolylineIDs "
181 i, noOfParts, lines.size(), lines.size() + noOfParts - 1);
184 int const firstPnt = *(hSHPObject->panPartStart + p);
185 int const lastPnt = (p < (noOfParts - 1))
186 ? *(hSHPObject->panPartStart + p + 1)
192 for (
int j = firstPnt; j < lastPnt; ++j)
194 line->addPoint(pnt_id_map[pnt_id]);
198 lines.push_back(line);
200 SHPDestroyObject(hSHPObject);
202 _geoObjects.addPolylineVec(std::move(lines), listName,
207 const std::string& listName,
208 std::string
const& gmsh_path)
212 auto const polylines =
_geoObjects.getPolylineVec(listName);
214 for (
auto const* polyline : *polylines)
216 INFO(
"Creating a surface by triangulation of the polyline ...");
224 "\t Creating a surface by triangulation of the polyline "
235 ERR(
"SHPInterface::write2dMeshToSHP(): Mesh to Shape conversion is "
236 "only working for 2D Meshes.");
243 ERR(
"SHPInterface::write2dMeshToSHP(): Mesh contains no elements.");
250 std::size_t
const max_exp = 8;
251 if (n_elements >= std::pow(10, max_exp))
253 ERR(
"SHPInterface::write2dMeshToSHP(): Mesh contains too many elements "
254 "for currently implemented DBF-boundaries.");
258 SHPHandle hSHP = SHPCreate(file_name.c_str(), SHPT_POLYGON);
259 DBFHandle hDBF = DBFCreate(file_name.c_str());
260 int const elem_id_field =
261 DBFAddField(hDBF,
"Elem_ID", FTInteger, max_exp, 0);
264 std::size_t shp_record(0);
265 std::vector<MeshLib::Element*>
const& elems = mesh.
getElements();
273 SHPWriteObject(hSHP, -1,
object);
274 SHPDestroyObject(
object);
277 DBFWriteIntegerAttribute(hDBF, shp_record, elem_id_field,
285 int const n_recs = DBFGetRecordCount(hDBF);
291 DBFAddField(hDBF, std::string(name).c_str(), FTInteger, 16, 0);
292 for (
int i = 0; i < n_recs; ++i)
294 std::size_t
const elem_idx =
295 DBFReadIntegerAttribute(hDBF, i, elem_id_field);
296 DBFWriteIntegerAttribute(hDBF, i, field, (*p)[elem_idx]);
303 DBFAddField(hDBF, std::string(name).c_str(), FTDouble, 33, 16);
304 for (
int i = 0; i < n_recs; ++i)
306 std::size_t
const elem_idx =
307 DBFReadIntegerAttribute(hDBF, i, elem_id_field);
308 DBFWriteDoubleAttribute(hDBF, i, field, (*p)[elem_idx]);
313 INFO(
"Shape export of 2D mesh '{:s}' finished.", mesh.
getName());
318 std::size_t
const shp_record)
321 double* padfX =
new double[nNodes + 1];
322 double* padfY =
new double[nNodes + 1];
323 double* padfZ =
new double[nNodes + 1];
324 for (
unsigned j = 0; j < nNodes; ++j)
331 padfX[nNodes] = (*e.
getNode(0))[0];
332 padfY[nNodes] = (*e.
getNode(0))[1];
333 padfZ[nNodes] = (*e.
getNode(0))[2];
336 return SHPCreateObject(SHPT_POLYGON, shp_record, 0,
nullptr,
nullptr,
337 nNodes + 1, padfX, padfY, padfZ,
nullptr);
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)
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.
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)