forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathossimNitfBndplbTag.cpp
More file actions
116 lines (98 loc) · 2.95 KB
/
Copy pathossimNitfBndplbTag.cpp
File metadata and controls
116 lines (98 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//---
//
// License: MIT
//
// Author: David Burken
//
// Description: BNDPLB tag class definition.
//
// Reference documents:
// - MIL-PRF-32466A, Appendix C, C.2.1.7
// - Digital Geographic Information Exchange Standard (DIGEST),
// Part 2 - Annex D, D1.2.7.7 BNDPL - Bounding Polygon
//
//---
// $Id$
#include <ossim/support_data/ossimNitfBndplbTag.h>
#include <ossim/base/ossimString.h>
#include <cstring> /* for memset */
#include <iomanip>
#include <iostream>
// static const ossimTrace traceDebug(ossimString("ossimNitfBndplbTag:debug"));
RTTI_DEF1(ossimNitfBndplbTag, "ossimNitfBndplbTag", ossimNitfRegisteredTag);
ossimNitfBndplbTag::ossimNitfBndplbTag()
: ossimNitfRegisteredTag(),
m_lon(),
m_lat()
{
// Set the tag name. Note the tag length is variable.
setTagName(std::string("BNDPLB"));
clearFields();
}
void ossimNitfBndplbTag::parseStream(std::istream& in)
{
clearFields();
// Points in polygon:
in.read(m_numPts, NUM_PTS_SIZE);
const ossim_uint32 POINTS = ossimString(m_numPts).toUInt32();
m_lon.resize(POINTS);
m_lat.resize(POINTS);
char tempStr[PT_SIZE+1];
tempStr[PT_SIZE] = '\0';
for ( ossim_uint32 i = 0; i < POINTS; ++i )
{
in.read( tempStr, PT_SIZE );
m_lon[i] = tempStr;
in.read( tempStr, PT_SIZE );
m_lat[i] = tempStr;
}
// Set the variable tag length:
setTagLength( 4 + POINTS * 30 );
}
void ossimNitfBndplbTag::writeStream(std::ostream& out)
{
out.write(m_numPts, NUM_PTS_SIZE);
ossim_uint32 POINTS = ossimString(m_numPts).toUInt32();
if ( ((ossim_uint32)m_lon.size() == POINTS) && ((ossim_uint32)m_lat.size() == POINTS) )
{
for ( ossim_uint32 i = 0; i < POINTS; ++i )
{
out.write( m_lon[i].data(), PT_SIZE );
out.write( m_lat[i].data(), PT_SIZE );
}
}
// else error...
}
void ossimNitfBndplbTag::clearFields()
{
memset(m_numPts, 0, NUM_PTS_SIZE);
m_numPts[NUM_PTS_SIZE] = '\0';
m_lon.clear();
m_lat.clear();
}
std::ostream& ossimNitfBndplbTag::print(std::ostream& out,
const std::string& prefix) const
{
std::string pfx = prefix;
pfx += getTagName();
pfx += ".";
// Grab the corners parsed into points.
out << std::setiosflags(std::ios_base::left)
<< pfx << std::setw(24) << "CETAG:" << getTagName() << "\n"
<< pfx << std::setw(24) << "CEL:" << getTagLength() << "\n"
<< pfx << std::setw(24) << "NUM_PTS:" << m_numPts << "\n";
ossim_uint32 POINTS = ossimString(m_numPts).toUInt32();
if ( ((ossim_uint32)m_lon.size() == POINTS) && ((ossim_uint32)m_lat.size() == POINTS) )
{
for ( ossim_uint32 i = 0; i < POINTS; ++i )
{
out << pfx << "LON" << i << std::setw(20) << ":" << m_lon[i] << "\n"
<< pfx << "LAT" << i << std::setw(20) << ":" << m_lat[i] << "\n";
}
}
return out;
}
ossim_uint32 ossimNitfBndplbTag::getNumberOfPoints() const
{
return ossimString(m_numPts).toUInt32();
}