1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2006 Refractions Research Inc.
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
13 **********************************************************************
15 * Last port: simplify/TaggedLineString.java rev. 1.2 (JTS-1.7.1)
17 **********************************************************************/
19 #include <geos/simplify/TaggedLineString.h>
20 #include <geos/simplify/TaggedLineSegment.h>
21 #include <geos/geom/CoordinateSequence.h>
22 #include <geos/geom/LineString.h>
23 #include <geos/geom/Geometry.h> // for auto_ptr destructor
24 #include <geos/geom/GeometryFactory.h>
25 #include <geos/geom/CoordinateSequenceFactory.h>
38 using namespace geos::geom
;
42 namespace simplify
{ // geos::simplify
45 TaggedLineString::TaggedLineString(const geom::LineString
* nParentLine
,
46 std::size_t nMinimumSize
)
48 parentLine(nParentLine
),
49 minimumSize(nMinimumSize
)
55 TaggedLineString::~TaggedLineString()
58 cerr
<< "TaggedLineString[" << this << "] destructor"
62 for (std::size_t i
=0, n
=segs
.size(); i
<n
; i
++)
65 for (std::size_t i
=0, n
=resultSegs
.size(); i
<n
; i
++)
71 TaggedLineString::init()
74 const CoordinateSequence
* pts
= parentLine
->getCoordinatesRO();
77 cerr
<< "TaggedLineString[" << this << "] pts.size() " << pts
->size()
84 segs
.reserve(pts
->size()-1);
86 for (std::size_t i
=0, n
=pts
->size()-1; i
<n
; i
++)
88 TaggedLineSegment
* seg
= new TaggedLineSegment(
99 cerr
<< "TaggedLineString[" << this << "] segs.size " << segs
.size()
101 cerr
<< "TaggedLineString[" << this << "] resultSegs.size " << resultSegs
.size()
108 TaggedLineString::getMinimumSize() const
114 const geom::LineString
*
115 TaggedLineString::getParent() const
121 const CoordinateSequence
*
122 TaggedLineString::getParentCoordinates() const
125 return parentLine
->getCoordinatesRO();
129 CoordinateSequence::AutoPtr
130 TaggedLineString::getResultCoordinates() const
134 cerr
<< __FUNCTION__
<< " resultSegs.size: "
135 << resultSegs
.size() << endl
;
138 CoordVectPtr pts
= extractCoordinates(resultSegs
);
141 cerr
<< __FUNCTION__
<< " extracted Coords.size: "
142 << pts
->size() << endl
;
146 CoordVect
* v
= pts
.release();
147 return CoordinateSequence::AutoPtr(parentLine
->getFactory()->getCoordinateSequenceFactory()->create(v
));
152 TaggedLineString::CoordVectPtr
153 TaggedLineString::extractCoordinates(
154 const std::vector
<TaggedLineSegment
*>& segs
)
156 CoordVectPtr
pts(new CoordVect());
159 cerr
<< __FUNCTION__
<< " segs.size: " << segs
.size() << endl
;
162 std::size_t i
=0, size
=segs
.size();
167 TaggedLineSegment
* seg
= segs
[i
];
169 pts
->push_back(seg
->p0
);
173 pts
->push_back(segs
[size
-1]->p1
);
181 TaggedLineString::getResultSize() const
183 unsigned resultSegsSize
= resultSegs
.size();
184 return resultSegsSize
== 0 ? 0 : resultSegsSize
+ 1;
189 TaggedLineString::getSegment(std::size_t i
)
195 const TaggedLineSegment
*
196 TaggedLineString::getSegment(std::size_t i
) const
202 vector
<TaggedLineSegment
*>&
203 TaggedLineString::getSegments()
210 const vector
<TaggedLineSegment
*>&
211 TaggedLineString::getSegments() const
218 TaggedLineString::asLineString() const
220 return parentLine
->getFactory()->createLineString(
221 getResultCoordinates());
226 TaggedLineString::asLinearRing() const
228 return parentLine
->getFactory()->createLinearRing(
229 getResultCoordinates());
234 TaggedLineString::addToResult(auto_ptr
<TaggedLineSegment
> seg
)
237 cerr
<< "TaggedLineString[" << this << "] adding "
238 << " seg " << seg
.get() << " to result"
241 resultSegs
.push_back(seg
.release());
243 cerr
<< "TaggedLineString[" << this << "] adding "
244 << " seg " << seg
.get() << " to result"
249 } // namespace geos::simplify