|
TECA
The Toolkit for Extreme Climate Analysis
|
Go to the documentation of this file. 1 #ifndef teca_shape_file_util_h
2 #define teca_shape_file_util_h
4 #include "teca_config.h"
5 #include "teca_binary_stream.h"
16 namespace teca_shape_file_util
24 std::ostream &
operator<<(std::ostream &os,
const SHPObject &obj);
27 template<
typename coord_t>
36 SHPHandle h = SHPOpen(
filename.c_str(),
"rb");
48 SHPGetInfo(h, &n_shapes, &types, x0, x1);
51 TECA_STATUS(
"Found " << n_shapes <<
" shapes of type "
54 if (types != SHPT_POLYGON)
57 <<
"\" are not polygons.")
62 polys.reserve(n_shapes);
64 for (
int i = 0; i < n_shapes; ++i)
67 std::cerr <<
"Reading object " << i <<
" ... " << std::endl;
69 SHPObject *obj = SHPReadObject(h, i);
72 TECA_ERROR(
"Failed to read the " << i <<
"th polygon")
78 std::cerr <<
"Object" << i <<
" = " << *obj << std::endl;
81 std::vector<int> starts(obj->panPartStart, obj->panPartStart + obj->nParts);
82 std::vector<int> ends(obj->panPartStart + 1, obj->panPartStart + obj->nParts);
83 ends.push_back(obj->nVertices);
84 for (
int j = 0; j < obj->nParts; ++j)
87 if (obj->panPartType[j] != SHPT_POLYGON)
89 TECA_WARNING(
"Part " << j <<
" of object " << i <<
" is "
91 <<
" but a SHPT_POLYGON is required")
95 int start = starts[j];
96 int n_verts = ends[j] - start;
100 poly.
copy(obj->padfX + start, obj->padfY + start, n_verts);
104 polys.push_back(poly);
107 SHPDestroyObject(obj);
118 template<
typename coord_t>
125 #if defined(TECA_HAS_MPI)
127 MPI_Initialized(&is_init);
130 MPI_Comm_rank(comm, &rank);
148 size_t n_polys = polys.size();
152 for (
size_t i = 0; i < n_polys; ++i)
153 polys[i].to_stream(bs);
165 polys.resize(n_polys);
167 for (
size_t i = 0; i < n_polys; ++i)
168 polys[i].from_stream(bs);
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:16
void copy(const in_coord_t *in_vx, const in_coord_t *in_vy, unsigned long in_n_verts)
deep copy the vertices of the polygon.
Definition: teca_geometry.h:109
TECA_EXPORT int load_polygons(MPI_Comm comm, const std::string &filename, std::vector< teca_geometry::polygon< coord_t >> &polys, int verbose=0)
Definition: teca_shape_file_util.h:120
TECA_EXPORT std::ostream & operator<<(std::ostream &os, const teca_calendar_util::time_point &tpt)
send the time_point to a stream in humnan readable form
TECA_EXPORT int load_polygons(const std::string &filename, std::vector< teca_geometry::polygon< coord_t >> &polys, int verbose=0)
Read polygons from the given file.
Definition: teca_shape_file_util.h:29
#define TECA_STATUS(_msg)
Constructs a status message and sends it to the stderr stream.
Definition: teca_common.h:152
TECA_EXPORT std::string filename(const std::string &filename)
#define TECA_WARNING(_msg)
Constructs a warning message and sends it to the stderr stream.
Definition: teca_common.h:149
const TECA_EXPORT char * shape_type_name(int shpt)
Get a string with the name of the shape type.
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
#define TECA_ERROR(_msg)
Constructs an error message and sends it to the stderr stream.
Definition: teca_common.h:146
Definition: teca_geometry.h:74