1 /**********************************************************************
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
14 **********************************************************************
16 * Revision 1.3 2006/04/04 08:16:46 strk
17 * Changed GEOSException hierarchy to be derived from std::runtime_exception.
18 * Removed the GEOSException::toString redundant method (use ::what() instead)
20 * Revision 1.2 2006/02/09 15:52:47 strk
21 * GEOSException derived from std::exception; always thrown and cought by const ref.
23 * Revision 1.1 2004/07/08 19:41:27 strk
24 * renamed to reflect JTS API.
26 * Revision 1.6 2004/07/02 13:28:26 strk
27 * Fixed all #include lines to reflect headers layout change.
28 * Added client application build tips in README.
30 * Revision 1.5 2003/11/07 01:23:42 pramsey
31 * Add standard CVS headers licence notices and copyrights to all cpp and h
35 **********************************************************************/
40 #include "CustomCoordinateSequenceExample.h"
42 #include <geos/util.h>
43 #include <geos/geom.h>
44 #include <geos/geosAlgorithm.h>
49 int main(int argc
, char** argv
) {
51 cout
<< "Start:" << endl
<< endl
;
53 //CustomPointCoordinateSequence is a sample implementation of a user-defined
54 //wrapper around their internal storage format (array of point_3d struct {3 x double})
56 point_3d p1
={11,11,DoubleNotANumber
};
57 point_3d p2
={140,200,DoubleNotANumber
};
58 point_3d p3
={240,200,DoubleNotANumber
};
59 point_3d p4
={55,55,DoubleNotANumber
};
60 point_3d p5
={140,120,DoubleNotANumber
};
62 //Array of point_3d (internal storage format)
70 //Creating CoordinateSequence
71 CoordinateSequence
*cl
=new CustomPointCoordinateSequence(points
,5);
73 cout
<< endl
<< "CoordinateSequence cl: " << cl
->toString() << endl
;
75 //Points can be set using Coordinates
76 cl
->setAt(*(new Coordinate(240,120)),3);
77 //or using native CustomPointCoordinateSequence format
78 point_3d pn
={140,120,DoubleNotANumber
};
79 ((CustomPointCoordinateSequence
*) cl
)->setAt(pn
,0);
80 cout
<< "CoordinateSequence cl: " << cl
->toString() << endl
;
82 //Since the underlying storage format is a fixed size array
83 //points can't be added or deleted
84 //cl->add(*(new Coordinate(240,120)),4); //Would cause exception
85 //cl->deleteAt(2); //Would cause exception
87 //To do the operations:
88 //First we need to create a GeometryFactory
89 GeometryFactory
*gf
=new GeometryFactory(new PrecisionModel(),0);
90 //Now we can create a Geometry
91 Geometry
*geom
=gf
->createPolygon(gf
->createLinearRing(cl
),NULL
);
92 cout
<< endl
<< "Geometry:" << endl
<< geom
->toString() << endl
;
93 //And see if the geometry is valid
94 cout
<< "Geometry is valid? " << (geom
->isValid()?"true":"false") << endl
;
96 cout
<< "End" << endl
;
97 } catch (const GEOSException
& ge
) {
98 cout
<< ge
.what() << endl
;