コード例 #1
0
OGRBoolean OGRGeometryCollection::Equals( const OGRGeometry * poOther ) const

{
    if( poOther == this )
        return TRUE;

    if( poOther->getGeometryType() != getGeometryType() )
        return FALSE;

    if( IsEmpty() && poOther->IsEmpty() )
        return TRUE;

    auto poOGC = poOther->toGeometryCollection();
    if( getNumGeometries() != poOGC->getNumGeometries() )
        return FALSE;

    // TODO(schwehr): Should test the SRS.

    for( int iGeom = 0; iGeom < nGeomCount; iGeom++ )
    {
        if( !getGeometryRef(iGeom)->Equals(poOGC->getGeometryRef(iGeom)) )
            return FALSE;
    }

    return TRUE;
}
コード例 #2
0
ファイル: ogrtools.cpp プロジェクト: lesserwhirls/Wave
void countGeometry(OGRGeometry* geom, size_t &numPoints, size_t &numObj)
{
    switch (geom->getGeometryType())
    {
    case wkbPolygon:
    {
        countGeometry(static_cast<OGRPolygon*>(geom), numPoints, numObj);
        break;
    }
    case wkbLineString:
    {
        countGeometry(static_cast<OGRLineString*>(geom), numPoints, numObj);
        break;
    }
    case wkbMultiPolygon:
    case wkbMultiLineString:
    {
        auto coll = static_cast<OGRGeometryCollection*>(geom);
        for (int i = 0; i < coll->getNumGeometries(); ++i)
        {
            countGeometry(coll->getGeometryRef(i), numPoints, numObj);
        }
        break;
    }
    default:
        qWarning() << "Unhandled geometry type:" << geom->getGeometryName();
    }
}
コード例 #3
0
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
0
ファイル: ogrtools.cpp プロジェクト: lesserwhirls/Wave
void extractGeometry(const OGRGeometry *geom, FeatureInfo& info)
{
    switch (geom->getGeometryType())
    {
    case wkbPolygon:
    {
        extractGeometry(static_cast<const OGRPolygon*>(geom), info);
        break;
    }
    case wkbLineString:
    {
        extractGeometry(static_cast<const OGRLineString*>(geom), info);
        break;
    }
    case wkbMultiLineString:
    case wkbMultiPolygon:
    {
        auto coll = static_cast<const OGRGeometryCollection*>(geom);
        for (int i = 0; i < coll->getNumGeometries(); ++i)
        {
            extractGeometry(coll->getGeometryRef(i), info);
        }
        break;
    }
    default:
        qWarning() << "Unhandled geometry type:" << geom->getGeometryName();
    }
}
コード例 #5
0
ファイル: ogrmultilinestring.cpp プロジェクト: puggan/OpenCPN
OGRErr OGRMultiLineString::exportToWkt( char ** ppszDstText ) const

{
    char        **papszLines;
    int         iLine, nCumulativeLength = 0;
    OGRErr      eErr;

    if( getNumGeometries() == 0 )
    {
        *ppszDstText = CPLStrdup("MULTILINESTRING(EMPTY)");
        return OGRERR_NONE;
    }

/* -------------------------------------------------------------------- */
/*      Build a list of strings containing the stuff for each ring.     */
/* -------------------------------------------------------------------- */
    papszLines = (char **) CPLCalloc(sizeof(char *),getNumGeometries());

    for( iLine = 0; iLine < getNumGeometries(); iLine++ )
    {
        eErr = getGeometryRef(iLine)->exportToWkt( &(papszLines[iLine]) );
        if( eErr != OGRERR_NONE )
            return eErr;

        CPLAssert( EQUALN(papszLines[iLine],"LINESTRING (", 12) );
        nCumulativeLength += strlen(papszLines[iLine] + 11);
    }

/* -------------------------------------------------------------------- */
/*      Allocate exactly the right amount of space for the              */
/*      aggregated string.                                              */
/* -------------------------------------------------------------------- */
    *ppszDstText = (char *) VSIMalloc(nCumulativeLength+getNumGeometries()+20);

    if( *ppszDstText == NULL )
        return OGRERR_NOT_ENOUGH_MEMORY;

/* -------------------------------------------------------------------- */
/*      Build up the string, freeing temporary strings as we go.        */
/* -------------------------------------------------------------------- */
    strcpy( *ppszDstText, "MULTILINESTRING (" );

    for( iLine = 0; iLine < getNumGeometries(); iLine++ )
    {
        if( iLine > 0 )
            strcat( *ppszDstText, "," );

        strcat( *ppszDstText, papszLines[iLine] + 11 );
        VSIFree( papszLines[iLine] );
    }

    strcat( *ppszDstText, ")" );

    CPLFree( papszLines );

    return OGRERR_NONE;
}
コード例 #6
0
OGRErr OGRMultiPoint::exportToWkt( char ** ppszDstText ) const

