1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
7 * Copyright (C) 2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
15 **********************************************************************
17 * Last port: operation/linemerge/EdgeString.java r378 (JTS-1.12)
19 **********************************************************************/
21 #include <geos/operation/linemerge/EdgeString.h>
22 #include <geos/operation/linemerge/LineMergeEdge.h>
23 #include <geos/operation/linemerge/LineMergeDirectedEdge.h>
24 #include <geos/geom/GeometryFactory.h>
25 #include <geos/geom/CoordinateSequenceFactory.h>
26 #include <geos/geom/CoordinateSequence.h>
27 #include <geos/geom/LineString.h>
33 using namespace geos::geom
;
36 namespace operation
{ // geos.operation
37 namespace linemerge
{ // geos.operation.linemerge
40 * Constructs an EdgeString with the given factory used to convert
41 * this EdgeString to a LineString
43 EdgeString::EdgeString(const GeometryFactory
*newFactory
):
50 EdgeString::~EdgeString() {
54 * Adds a directed edge which is known to form part of this line.
57 EdgeString::add(LineMergeDirectedEdge
*directedEdge
)
59 directedEdges
.push_back(directedEdge
);
63 EdgeString::getCoordinates()
65 if (coordinates
==NULL
) {
66 int forwardDirectedEdges
= 0;
67 int reverseDirectedEdges
= 0;
68 coordinates
=factory
->getCoordinateSequenceFactory()->create(NULL
);
69 for (std::size_t i
=0, e
=directedEdges
.size(); i
<e
; ++i
) {
70 LineMergeDirectedEdge
* directedEdge
= directedEdges
[i
];
71 if (directedEdge
->getEdgeDirection()) {
72 forwardDirectedEdges
++;
74 reverseDirectedEdges
++;
77 assert(dynamic_cast<LineMergeEdge
*>(directedEdge
->getEdge()));
78 LineMergeEdge
* lme
=static_cast<LineMergeEdge
*>( directedEdge
->getEdge());
80 coordinates
->add(lme
->getLine()->getCoordinatesRO(),
82 directedEdge
->getEdgeDirection());
84 if (reverseDirectedEdges
> forwardDirectedEdges
) {
85 CoordinateSequence::reverse(coordinates
);
92 * Converts this EdgeString into a new LineString.
95 EdgeString::toLineString()
97 return factory
->createLineString(getCoordinates());
100 } // namespace geos.operation.linemerge
101 } // namespace geos.operation
104 /**********************************************************************
106 * Revision 1.10 2006/03/22 10:13:54 strk
107 * opLinemerge.h split
109 **********************************************************************/