1 /**********************************************************************
2 * WARNING! This example is obsoleted, read doc/example.cpp for
4 /**********************************************************************
6 * GEOS - Geometry Engine Open Source
7 * http://geos.osgeo.org
9 * Copyright (C) 2001-2002 Vivid Solutions Inc.
11 * This is free software; you can redistribute and/or modify it under
12 * the terms of the GNU Lesser General Public Licence as published
13 * by the Free Software Foundation.
14 * See the COPYING file for more information.
16 **********************************************************************
18 * Revision 1.3 2006/02/09 15:52:47 strk
19 * GEOSException derived from std::exception; always thrown and cought by const ref.
21 * Revision 1.2 2006/01/31 19:07:33 strk
22 * - Renamed DefaultCoordinateSequence to CoordinateArraySequence.
23 * - Moved GetNumGeometries() and GetGeometryN() interfaces
24 * from GeometryCollection to Geometry class.
25 * - Added getAt(int pos, Coordinate &to) funtion to CoordinateSequence class.
26 * - Reworked automake scripts to produce a static lib for each subdir and
27 * then link all subsystem's libs togheter
28 * - Moved C-API in it's own top-level dir capi/
29 * - Moved source/bigtest and source/test to tests/bigtest and test/xmltester
30 * - Fixed PointLocator handling of LinearRings
31 * - Changed CoordinateArrayFilter to reduce memory copies
32 * - Changed UniqueCoordinateArrayFilter to reduce memory copies
33 * - Added CGAlgorithms::isPointInRing() version working with
34 * Coordinate::ConstVect type (faster!)
35 * - Ported JTS-1.7 version of ConvexHull with big attention to
36 * memory usage optimizations.
37 * - Improved XMLTester output and user interface
38 * - geos::geom::util namespace used for geom/util stuff
39 * - Improved memory use in geos::geom::util::PolygonExtractor
40 * - New ShortCircuitedGeometryVisitor class
41 * - New operation/predicate package
43 * Revision 1.1 2004/07/08 19:41:27 strk
44 * renamed to reflect JTS API.
46 * Revision 1.5 2004/07/02 13:28:26 strk
47 * Fixed all #include lines to reflect headers layout change.
48 * Added client application build tips in README.
50 * Revision 1.4 2003/11/07 01:23:42 pramsey
51 * Add standard CVS headers licence notices and copyrights to all cpp and h
55 **********************************************************************/
61 #include <geos/util.h>
62 #include <geos/geom.h>
63 #include <geos/geosAlgorithm.h>
68 int main(int argc
, char** argv
)
71 cout
<< "Start:" << endl
<< endl
;
73 CoordinateSequence
*cl1
=new CoordinateArraySequence();
75 //CoordinateSequence cl1 is empty
76 cout
<< endl
<< "CoordinateSequence cl1: " << cl1
->toString() << endl
;
78 cl1
->add(*(new Coordinate(140,120)));
79 cl1
->add(*(new Coordinate(160,20)));
80 cl1
->add(*(new Coordinate(33,33)));
81 cl1
->add(*(new Coordinate(20,20)));
82 cl1
->add(*(new Coordinate(11,11)));
83 cl1
->add(*(new Coordinate(140,120)));
84 cout
<< "CoordinateSequence cl1: " << cl1
->toString() << endl
;
86 cl1
->setAt(*(new Coordinate(20,120)),4);
87 cout
<< "CoordinateSequence cl1: " << cl1
->toString() << endl
;
90 cout
<< "CoordinateSequence cl1: " << cl1
->toString() << endl
;
92 //Switching CoordinateSequenceFactory to create PointCoordinateSequences
93 //PointCoordinateSequence is a sample implementation of a user-defined
94 //CoordinateSequence based on a vector of struct {3 x double}
95 CoordinateSequenceFactory::internalFactory
=new PointCoordinateSequenceFactory();
96 //Now calls to CoordinateSequenceFactory would create PointCoordinateSequences
97 CoordinateSequence
*cl2
=CoordinateSequenceFactory::internalFactory
->createCoordinateSequence();
98 //It is also possible to explicitly create PointCoordinateSequences
99 //CoordinateSequence *cl2=new PointCoordinateSequence();
101 //CoordinateSequence cl2 is empty
102 cout
<< endl
<< "CoordinateSequence cl2: " << cl2
->toString() << endl
;
104 //Points could be added as Coordinates
105 cl2
->add(*(new Coordinate(11,11)));
106 cl2
->add(*(new Coordinate(140,200)));
107 cl2
->add(*(new Coordinate(33,33)));
108 //or using native PointCoordinateSequence format
109 point_3d p1
={240,200,DoubleNotANumber
};
110 point_3d p2
={55,55,DoubleNotANumber
};
111 point_3d p3
={140,120,DoubleNotANumber
};
112 ((PointCoordinateSequence
*) cl2
)->add(p1
);
113 ((PointCoordinateSequence
*) cl2
)->add(p2
);
114 ((PointCoordinateSequence
*) cl2
)->add(p3
);
115 cout
<< "CoordinateSequence cl2: " << cl2
->toString() << endl
;
117 //Points can be set using Coordinates
118 cl2
->setAt(*(new Coordinate(240,120)),4);
119 //or using native PointCoordinateSequence format
120 point_3d pn
={140,120,DoubleNotANumber
};
121 ((PointCoordinateSequence
*) cl2
)->setAt(pn
,0);
122 cout
<< "CoordinateSequence cl2: " << cl2
->toString() << endl
;
125 cout
<< "CoordinateSequence cl2: " << cl2
->toString() << endl
;
127 //To do the operations:
128 //First we need to create a GeometryFactory
129 GeometryFactory
*gf
=new GeometryFactory(new PrecisionModel(),0);
130 //Now we can create Geometries
131 Geometry
*geom1
=gf
->createPolygon(gf
->createLinearRing(cl1
),NULL
);
132 cout
<< endl
<< "Geometry 1:" << endl
<< geom1
->toString() << endl
;
133 Geometry
*geom2
=gf
->createPolygon(gf
->createLinearRing(cl2
),NULL
);
134 cout
<< endl
<< "Geometry 2:" << endl
<< geom2
->toString() << endl
;
135 //And see how they relate to each other
136 IntersectionMatrix
*im
=geom1
->relate(geom2
);
137 cout
<< endl
<< "Result of relate() operation should be \"FF2F01212\"" << endl
;
138 cout
<< "Result is: " << im
->toString() << endl
;
140 cout
<< "End" << endl
;
141 } catch (const GEOSException
& ge
) {
142 cout
<< ge
->toString() << endl
;