Skip to content

Commit 1418cb0

Browse files
committed
Added PointView spatial reference getter methods
1 parent 685a0a2 commit 1418cb0

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

source/pdal/capi/PointView.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,56 @@ namespace pdal
5252

5353
return ptr;
5454
}
55+
56+
size_t PDALGetPointViewProj4(PDALPointViewPtr view, char *proj, size_t size)
57+
{
58+
pdal::capi::PointView *wrapper = reinterpret_cast<pdal::capi::PointView *>(view);
59+
60+
size_t result = 0;
61+
62+
if (size > 0 && proj)
63+
{
64+
proj[0] = '\0';
65+
proj[size-1] = '\0';
66+
67+
if (wrapper && *wrapper)
68+
{
69+
std::string s = (*wrapper)->spatialReference().getProj4();
70+
std::strncpy(proj, s.c_str(), size - 1);
71+
result = std::min(s.length(), size);
72+
}
73+
}
74+
75+
return result;
76+
}
77+
78+
size_t PDALGetPointViewWkt(PDALPointViewPtr view, char *wkt, size_t size, bool pretty)
79+
{
80+
pdal::capi::PointView *wrapper = reinterpret_cast<pdal::capi::PointView *>(view);
81+
82+
size_t result = 0;
83+
84+
if (size > 0 && wkt)
85+
{
86+
wkt[0] = '\0';
87+
wkt[size-1] = '\0';
88+
89+
if (wrapper && *wrapper)
90+
{
91+
std::string s = (*wrapper)->spatialReference().getWKT();
92+
93+
if (pretty)
94+
{
95+
s = SpatialReference::prettyWkt(s);
96+
}
97+
98+
std::strncpy(wkt, s.c_str(), size - 1);
99+
result = std::min(s.length(), size);
100+
}
101+
}
102+
103+
return result;
104+
}
55105
}
56106
}
57107
}

source/pdal/capi/PointView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ namespace pdal
3030
*/
3131
PDAL_C_API PDALPointViewPtr PDALClonePointView(PDALPointViewPtr view);
3232

33+
PDAL_C_API size_t PDALGetPointViewProj4(PDALPointViewPtr view, char *proj, size_t size);
3334

35+
PDAL_C_API size_t PDALGetPointViewWkt(PDALPointViewPtr view, char *wkt, size_t size, bool pretty);
3436

3537

3638
/**

tests/pdal/capi/PointViewTest.c.in

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,63 @@ TEST testPDALClonePointView(void)
150150
PASS();
151151
}
152152

153+
TEST testPDALGetPointViewProj4(void)
154+
{
155+
PDALResetPointViewCollection(gPointViewCollection);
156+
bool hasNext = PDALHasNextPointView(gPointViewCollection);
157+
ASSERT_FALSE(!hasNext);
158+
159+
PDALPointViewPtr view = PDALGetNextPointView(gPointViewCollection);
160+
ASSERT_FALSE(view == NULL);
161+
162+
char proj[1024];
163+
size_t size = PDALGetPointViewProj4(NULL, proj, 1024);
164+
ASSERT_FALSE(size > 0);
165+
ASSERT_FALSE(proj[0] != '\0');
166+
167+
size = PDALGetPointViewProj4(view, NULL, 1024);
168+
ASSERT_FALSE(size > 0);
169+
170+
size = PDALGetPointViewProj4(view, proj, 0);
171+
ASSERT_FALSE(size > 0);
172+
173+
// TODO Enable when test incorporates a pipeline with projection info
174+
// size = PDALGetPointViewProj4(view, proj, 1024);
175+
// ASSERT_FALSE(size == 0 || size > 1024);
176+
// ASSERT_FALSE(proj[0] == '\0');
177+
// printf("\n%s\n", proj);
178+
179+
PASS();
180+
}
181+
182+
TEST testPDALGetPointViewWkt(void)
183+
{
184+
PDALResetPointViewCollection(gPointViewCollection);
185+
bool hasNext = PDALHasNextPointView(gPointViewCollection);
186+
ASSERT_FALSE(!hasNext);
187+
188+
PDALPointViewPtr view = PDALGetNextPointView(gPointViewCollection);
189+
ASSERT_FALSE(view == NULL);
190+
191+
char wkt[1024];
192+
size_t size = PDALGetPointViewWkt(NULL, wkt, 1024, false);
193+
ASSERT_FALSE(size > 0);
194+
ASSERT_FALSE(wkt[0] != '\0');
195+
196+
size = PDALGetPointViewWkt(view, NULL, 1024, false);
197+
ASSERT_FALSE(size > 0);
198+
199+
size = PDALGetPointViewWkt(view, wkt, 0, false);
200+
ASSERT_FALSE(size > 0);
201+
202+
// TODO Enable when test incorporates a pipeline with projection info
203+
// size = PDALGetPointViewWkt(view, wkt, 1024, false);
204+
// ASSERT_FALSE(size == 0 || size > 1024);
205+
// ASSERT_FALSE(wkt[0] == '\0');
206+
// printf("\n%s\n", wkt);
207+
208+
PASS();
209+
}
153210

154211
GREATEST_SUITE(PointViewTest)
155212
{
@@ -160,6 +217,8 @@ GREATEST_SUITE(PointViewTest)
160217
RUN_TEST(testPDALGetPointViewSize);
161218
RUN_TEST(testPDALIsPointViewEmpty);
162219
RUN_TEST(testPDALClonePointView);
220+
RUN_TEST(testPDALGetPointViewProj4);
221+
RUN_TEST(testPDALGetPointViewWkt);
163222

164223
SET_SETUP(NULL, NULL);
165224
SET_TEARDOWN(NULL, NULL);

0 commit comments

Comments
 (0)