📄 ogrpolygon.cpp
字号:
/****************************************************************************** * $Id: ogrpolygon.cpp,v 1.42 2006/07/07 15:09:12 fwarmerdam Exp $ * * Project: OpenGIS Simple Features Reference Implementation * Purpose: The OGRPolygon geometry class. * Author: Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: ogrpolygon.cpp,v $ * Revision 1.42 2006/07/07 15:09:12 fwarmerdam * improve handling of empty linearrings and polygons in aggregates * * Revision 1.41 2006/07/07 00:05:46 mloskot * Removed GEOS C++ API usage from OGR and autotools. * * Revision 1.40 2006/06/19 23:19:45 mloskot * Added new functions OGRLinearRing::isPointInRing and OGRPolygon::IsPointOnSurface. * * Revision 1.39 2006/03/31 17:57:32 fwarmerdam * header updates * * Revision 1.38 2005/10/21 15:58:34 fwarmerdam * use c++ casting for GEOSGeom * * Revision 1.37 2005/10/21 03:56:52 fwarmerdam * Fixed up for only capi. * * Revision 1.36 2005/10/20 19:55:29 fwarmerdam * added GEOS C API support * * Revision 1.35 2005/07/22 19:30:25 fwarmerdam * Document get_Area(). * * Revision 1.34 2005/07/20 02:34:09 fwarmerdam * maintain dimension better * * Revision 1.33 2005/07/20 01:43:51 fwarmerdam * upgraded OGR geometry dimension handling * * Revision 1.32 2005/07/12 17:34:00 fwarmerdam * updated to produce proper empty syntax and consume either * * Revision 1.31 2005/04/06 20:43:00 fwarmerdam * fixed a variety of method signatures for documentation * * Revision 1.30 2005/02/22 12:38:01 fwarmerdam * rename Equal/Intersect to Equals/Intersects * * Revision 1.29 2004/10/04 21:06:46 fwarmerdam * added centroid support * * Revision 1.28 2004/09/17 15:05:36 fwarmerdam * added get_Area() support * * Revision 1.27 2004/07/10 04:51:42 warmerda * added closeRings * * Revision 1.26 2004/02/22 09:56:54 dron * Fix compirison casting problems in OGRPolygon::Equal(). * * Revision 1.25 2004/02/21 15:36:14 warmerda * const correctness updates for geometry: bug 289 * * Revision 1.24 2004/01/16 21:57:17 warmerda * fixed up EMPTY support * * Revision 1.23 2004/01/16 21:20:00 warmerda * Added EMPTY support * * Revision 1.22 2003/08/27 15:40:37 warmerda * added support for generating DB2 V7.2 compatible WKB * * Revision 1.21 2003/06/09 13:48:54 warmerda * added DB2 V7.2 byte order hack * * Revision 1.20 2003/05/28 19:16:43 warmerda * fixed up argument names and stuff for docs * * Revision 1.19 2003/03/07 21:28:56 warmerda * support 0x8000 style 3D WKB flags * * Revision 1.18 2002/09/11 13:47:17 warmerda * preliminary set of fixes for 3D WKB enum * * Revision 1.17 2002/05/02 19:44:53 warmerda * fixed 3D binary support for polygon/linearring * * Revision 1.16 2002/03/05 14:25:14 warmerda * expand tabs * * Revision 1.15 2001/11/01 17:20:33 warmerda * added DISABLE_OGRGEOM_TRANSFORM macro * * Revision 1.14 2001/09/21 16:24:20 warmerda * added transform() and transformTo() methods * * Revision 1.13 2001/07/18 05:03:05 warmerda * added CPL_CVSID * * Revision 1.12 1999/11/18 19:02:19 warmerda * expanded tabs * * Revision 1.11 1999/09/22 13:18:55 warmerda * Added the addRingDirectly() method. * * Revision 1.10 1999/09/13 02:27:33 warmerda * incorporated limited 2.5d support * * Revision 1.9 1999/07/27 00:48:12 warmerda * Added Equal() support * * Revision 1.8 1999/07/06 21:36:47 warmerda * tenatively added getEnvelope() and Intersect() * * Revision 1.7 1999/06/25 20:44:43 warmerda * implemented assignSpatialReference, carry properly * * Revision 1.6 1999/05/31 20:43:55 warmerda * added empty() method * * Revision 1.5 1999/05/31 14:59:06 warmerda * added documentation * * Revision 1.4 1999/05/23 05:34:41 warmerda * added support for clone(), multipolygons and geometry collections * * Revision 1.3 1999/05/20 14:35:44 warmerda * added support for well known text format * * Revision 1.2 1999/05/17 14:38:11 warmerda * Added new IPolygon style methods. * * Revision 1.1 1999/03/30 21:21:05 warmerda * New * */#include "ogr_geometry.h"#include "ogr_p.h"#include "ogr_geos.h"#include "ogr_api.h"CPL_CVSID("$Id: ogrpolygon.cpp,v 1.42 2006/07/07 15:09:12 fwarmerdam Exp $");/************************************************************************//* OGRPolygon() *//************************************************************************//** * Create an empty polygon. */OGRPolygon::OGRPolygon(){ nRingCount = 0; papoRings = NULL;}/************************************************************************//* ~OGRPolygon() *//************************************************************************/OGRPolygon::~OGRPolygon(){ empty();}/************************************************************************//* clone() *//************************************************************************/OGRGeometry *OGRPolygon::clone() const{ OGRPolygon *poNewPolygon; poNewPolygon = new OGRPolygon; poNewPolygon->assignSpatialReference( getSpatialReference() ); for( int i = 0; i < nRingCount; i++ ) { poNewPolygon->addRing( papoRings[i] ); } return poNewPolygon;}/************************************************************************//* empty() *//************************************************************************/void OGRPolygon::empty(){ if( papoRings != NULL ) { for( int i = 0; i < nRingCount; i++ ) { delete papoRings[i]; } OGRFree( papoRings ); } papoRings = NULL; nRingCount = 0;}/************************************************************************//* getGeometryType() *//************************************************************************/OGRwkbGeometryType OGRPolygon::getGeometryType() const{ if( getCoordinateDimension() == 3 ) return wkbPolygon25D; else return wkbPolygon;}/************************************************************************//* getDimension() *//************************************************************************/int OGRPolygon::getDimension() const{ return 2;}/************************************************************************//* flattenTo2D() *//************************************************************************/void OGRPolygon::flattenTo2D(){ for( int iRing = 0; iRing < nRingCount; iRing++ ) papoRings[iRing]->flattenTo2D();}/************************************************************************//* getGeometryName() *//************************************************************************/const char * OGRPolygon::getGeometryName() const{ return "POLYGON";}/************************************************************************//* getExteriorRing() *//************************************************************************//** * Fetch reference to external polygon ring. * * Note that the returned ring pointer is to an internal data object of * the OGRPolygon. It should not be modified or deleted by the application, * and the pointer is only valid till the polygon is next modified. Use * the OGRGeometry::clone() method to make a separate copy within the * application. * * Relates to the SFCOM IPolygon::get_ExteriorRing() method. * * @return pointer to external ring. May be NULL if the OGRPolygon is empty. */OGRLinearRing *OGRPolygon::getExteriorRing(){ if( nRingCount > 0 ) return papoRings[0]; else return NULL;}const OGRLinearRing *OGRPolygon::getExteriorRing() const{ if( nRingCount > 0 ) return papoRings[0]; else return NULL;}/************************************************************************//* getNumInteriorRings() *//************************************************************************//** * Fetch the number of internal rings. * * Relates to the SFCOM IPolygon::get_NumInteriorRings() method. * * @return count of internal rings, zero or more. */int OGRPolygon::getNumInteriorRings() const{ if( nRingCount > 0 ) return nRingCount-1; else return 0;}/************************************************************************//* getInteriorRing() *//************************************************************************//** * Fetch reference to indicated internal ring. * * Note that the returned ring pointer is to an internal data object of * the OGRPolygon. It should not be modified or deleted by the application, * and the pointer is only valid till the polygon is next modified. Use * the OGRGeometry::clone() method to make a separate copy within the * application. * * Relates to the SFCOM IPolygon::get_InternalRing() method. * * @param iRing internal ring index from 0 to getNumInternalRings() - 1. * * @return pointer to external ring. May be NULL if the OGRPolygon is empty. */OGRLinearRing *OGRPolygon::getInteriorRing( int iRing ){ if( iRing < 0 || iRing >= nRingCount-1 ) return NULL; else return papoRings[iRing+1];}const OGRLinearRing *OGRPolygon::getInteriorRing( int iRing ) const{ if( iRing < 0 || iRing >= nRingCount-1 ) return NULL; else return papoRings[iRing+1];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -