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