本文整理汇总了C++中OGRGeometryCollection::getGeometryRef方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeometryCollection::getGeometryRef方法的具体用法?C++ OGRGeometryCollection::getGeometryRef怎么用?C++ OGRGeometryCollection::getGeometryRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRGeometryCollection
的用法示例。
在下文中一共展示了OGRGeometryCollection::getGeometryRef方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wkbFlatten
OGRGeometry *OGRGeometryFactory::forceToPolygon( OGRGeometry *poGeom )
{
if( poGeom == NULL )
return NULL;
if( wkbFlatten(poGeom->getGeometryType()) != wkbGeometryCollection
|| wkbFlatten(poGeom->getGeometryType()) != wkbMultiPolygon )
return poGeom;
// build an aggregated polygon from all the polygon rings in the container.
OGRPolygon *poPolygon = new OGRPolygon();
OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom;
int iGeom;
for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
{
if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType())
!= wkbPolygon )
continue;
OGRPolygon *poOldPoly = (OGRPolygon *) poGC->getGeometryRef(iGeom);
int iRing;
poPolygon->addRing( poOldPoly->getExteriorRing() );
for( iRing = 0; iRing < poOldPoly->getNumInteriorRings(); iRing++ )
poPolygon->addRing( poOldPoly->getInteriorRing( iRing ) );
}
delete poGC;
return poPolygon;
}
示例2: OGRMultiPolygon
OGRGeometry *OGRGeometryFactory::forceToMultiPolygon( OGRGeometry *poGeom )
{
if( poGeom == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* Check for the case of a geometrycollection that can be */
/* promoted to MultiPolygon. */
/* -------------------------------------------------------------------- */
if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection )
{
int iGeom;
int bAllPoly = TRUE;
OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom;
for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
{
if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType())
!= wkbPolygon )
bAllPoly = FALSE;
}
if( !bAllPoly )
return poGeom;
OGRMultiPolygon *poMP = new OGRMultiPolygon();
while( poGC->getNumGeometries() > 0 )
{
poMP->addGeometryDirectly( poGC->getGeometryRef(0) );
poGC->removeGeometry( 0, FALSE );
}
delete poGC;
return poMP;
}
/* -------------------------------------------------------------------- */
/* Eventually we should try to split the polygon into component */
/* island polygons. But thats alot of work and can be put off. */
/* -------------------------------------------------------------------- */
if( wkbFlatten(poGeom->getGeometryType()) != wkbPolygon )
return poGeom;
OGRMultiPolygon *poMP = new OGRMultiPolygon();
poMP->addGeometryDirectly( poGeom );
return poMP;
}
示例3: Equals
OGRBoolean OGRGeometryCollection::Equals( OGRGeometry * poOther ) const
{
if( poOther == this )
return TRUE;
if( poOther->getGeometryType() != getGeometryType() )
return FALSE;
if ( IsEmpty() && poOther->IsEmpty() )
return TRUE;
OGRGeometryCollection *poOGC = (OGRGeometryCollection *) poOther;
if( getNumGeometries() != poOGC->getNumGeometries() )
return FALSE;
// we should eventually test the SRS.
for( int iGeom = 0; iGeom < nGeomCount; iGeom++ )
{
if( !getGeometryRef(iGeom)->Equals(poOGC->getGeometryRef(iGeom)) )
return FALSE;
}
return TRUE;
}
示例4: OGRMultiLineString
OGRGeometry *OGRGeometryFactory::forceToMultiLineString( OGRGeometry *poGeom )
{
if( poGeom == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* Check for the case of a geometrycollection that can be */
/* promoted to MultiLineString. */
/* -------------------------------------------------------------------- */
if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection )
{
int iGeom;
int bAllLines = TRUE;
OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom;
for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
{
if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType())
!= wkbLineString )
bAllLines = FALSE;
}
if( !bAllLines )
return poGeom;
OGRMultiLineString *poMP = new OGRMultiLineString();
while( poGC->getNumGeometries() > 0 )
{
poMP->addGeometryDirectly( poGC->getGeometryRef(0) );
poGC->removeGeometry( 0, FALSE );
}
delete poGC;
return poMP;
}
if( wkbFlatten(poGeom->getGeometryType()) != wkbLineString )
return poGeom;
OGRMultiLineString *poMP = new OGRMultiLineString();
poMP->addGeometryDirectly( poGeom );
return poMP;
}
示例5: OGRMultiPolygon
OGRMultiPolygon* OGRILI1Layer::Polygonize( OGRGeometryCollection* poLines, bool fix_crossing_lines )
{
OGRMultiPolygon *poPolygon = new OGRMultiPolygon();
if (poLines->getNumGeometries() == 0) return poPolygon;
#if defined(HAVE_GEOS)
GEOSGeom *ahInGeoms = NULL;
int i = 0;
OGRGeometryCollection *poNoncrossingLines = poLines;
GEOSGeom hResultGeom = NULL;
OGRGeometry *poMP = NULL;
if (fix_crossing_lines && poLines->getNumGeometries() > 0)
{
CPLDebug( "OGR_ILI", "Fixing crossing lines");
//A union of the geometry collection with one line fixes invalid geometries
poNoncrossingLines = (OGRGeometryCollection*)poLines->Union(poLines->getGeometryRef(0));
CPLDebug( "OGR_ILI", "Fixed lines: %d", poNoncrossingLines->getNumGeometries()-poLines->getNumGeometries());
}
GEOSContextHandle_t hGEOSCtxt = OGRGeometry::createGEOSContext();
ahInGeoms = (GEOSGeom *) CPLCalloc(sizeof(void*),poNoncrossingLines->getNumGeometries());
for( i = 0; i < poNoncrossingLines->getNumGeometries(); i++ )
ahInGeoms[i] = poNoncrossingLines->getGeometryRef(i)->exportToGEOS(hGEOSCtxt);
hResultGeom = GEOSPolygonize_r( hGEOSCtxt,
ahInGeoms,
poNoncrossingLines->getNumGeometries() );
for( i = 0; i < poNoncrossingLines->getNumGeometries(); i++ )
GEOSGeom_destroy_r( hGEOSCtxt, ahInGeoms[i] );
CPLFree( ahInGeoms );
if (poNoncrossingLines != poLines) delete poNoncrossingLines;
if( hResultGeom == NULL )
{
OGRGeometry::freeGEOSContext( hGEOSCtxt );
return NULL;
}
poMP = OGRGeometryFactory::createFromGEOS( hGEOSCtxt, hResultGeom );
GEOSGeom_destroy_r( hGEOSCtxt, hResultGeom );
OGRGeometry::freeGEOSContext( hGEOSCtxt );
return (OGRMultiPolygon *) poMP;
#endif
return poPolygon;
}
示例6: OGRMultiPolygon
OGRMultiPolygon* OGRILI1Layer::Polygonize( OGRGeometryCollection* poLines, bool fix_crossing_lines )
{
OGRMultiPolygon *poPolygon = new OGRMultiPolygon();
if (poLines->getNumGeometries() == 0) return poPolygon;
#if defined(HAVE_GEOS)
GEOSGeom *ahInGeoms = NULL;
int i = 0;
OGRGeometryCollection *poNoncrossingLines = poLines;
GEOSGeom hResultGeom = NULL;
OGRGeometry *poMP = NULL;
if (fix_crossing_lines && poLines->getNumGeometries() > 0)
{
#if (GEOS_VERSION_MAJOR >= 3)
CPLDebug( "OGR_ILI", "Fixing crossing lines");
//A union of the geometry collection with one line fixes invalid geometries
poNoncrossingLines = (OGRGeometryCollection*)poLines->Union(poLines->getGeometryRef(0));
CPLDebug( "OGR_ILI", "Fixed lines: %d", poNoncrossingLines->getNumGeometries()-poLines->getNumGeometries());
#else
#warning Interlis 1 AREA cleanup disabled. Needs GEOS >= 3.0
#endif
}
ahInGeoms = (GEOSGeom *) CPLCalloc(sizeof(void*),poNoncrossingLines->getNumGeometries());
for( i = 0; i < poNoncrossingLines->getNumGeometries(); i++ )
ahInGeoms[i] = poNoncrossingLines->getGeometryRef(i)->exportToGEOS();
hResultGeom = GEOSPolygonize( ahInGeoms,
poNoncrossingLines->getNumGeometries() );
for( i = 0; i < poNoncrossingLines->getNumGeometries(); i++ )
GEOSGeom_destroy( ahInGeoms[i] );
CPLFree( ahInGeoms );
if (poNoncrossingLines != poLines) delete poNoncrossingLines;
if( hResultGeom == NULL )
return NULL;
poMP = OGRGeometryFactory::createFromGEOS( hResultGeom );
GEOSGeom_destroy( hResultGeom );
return (OGRMultiPolygon *) poMP;
#endif
return poPolygon;
}
示例7: Dispatch
void Shape::Dispatch(OGRGeometry *geom){
switch(geom->getGeometryType()){
case wkbPolygon:
{
PlotPolygon((OGRPolygon *)geom);
break;
}
case wkbMultiPolygon:
{
OGRGeometryCollection *coll = (OGRGeometryCollection *)geom;
for(int i = 0; i < coll->getNumGeometries(); i++)
Dispatch(coll->getGeometryRef(i));
break;
}
}
}
示例8: Draw
void wxGISSimpleMarkerSymbol::Draw(const wxGISGeometry &Geometry, int nLevel)
{
if(!Geometry.IsOk() ||!m_pDisplay)
return;
OGRwkbGeometryType eGeomType = wkbFlatten(Geometry.GetType());
if(eGeomType != wkbPoint && eGeomType != wkbMultiPoint)
return;
OGREnvelope Env = Geometry.GetEnvelope();
if(!m_pDisplay->CanDraw(Env))
return;
OGRGeometry *pGeom = Geometry;
if(eGeomType == wkbMultiPoint)
{
OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)pGeom;
for(int i = 0; i < pOGRGeometryCollection->getNumGeometries(); ++i)
Draw(wxGISGeometry(pOGRGeometryCollection->getGeometryRef(i), false));
return;
}
wxCriticalSectionLocker lock(m_pDisplay->GetLock());
OGRPoint* pPoint = (OGRPoint*)pGeom;
if(m_dfOutlineSize)
{
if(!m_pDisplay->DrawPointFast(pPoint->getX(), pPoint->getY()))
{
return;
}
m_pDisplay->SetColor(m_OutlineColor);
m_pDisplay->SetLineWidth( m_dfSize + m_dfOutlineSize + m_dfOutlineSize);
m_pDisplay->Stroke();
}
if(!m_pDisplay->DrawPointFast(pPoint->getX(), pPoint->getY()))
{
return;
}
m_pDisplay->SetColor(m_Color);
m_pDisplay->SetLineWidth( m_dfSize );
m_pDisplay->SetLineCap(CAIRO_LINE_CAP_ROUND);
m_pDisplay->Stroke();
}
示例9: draw_geometry
void GeomDrawBox::draw_geometry(cairo_t *cr, OGRGeometry *geom, double scale, double x, double y, double height)
{
switch (geom->getGeometryType())
{
case wkbPolygon:
draw_polygon(cr, dynamic_cast<OGRPolygon*>(geom), scale, x, y, height);
break;
case wkbMultiPolygon:
{
OGRGeometryCollection *geoCollection = dynamic_cast<OGRGeometryCollection*>(geom);
for (int i = 0; i < geoCollection->getNumGeometries(); ++i)
draw_geometry(cr, geoCollection->getGeometryRef(i), scale, x, y, height);
}
break;
default:
log_warning("Can't paint geometry type %s\n", geom->getGeometryName());
break;
}
}
示例10: geometry
OGRConvert::Geometry* OGRConvert::geometry ( OGRGeometry* geometry, OGRCoordinateTransformation *transform, double verticalOffset )
{
if ( 0x0 != geometry )
{
switch ( geometry->getGeometryType() )
{
case wkbPoint:
case wkbPoint25D:
case wkbLineString:
case wkbLineString25D:
case wkbLinearRing:
case wkbPolygon:
case wkbPolygon25D:
return OGRConvert::_geometry ( geometry, transform, verticalOffset );
break;
case wkbMultiPoint:
case wkbMultiPoint25D:
case wkbMultiLineString:
case wkbMultiLineString25D:
case wkbMultiPolygon:
case wkbMultiPolygon25D:
case wkbGeometryCollection:
case wkbGeometryCollection25D:
{
OGRGeometryCollection* collection ( static_cast<OGRGeometryCollection*> ( geometry ) );
Minerva::Core::Data::MultiGeometry::RefPtr multiGeometry ( new Minerva::Core::Data::MultiGeometry );
for ( int i = 0; i < collection->getNumGeometries(); ++i )
{
multiGeometry->addGeometry ( OGRConvert::_geometry ( collection->getGeometryRef ( i ), transform, verticalOffset ) );
}
return multiGeometry.release();
}
break;
case wkbNone:
case wkbUnknown:
return 0x0;
}
}
return 0x0;
}
示例11: if
//.........这里部分代码省略.........
OGRLinearRing *poRing = poPolygon->getInteriorRing(iRing);
AppendString( ppszText, pnLength, pnMaxLength,
"<gml:innerBoundaryIs>" );
if( !OGR2GMLGeometryAppend( poRing, ppszText, pnLength,
pnMaxLength, TRUE ) )
return FALSE;
AppendString( ppszText, pnLength, pnMaxLength,
"</gml:innerBoundaryIs>" );
}
AppendString( ppszText, pnLength, pnMaxLength,
"</gml:Polygon>" );
}
/* -------------------------------------------------------------------- */
/* MultiPolygon, MultiLineString, MultiPoint, MultiGeometry */
/* -------------------------------------------------------------------- */
else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon
|| wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString
|| wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPoint
|| wkbFlatten(poGeometry->getGeometryType()) == wkbGeometryCollection )
{
OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeometry;
int iMember;
const char *pszElemClose = NULL;
const char *pszMemberElem = NULL;
// Buffer for opening tag + srsName attribute
char* pszElemOpen = NULL;
if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon )
{
pszElemOpen = (char *) CPLMalloc( 13 + nAttrsLength + 1 );
sprintf( pszElemOpen, "MultiPolygon%s>", szAttributes );
pszElemClose = "MultiPolygon>";
pszMemberElem = "polygonMember>";
}
else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString )
{
pszElemOpen = (char *) CPLMalloc( 16 + nAttrsLength + 1 );
sprintf( pszElemOpen, "MultiLineString%s>", szAttributes );
pszElemClose = "MultiLineString>";
pszMemberElem = "lineStringMember>";
}
else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPoint )
{
pszElemOpen = (char *) CPLMalloc( 11 + nAttrsLength + 1 );
sprintf( pszElemOpen, "MultiPoint%s>", szAttributes );
pszElemClose = "MultiPoint>";
pszMemberElem = "pointMember>";
}
else
{
pszElemOpen = (char *) CPLMalloc( 19 + nAttrsLength + 1 );
sprintf( pszElemOpen, "MultiGeometry%s>", szAttributes );
pszElemClose = "MultiGeometry>";
pszMemberElem = "geometryMember>";
}
AppendString( ppszText, pnLength, pnMaxLength, "<gml:" );
AppendString( ppszText, pnLength, pnMaxLength, pszElemOpen );
for( iMember = 0; iMember < poGC->getNumGeometries(); iMember++)
{
OGRGeometry *poMember = poGC->getGeometryRef( iMember );
AppendString( ppszText, pnLength, pnMaxLength, "<gml:" );
AppendString( ppszText, pnLength, pnMaxLength, pszMemberElem );
if( !OGR2GMLGeometryAppend( poMember,
ppszText, pnLength, pnMaxLength,
TRUE ) )
{
return FALSE;
}
AppendString( ppszText, pnLength, pnMaxLength, "</gml:" );
AppendString( ppszText, pnLength, pnMaxLength, pszMemberElem );
}
AppendString( ppszText, pnLength, pnMaxLength, "</gml:" );
AppendString( ppszText, pnLength, pnMaxLength, pszElemClose );
// FREE TAG BUFFER
CPLFree( pszElemOpen );
}
else
{
return FALSE;
}
return TRUE;
}
示例12: geom2kml
//.........这里部分代码省略.........
{
CPLError(CE_Failure, CPLE_NotSupported, "Invalid polygon");
return NULL;
}
poOgrPolygon = ( OGRPolygon * ) poOgrGeom;
poKmlGeometry = poKmlPolygon = poKmlFactory->CreatePolygon ( );
poKmlTmpGeometry = geom2kml ( poOgrPolygon->getExteriorRing ( ),
0, poKmlFactory );
poKmlPolygon->
set_outerboundaryis ( AsOuterBoundaryIs ( poKmlTmpGeometry ) );
nGeom = poOgrPolygon->getNumInteriorRings ( );
for ( i = 0; i < nGeom; i++ ) {
poKmlTmpGeometry = geom2kml ( poOgrPolygon->getInteriorRing ( i ),
i + 1, poKmlFactory );
poKmlPolygon->
add_innerboundaryis ( AsInnerBoundaryIs ( poKmlTmpGeometry ) );
}
break;
case wkbPolygon25D:
CPLErrorReset();
if( CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) &&
OGRGeometryFactory::haveGEOS() && (!poOgrGeom->IsValid() ||
CPLGetLastErrorType() != CE_None) )
{
CPLError(CE_Failure, CPLE_NotSupported, "Invalid polygon");
return NULL;
}
poOgrPolygon = ( OGRPolygon * ) poOgrGeom;
poKmlGeometry = poKmlPolygon = poKmlFactory->CreatePolygon ( );
poKmlTmpGeometry = geom2kml ( poOgrPolygon->getExteriorRing ( ),
0, poKmlFactory );
poKmlPolygon->
set_outerboundaryis ( AsOuterBoundaryIs ( poKmlTmpGeometry ) );
nGeom = poOgrPolygon->getNumInteriorRings ( );
for ( i = 0; i < nGeom; i++ ) {
poKmlTmpGeometry = geom2kml ( poOgrPolygon->getInteriorRing ( i ),
i + 1, poKmlFactory );
poKmlPolygon->
add_innerboundaryis ( AsInnerBoundaryIs ( poKmlTmpGeometry ) );
}
break;
case wkbMultiPoint:
case wkbMultiLineString:
case wkbMultiPolygon:
case wkbGeometryCollection:
case wkbMultiPoint25D:
case wkbMultiLineString25D:
case wkbMultiPolygon25D:
case wkbGeometryCollection25D:
poOgrMultiGeom = ( OGRGeometryCollection * ) poOgrGeom;
nGeom = poOgrMultiGeom->getNumGeometries ( );
if( nGeom == 1 &&
CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) )
{
CPLDebug("LIBKML", "Turning multiple geometry into single geometry");
poKmlGeometry = geom2kml( poOgrMultiGeom->getGeometryRef ( 0 ),
-1, poKmlFactory );
}
else
{
if( nGeom == 0 &&
CPLTestBool(CPLGetConfigOption("LIBKML_STRICT_COMPLIANCE", "TRUE")) )
{
CPLError(CE_Warning, CPLE_AppDefined, "Empty multi geometry are not recommended");
}
poKmlGeometry = poKmlMultiGeometry =
poKmlFactory->CreateMultiGeometry ( );
for ( i = 0; i < nGeom; i++ ) {
poKmlTmpGeometry = geom2kml ( poOgrMultiGeom->getGeometryRef ( i ),
-1, poKmlFactory );
poKmlMultiGeometry->
add_geometry ( AsGeometry ( poKmlTmpGeometry ) );
}
}
break;
case wkbUnknown:
case wkbNone:
default:
break;
}
return poKmlGeometry;
}
示例13: if
//.........这里部分代码省略.........
ppszText, pnLength, pnMaxLength );
if( bRing )
AppendString( ppszText, pnLength, pnMaxLength,
"</LinearRing>" );
else
AppendString( ppszText, pnLength, pnMaxLength,
"</LineString>" );
}
/* -------------------------------------------------------------------- */
/* Polygon */
/* -------------------------------------------------------------------- */
else if( poGeometry->getGeometryType() == wkbPolygon
|| poGeometry->getGeometryType() == wkbPolygon25D )
{
OGRPolygon* poPolygon = static_cast<OGRPolygon*>(poGeometry);
AppendString( ppszText, pnLength, pnMaxLength, "<Polygon>" );
if (NULL != szAltitudeMode)
{
AppendString( ppszText, pnLength, pnMaxLength, szAltitudeMode);
}
if( poPolygon->getExteriorRing() != NULL )
{
AppendString( ppszText, pnLength, pnMaxLength,
"<outerBoundaryIs>" );
if( !OGR2KMLGeometryAppend( poPolygon->getExteriorRing(),
ppszText, pnLength, pnMaxLength,
szAltitudeMode ) )
{
return false;
}
AppendString( ppszText, pnLength, pnMaxLength,
"</outerBoundaryIs>" );
}
for( int iRing = 0; iRing < poPolygon->getNumInteriorRings(); iRing++ )
{
OGRLinearRing *poRing = poPolygon->getInteriorRing(iRing);
AppendString( ppszText, pnLength, pnMaxLength,
"<innerBoundaryIs>" );
if( !OGR2KMLGeometryAppend( poRing, ppszText, pnLength,
pnMaxLength, szAltitudeMode ) )
{
return false;
}
AppendString( ppszText, pnLength, pnMaxLength,
"</innerBoundaryIs>" );
}
AppendString( ppszText, pnLength, pnMaxLength,
"</Polygon>" );
}
/* -------------------------------------------------------------------- */
/* MultiPolygon */
/* -------------------------------------------------------------------- */
else if( wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon
|| wkbFlatten(poGeometry->getGeometryType()) == wkbMultiLineString
|| wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPoint
|| wkbFlatten(poGeometry->getGeometryType()) ==
wkbGeometryCollection )
{
OGRGeometryCollection* poGC = NULL;
poGC = static_cast<OGRGeometryCollection*>(poGeometry);
AppendString( ppszText, pnLength, pnMaxLength, "<MultiGeometry>" );
// XXX - mloskot
//if (NULL != szAltitudeMode)
//{
// AppendString( ppszText, pnLength, pnMaxLength, szAltitudeMode);
//}
for( int iMember = 0; iMember < poGC->getNumGeometries(); iMember++)
{
OGRGeometry *poMember = poGC->getGeometryRef( iMember );
if( !OGR2KMLGeometryAppend( poMember, ppszText, pnLength,
pnMaxLength, szAltitudeMode ) )
{
return false;
}
}
AppendString( ppszText, pnLength, pnMaxLength, "</MultiGeometry>" );
}
else
{
return false;
}
return true;
}
示例14: OGRMultiPolygon
OGRMultiPolygon* OGRILI1Layer::Polygonize( OGRGeometryCollection* poLines, bool fix_crossing_lines )
{
if (poLines->getNumGeometries() == 0)
{
return new OGRMultiPolygon();
}
#if defined(HAVE_GEOS)
GEOSGeom *ahInGeoms = NULL;
OGRGeometryCollection *poNoncrossingLines = poLines;
GEOSGeom hResultGeom = NULL;
OGRGeometry *poMP = NULL;
if (fix_crossing_lines && poLines->getNumGeometries() > 0)
{
CPLDebug( "OGR_ILI", "Fixing crossing lines");
//A union of the geometry collection with one line fixes invalid geometries
OGRGeometry* poUnion = poLines->Union(poLines->getGeometryRef(0));
if( poUnion != NULL )
{
if( wkbFlatten(poUnion->getGeometryType()) == wkbGeometryCollection ||
wkbFlatten(poUnion->getGeometryType()) == wkbMultiLineString )
{
poNoncrossingLines = dynamic_cast<OGRGeometryCollection*>(poUnion);
CPLDebug( "OGR_ILI", "Fixed lines: %d", poNoncrossingLines->getNumGeometries()-poLines->getNumGeometries());
}
else
{
delete poUnion;
}
}
}
GEOSContextHandle_t hGEOSCtxt = OGRGeometry::createGEOSContext();
ahInGeoms = (GEOSGeom *) CPLCalloc(sizeof(void*),poNoncrossingLines->getNumGeometries());
for( int i = 0; i < poNoncrossingLines->getNumGeometries(); i++ )
ahInGeoms[i] = poNoncrossingLines->getGeometryRef(i)->exportToGEOS(hGEOSCtxt);
hResultGeom = GEOSPolygonize_r( hGEOSCtxt,
ahInGeoms,
poNoncrossingLines->getNumGeometries() );
for( int i = 0; i < poNoncrossingLines->getNumGeometries(); i++ )
GEOSGeom_destroy_r( hGEOSCtxt, ahInGeoms[i] );
CPLFree( ahInGeoms );
if (poNoncrossingLines != poLines) delete poNoncrossingLines;
if( hResultGeom == NULL )
{
OGRGeometry::freeGEOSContext( hGEOSCtxt );
return new OGRMultiPolygon();
}
poMP = OGRGeometryFactory::createFromGEOS( hGEOSCtxt, hResultGeom );
GEOSGeom_destroy_r( hGEOSCtxt, hResultGeom );
OGRGeometry::freeGEOSContext( hGEOSCtxt );
poMP = OGRGeometryFactory::forceToMultiPolygon( poMP );
if( poMP && wkbFlatten(poMP->getGeometryType()) == wkbMultiPolygon )
return dynamic_cast<OGRMultiPolygon *>(poMP);
else
{
delete poMP;
return new OGRMultiPolygon();
}
#else
return new OGRMultiPolygon();
#endif
}
示例15: ProcessCommonGeometry
static void ProcessCommonGeometry(OGRGeometry* poGeom, OGRGeometry *poClipSrc,
int iBurnField, double dfBurnValue,
const double dfIncreaseBurnValue,
const double dfMultiplyBurnValue,
std::vector<double> &adfX,
std::vector<double> &adfY,
std::vector<double> &adfZ)
{
if (NULL == poGeom)
return;
OGRwkbGeometryType eType = wkbFlatten(poGeom->getGeometryType());
switch (eType)
{
case wkbPoint:
return ProcessGeometry((OGRPoint *)poGeom, poClipSrc,
iBurnField, dfBurnValue, dfIncreaseBurnValue, dfMultiplyBurnValue, adfX, adfY, adfZ);
case wkbLinearRing:
case wkbLineString:
{
OGRLineString *poLS = (OGRLineString*)poGeom;
OGRPoint point;
for (int pointIndex = 0; pointIndex < poLS->getNumPoints(); pointIndex++)
{
poLS->getPoint(pointIndex, &point);
ProcessCommonGeometry((OGRGeometry*)&point, poClipSrc,
iBurnField, dfBurnValue, dfIncreaseBurnValue, dfMultiplyBurnValue, adfX, adfY, adfZ);
}
}
break;
case wkbPolygon:
{
int nRings(0);
OGRPolygon* poPoly = (OGRPolygon*)poGeom;
OGRLinearRing* poRing = poPoly->getExteriorRing();
ProcessCommonGeometry((OGRGeometry*)poRing, poClipSrc,
iBurnField, dfBurnValue, dfIncreaseBurnValue, dfMultiplyBurnValue, adfX, adfY, adfZ);
nRings = poPoly->getNumInteriorRings();
if (nRings > 0)
{
for (int ir = 0; ir < nRings; ++ir)
{
OGRLinearRing* poRing = poPoly->getInteriorRing(ir);
ProcessCommonGeometry((OGRGeometry*)poRing, poClipSrc,
iBurnField, dfBurnValue, dfIncreaseBurnValue, dfMultiplyBurnValue, adfX, adfY, adfZ);
}
}
}
break;
case wkbMultiPoint:
case wkbMultiPolygon:
case wkbMultiLineString:
case wkbGeometryCollection:
{
OGRGeometryCollection* pOGRGeometryCollection = (OGRGeometryCollection*)poGeom;
for (int i = 0; i < pOGRGeometryCollection->getNumGeometries(); ++i)
{
ProcessCommonGeometry(pOGRGeometryCollection->getGeometryRef(i), poClipSrc,
iBurnField, dfBurnValue, dfIncreaseBurnValue, dfMultiplyBurnValue, adfX, adfY, adfZ);
}
}
break;
case wkbUnknown:
case wkbNone:
default:
break;
}
}