{
    int         nMaxString = getNumGeometries() * 20 + 128;
    int         nRetLen = 0;

    if( getNumGeometries() == 0 )
    {
        *ppszDstText = CPLStrdup("MULTIPOINT(EMPTY)");
        return OGRERR_NONE;
    }

    *ppszDstText = (char *) VSIMalloc( nMaxString );
    if( *ppszDstText == NULL )
        return OGRERR_NOT_ENOUGH_MEMORY;

    sprintf( *ppszDstText, "%s (", getGeometryName() );

    for( int i = 0; i < getNumGeometries(); i++ )
    {
        OGRPoint        *poPoint = (OGRPoint *) getGeometryRef( i );

        if( i > 0 )
            strcat( *ppszDstText + nRetLen, "," );

        nRetLen += strlen(*ppszDstText + nRetLen);

        if( nMaxString < nRetLen + 100 )
        {
            nMaxString = nMaxString * 2;
            *ppszDstText = (char *) CPLRealloc(*ppszDstText,nMaxString);
        }

        if( poPoint->getCoordinateDimension() == 3 )
            OGRMakeWktCoordinate( *ppszDstText + nRetLen,
                                  poPoint->getX(),
                                  poPoint->getY(),
                                  poPoint->getZ() );
        else
            OGRMakeWktCoordinate( *ppszDstText + nRetLen,
                                  poPoint->getX(),
                                  poPoint->getY(),
                                  0.0 );
    }

    strcat( *ppszDstText+nRetLen, ")" );

    return OGRERR_NONE;
}
コード例 #7
0
OGRGeometry *OGRMultiPoint::clone() const

{
    OGRMultiPoint       *poNewGC;

    poNewGC = new OGRMultiPoint;
    poNewGC->assignSpatialReference( getSpatialReference() );

    for( int i = 0; i < getNumGeometries(); i++ )
    {
        poNewGC->addGeometry( getGeometryRef(i) );
    }

    return poNewGC;
}
コード例 #8
0
double OGRMultiPolygon::get_Area() const

{
    double dfArea = 0.0;
    int iPoly;

    for( iPoly = 0; iPoly < getNumGeometries(); iPoly++ )
    {
        OGRPolygon *poPoly = (OGRPolygon *) getGeometryRef( iPoly );

        dfArea += poPoly->get_Area();
    }

    return dfArea;
}
コード例 #9
0
ファイル: OSMSDF.cpp プロジェクト: Hemofektik/Druckwelle
			bool LoadShapes(GDALDataset* dataset, QueryIntermediateData& qid)
			{
				OGRLayer* waterLayer = dataset->GetLayerByName("water");
				if (!waterLayer) return true; // requested layer may not be present in requested dataset

				waterLayer->ResetReading();

				OGRFeature* feature;
				while ((feature = waterLayer->GetNextFeature()) != NULL)
				{
					auto geo = feature->GetGeometryRef();
					auto featureId = feature->GetFID();

					if (qid.transform)
					{
						if (geo->transform(qid.transform) != OGRERR_NONE)
						{
							continue;
						}
					}

					if (geo->getGeometryType() == wkbMultiPolygon)
					{
						auto mp = (OGRMultiPolygon*)geo;
						const int numPolys = mp->getNumGeometries();
						for (int p = 0; p < numPolys; p++)
						{
							auto poly = new Polygon((OGRPolygon*)mp->getGeometryRef(p), featureId);

							qid.waterPolyQuadtree.Insert(poly);
							qid.waterPolygons.push_back(poly);
						}
					}
					else if (geo->getGeometryType() == wkbPolygon)
					{
						auto poly = new Polygon((OGRPolygon*)geo, featureId);

						qid.waterPolyQuadtree.Insert(poly);
						qid.waterPolygons.push_back(poly);
					}

					OGRFeature::DestroyFeature(feature);
				}

				return true;
			}
コード例 #10
0
OGRErr OGRMultiLineString::exportToWkt( char ** ppszDstText ) const

{
    char        **papszLines;
    int         iLine, nCumulativeLength = 0, nValidLineStrings=0;
    OGRErr      eErr;

/* -------------------------------------------------------------------- */
/*      Build a list of strings containing the stuff for each ring.     */
/* -------------------------------------------------------------------- */
    papszLines = (char **) CPLCalloc(sizeof(char *),getNumGeometries());

    for( iLine = 0; iLine < getNumGeometries(); iLine++ )
    {
        eErr = getGeometryRef(iLine)->exportToWkt( &(papszLines[iLine]) );
        if( eErr != OGRERR_NONE )
            return eErr;

        if( !EQUALN(papszLines[iLine],"LINESTRING (", 12) )
        {
            CPLDebug( "OGR", "OGRMultiLineString::exportToWkt() - skipping %s.",
                      papszLines[iLine] );
            CPLFree( papszLines[iLine] );
            papszLines[iLine] = NULL;
            continue;
        }

        nCumulativeLength += strlen(papszLines[iLine] + 11);
        nValidLineStrings++;
    }
    
/* -------------------------------------------------------------------- */
/*      Return MULTILINESTRING EMPTY if we get no valid line string.    */
/* -------------------------------------------------------------------- */
    if( nValidLineStrings == 0 )
    {
        CPLFree( papszLines );
        *ppszDstText = CPLStrdup("MULTILINESTRING EMPTY");
        return OGRERR_NONE;
    }

/* -------------------------------------------------------------------- */
/*      Allocate exactly the right amount of space for the              */
/*      aggregated string.                                              */
/* -------------------------------------------------------------------- */
    *ppszDstText = (char *) VSIMalloc(nCumulativeLength+getNumGeometries()+20);

    if( *ppszDstText == NULL )
        return OGRERR_NOT_ENOUGH_MEMORY;

/* -------------------------------------------------------------------- */
/*      Build up the string, freeing temporary strings as we go.        */
/* -------------------------------------------------------------------- */
    char *pszAppendPoint = *ppszDstText;

    strcpy( pszAppendPoint, "MULTILINESTRING (" );

    int bMustWriteComma = FALSE;
    for( iLine = 0; iLine < getNumGeometries(); iLine++ )
    {                                                           
        if( papszLines[iLine] == NULL )
            continue;

        if( bMustWriteComma )
            strcat( pszAppendPoint, "," );
        bMustWriteComma = TRUE;
        
        strcat( pszAppendPoint, papszLines[iLine] + 11 );
        pszAppendPoint += strlen(pszAppendPoint);

        VSIFree( papszLines[iLine] );
    }

    strcat( pszAppendPoint, ")" );

    CPLFree( papszLines );

    return OGRERR_NONE;
}
コード例 #11
0
OGRErr OGRMultiPolygon::exportToWkt( char ** ppszDstText ) const

{
    char        **papszPolygons;
    int         iPoly, nCumulativeLength = 0, nValidPolys=0;
    OGRErr      eErr;
    int         bMustWriteComma = FALSE;

    /* -------------------------------------------------------------------- */
    /*      Build a list of strings containing the stuff for each ring.     */
    /* -------------------------------------------------------------------- */
    papszPolygons = (char **) CPLCalloc(sizeof(char *),getNumGeometries());

    for( iPoly = 0; iPoly < getNumGeometries(); iPoly++ )
    {
        eErr = getGeometryRef(iPoly)->exportToWkt( &(papszPolygons[iPoly]) );
        if( eErr != OGRERR_NONE )
            goto error;

        if( !EQUALN(papszPolygons[iPoly],"POLYGON (", 9) )
        {
            CPLDebug( "OGR", "OGRMultiPolygon::exportToWkt() - skipping %s.",
                      papszPolygons[iPoly] );
            CPLFree( papszPolygons[iPoly] );
            papszPolygons[iPoly] = NULL;
            continue;
        }

        nCumulativeLength += strlen(papszPolygons[iPoly] + 8);
        nValidPolys++;
    }

    /* -------------------------------------------------------------------- */
    /*      Return MULTIPOLYGON EMPTY if we get no valid polygons.          */
    /* -------------------------------------------------------------------- */
    if( nValidPolys == 0 )
    {
        CPLFree( papszPolygons );
        *ppszDstText = CPLStrdup("MULTIPOLYGON EMPTY");
        return OGRERR_NONE;
    }

    /* -------------------------------------------------------------------- */
    /*      Allocate exactly the right amount of space for the              */
    /*      aggregated string.                                              */
    /* -------------------------------------------------------------------- */
    *ppszDstText = (char *) VSIMalloc(nCumulativeLength+getNumGeometries()+20);

    if( *ppszDstText == NULL )
    {
        eErr = OGRERR_NOT_ENOUGH_MEMORY;
        goto error;
    }

    /* -------------------------------------------------------------------- */
    /*      Build up the string, freeing temporary strings as we go.        */
    /* -------------------------------------------------------------------- */
    strcpy( *ppszDstText, "MULTIPOLYGON (" );
    nCumulativeLength = strlen(*ppszDstText);

    for( iPoly = 0; iPoly < getNumGeometries(); iPoly++ )
    {
        if( papszPolygons[iPoly] == NULL )
            continue;

        if( bMustWriteComma )
            (*ppszDstText)[nCumulativeLength++] = ',';
        bMustWriteComma = TRUE;

        int nPolyLength = strlen(papszPolygons[iPoly] + 8);
        memcpy( *ppszDstText + nCumulativeLength, papszPolygons[iPoly] + 8, nPolyLength );
        nCumulativeLength += nPolyLength;
        VSIFree( papszPolygons[iPoly] );
    }

    (*ppszDstText)[nCumulativeLength++] = ')';
    (*ppszDstText)[nCumulativeLength] = '\0';

    CPLFree( papszPolygons );

    return OGRERR_NONE;

error:
    for( iPoly = 0; iPoly < getNumGeometries(); iPoly++ )
        CPLFree( papszPolygons[iPoly] );
    CPLFree( papszPolygons );
    return eErr;
}
コード例 #12
0
ファイル: ogrmultipoint.cpp プロジェクト: Mavrx-inc/gdal
OGRErr OGRMultiPoint::exportToWkt( char ** ppszDstText,
                                   OGRwkbVariant eWkbVariant ) const

{
    size_t nMaxString = static_cast<size_t>(getNumGeometries()) * 22 + 130;
    size_t nRetLen = 0;

/* -------------------------------------------------------------------- */
/*      Return MULTIPOINT EMPTY if we get no valid points.              */
/* -------------------------------------------------------------------- */
    if( IsEmpty() )
    {
        if( eWkbVariant == wkbVariantIso )
        {
            if( (flags & OGR_G_3D) && (flags & OGR_G_MEASURED) )
                *ppszDstText = CPLStrdup("MULTIPOINT ZM EMPTY");
            else if( flags & OGR_G_MEASURED )
                *ppszDstText = CPLStrdup("MULTIPOINT M EMPTY");
            else if( flags & OGR_G_3D )
                *ppszDstText = CPLStrdup("MULTIPOINT Z EMPTY");
            else
                *ppszDstText = CPLStrdup("MULTIPOINT EMPTY");
        }
        else
            *ppszDstText = CPLStrdup("MULTIPOINT EMPTY");
        return OGRERR_NONE;
    }

    *ppszDstText = static_cast<char *>(VSI_MALLOC_VERBOSE( nMaxString ));
    if( *ppszDstText == NULL )
        return OGRERR_NOT_ENOUGH_MEMORY;

    if( eWkbVariant == wkbVariantIso )
    {
        if( (flags & OGR_G_3D) && (flags & OGR_G_MEASURED) )
            snprintf( *ppszDstText, nMaxString, "%s ZM (", getGeometryName() );
        else if( flags & OGR_G_MEASURED )
            snprintf( *ppszDstText, nMaxString, "%s M (", getGeometryName() );
        else if( flags & OGR_G_3D )
            snprintf( *ppszDstText, nMaxString, "%s Z (", getGeometryName() );
        else
            snprintf( *ppszDstText, nMaxString, "%s (", getGeometryName() );
    }
    else
        snprintf( *ppszDstText, nMaxString, "%s (", getGeometryName() );

    bool bMustWriteComma = false;
    for( int i = 0; i < getNumGeometries(); i++ )
    {
        OGRPoint *poPoint = (OGRPoint *) getGeometryRef( i );

        if( poPoint->IsEmpty() )
        {
            CPLDebug("OGR",
                     "OGRMultiPoint::exportToWkt() - skipping POINT EMPTY.");
            continue;
        }

        if( bMustWriteComma )
            strcat( *ppszDstText + nRetLen, "," );
        bMustWriteComma = true;

        nRetLen += strlen(*ppszDstText + nRetLen);

        if( nMaxString < nRetLen + 100 )
        {
            nMaxString = nMaxString * 2;
            *ppszDstText =
                static_cast<char *>(CPLRealloc(*ppszDstText, nMaxString));
        }

        if( eWkbVariant == wkbVariantIso )
        {
            strcat( *ppszDstText + nRetLen, "(" );
            nRetLen++;
        }

        OGRMakeWktCoordinateM(
            *ppszDstText + nRetLen,
            poPoint->getX(),
            poPoint->getY(),
            poPoint->getZ(),
            poPoint->getM(),
            poPoint->Is3D(),
            poPoint->IsMeasured() && (eWkbVariant == wkbVariantIso));

        if( eWkbVariant == wkbVariantIso )
        {
            strcat( *ppszDstText + nRetLen, ")" );
            nRetLen++;
        }
    }

    strcat( *ppszDstText+nRetLen, ")" );

    return OGRERR_NONE;
}
コード例 #13
0
ファイル: ogrmultipoint.cpp プロジェクト: drownedout/datamap
OGRErr OGRMultiPoint::exportToWkt( char ** ppszDstText,
                                   OGRwkbVariant eWkbVariant ) const

{
    int         nMaxString = getNumGeometries() * 22 + 128;
    int         nRetLen = 0;

/* -------------------------------------------------------------------- */
/*      Return MULTIPOINT EMPTY if we get no valid points.              */
/* -------------------------------------------------------------------- */
    if( IsEmpty() )
    {
        if( getCoordinateDimension() == 3 && eWkbVariant == wkbVariantIso )
            *ppszDstText = CPLStrdup("MULTIPOINT Z EMPTY");
        else
            *ppszDstText = CPLStrdup("MULTIPOINT EMPTY");
        return OGRERR_NONE;
    }

    *ppszDstText = (char *) VSIMalloc( nMaxString );
    if( *ppszDstText == NULL )
        return OGRERR_NOT_ENOUGH_MEMORY;

    if( getCoordinateDimension() == 3 && eWkbVariant == wkbVariantIso )
        sprintf( *ppszDstText, "%s Z (", getGeometryName() );
    else
        sprintf( *ppszDstText, "%s (", getGeometryName() );

    int bMustWriteComma = FALSE;
    for( int i = 0; i < getNumGeometries(); i++ )
    {
        OGRPoint        *poPoint = (OGRPoint *) getGeometryRef( i );

        if (poPoint->IsEmpty())
        {
            CPLDebug( "OGR", "OGRMultiPoint::exportToWkt() - skipping POINT EMPTY.");
            continue;
        }

        if( bMustWriteComma )
            strcat( *ppszDstText + nRetLen, "," );
        bMustWriteComma = TRUE;

        nRetLen += strlen(*ppszDstText + nRetLen);

        if( nMaxString < nRetLen + 100 )
        {
            nMaxString = nMaxString * 2;
            *ppszDstText = (char *) CPLRealloc(*ppszDstText,nMaxString);
        }

        if( eWkbVariant == wkbVariantIso )
        {
            strcat( *ppszDstText + nRetLen, "(" );
            nRetLen ++;
        }

        OGRMakeWktCoordinate( *ppszDstText + nRetLen,
                              poPoint->getX(), 
                              poPoint->getY(),
                              poPoint->getZ(),
                              poPoint->getCoordinateDimension() );

        if( eWkbVariant == wkbVariantIso )
        {
            strcat( *ppszDstText + nRetLen, ")" );
            nRetLen ++;
        }
    }

    strcat( *ppszDstText+nRetLen, ")" );

    return OGRERR_NONE;
}