OGRErr OGRGeometryCollection::exportToWkb( OGRwkbByteOrder eByteOrder, unsigned char * pabyData ) { int nOffset; /* -------------------------------------------------------------------- */ /* Set the byte order. */ /* -------------------------------------------------------------------- */ pabyData[0] = (unsigned char) eByteOrder; /* -------------------------------------------------------------------- */ /* Set the geometry feature type. */ /* -------------------------------------------------------------------- */ if( eByteOrder == wkbNDR ) { pabyData[1] = getGeometryType(); pabyData[2] = 0; pabyData[3] = 0; pabyData[4] = 0; } else { pabyData[1] = 0; pabyData[2] = 0; pabyData[3] = 0; pabyData[4] = getGeometryType(); } /* -------------------------------------------------------------------- */ /* Copy in the raw data. */ /* -------------------------------------------------------------------- */ if( OGR_SWAP( eByteOrder ) ) { int nCount; nCount = CPL_SWAP32( nGeomCount ); memcpy( pabyData+5, &nCount, 4 ); } else { memcpy( pabyData+5, &nGeomCount, 4 ); } nOffset = 9; /* ==================================================================== */ /* Serialize each of the Geoms. */ /* ==================================================================== */ for( int iGeom = 0; iGeom < nGeomCount; iGeom++ ) { papoGeoms[iGeom]->exportToWkb( eByteOrder, pabyData + nOffset ); nOffset += papoGeoms[iGeom]->WkbSize(); } return OGRERR_NONE; }
OGRErr OGRLineString::exportToWkb( OGRwkbByteOrder eByteOrder, unsigned char * pabyData ) const { /* -------------------------------------------------------------------- */ /* Set the byte order. */ /* -------------------------------------------------------------------- */ pabyData[0] = DB2_V72_UNFIX_BYTE_ORDER((unsigned char) eByteOrder); /* -------------------------------------------------------------------- */ /* Set the geometry feature type. */ /* -------------------------------------------------------------------- */ GUInt32 nGType = getGeometryType(); if( eByteOrder == wkbNDR ) nGType = CPL_LSBWORD32( nGType ); else nGType = CPL_MSBWORD32( nGType ); memcpy( pabyData + 1, &nGType, 4 ); /* -------------------------------------------------------------------- */ /* Copy in the data count. */ /* -------------------------------------------------------------------- */ memcpy( pabyData+5, &nPointCount, 4 ); /* -------------------------------------------------------------------- */ /* Copy in the raw data. */ /* -------------------------------------------------------------------- */ int i; if( getCoordinateDimension() == 3 ) { for( i = 0; i < nPointCount; i++ ) { memcpy( pabyData + 9 + 24*i, paoPoints+i, 16 ); memcpy( pabyData + 9 + 16 + 24*i, padfZ+i, 8 ); } } else memcpy( pabyData+9, paoPoints, 16 * nPointCount ); /* -------------------------------------------------------------------- */ /* Swap if needed. */ /* -------------------------------------------------------------------- */ if( OGR_SWAP( eByteOrder ) ) { int nCount; nCount = CPL_SWAP32( nPointCount ); memcpy( pabyData+5, &nCount, 4 ); for( i = getCoordinateDimension() * nPointCount - 1; i >= 0; i-- ) { CPL_SWAP64PTR( pabyData + 9 + 8 * i ); } } return OGRERR_NONE; }
OGRBoolean OGRPoint::Equals( OGRGeometry * poOther ) const { if( poOther== this ) return TRUE; if( poOther->getGeometryType() != getGeometryType() ) return FALSE; OGRPoint *poOPoint = dynamic_cast<OGRPoint *>(poOther); if( poOPoint == NULL ) { CPLError(CE_Fatal, CPLE_AppDefined, "dynamic_cast failed. Expected OGRPoint."); return FALSE; } if( flags != poOPoint->flags ) return FALSE; if( IsEmpty() ) return TRUE; // Should eventually test the SRS. if( poOPoint->getX() != getX() || poOPoint->getY() != getY() || poOPoint->getZ() != getZ() ) return FALSE; return TRUE; }
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; }
OGRBoolean OGRPolygon::Equal( OGRGeometry * poOther ) { OGRPolygon *poOPoly = (OGRPolygon *) poOther; if( poOther == this ) return TRUE; if( poOther->getGeometryType() != getGeometryType() ) return FALSE; if( getNumInteriorRings() != poOPoly->getNumInteriorRings() ) return FALSE; if( !getExteriorRing()->Equal( poOPoly->getExteriorRing() ) ) return FALSE; // we should eventually test the SRS. for( int iRing = 0; iRing < getNumInteriorRings(); iRing++ ) { if( !getInteriorRing(iRing)->Equal(poOPoly->getInteriorRing(iRing)) ) return FALSE; } return TRUE; }
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; }
OGRErr OGRPoint::exportToWkb( OGRwkbByteOrder eByteOrder, unsigned char * pabyData, OGRwkbVariant eWkbVariant ) const { /* -------------------------------------------------------------------- */ /* Set the byte order. */ /* -------------------------------------------------------------------- */ pabyData[0] = DB2_V72_UNFIX_BYTE_ORDER((unsigned char) eByteOrder); /* -------------------------------------------------------------------- */ /* Set the geometry feature type. */ /* -------------------------------------------------------------------- */ GUInt32 nGType = getGeometryType(); if ( eWkbVariant == wkbVariantIso ) nGType = getIsoGeometryType(); if( eByteOrder == wkbNDR ) nGType = CPL_LSBWORD32( nGType ); else nGType = CPL_MSBWORD32( nGType ); memcpy( pabyData + 1, &nGType, 4 ); /* -------------------------------------------------------------------- */ /* Copy in the raw data. */ /* -------------------------------------------------------------------- */ if ( IsEmpty() && eWkbVariant == wkbVariantIso ) { double dNan = std::numeric_limits<double>::quiet_NaN(); memcpy( pabyData+5, &dNan, 8 ); memcpy( pabyData+5+8, &dNan, 8 ); if( getCoordinateDimension() == 3 ) memcpy( pabyData+5+16, &dNan, 8 ); } else { memcpy( pabyData+5, &x, 16 ); if( getCoordinateDimension() == 3 ) { memcpy( pabyData + 5 + 16, &z, 8 ); } } /* -------------------------------------------------------------------- */ /* Swap if needed. */ /* -------------------------------------------------------------------- */ if( OGR_SWAP( eByteOrder ) ) { CPL_SWAPDOUBLE( pabyData + 5 ); CPL_SWAPDOUBLE( pabyData + 5 + 8 ); if( getCoordinateDimension() == 3 ) CPL_SWAPDOUBLE( pabyData + 5 + 16 ); } return OGRERR_NONE; }
OGRBoolean OGRLineString::Equal( OGRGeometry * poOther ) { OGRLineString *poOLine = (OGRLineString *) poOther; if( poOther == this ) return TRUE; if( poOther->getGeometryType() != getGeometryType() ) return FALSE; // we should eventually test the SRS. if( getNumPoints() != poOLine->getNumPoints() ) return FALSE; for( int iPoint = 1; iPoint < getNumPoints(); iPoint++ ) { if( getX(iPoint) != poOLine->getX(iPoint) || getY(iPoint) != poOLine->getY(iPoint) || getZ(iPoint) != poOLine->getZ(iPoint) ) return FALSE; } return TRUE; }
OGRGeometry* OGRGeometryCollection::getCurveGeometry( const char* const* papszOptions) const { OGRGeometryCollection* poGC = OGRGeometryFactory::createGeometry( OGR_GT_GetCurve(getGeometryType()))->toGeometryCollection(); if( poGC == nullptr ) return nullptr; poGC->assignSpatialReference( getSpatialReference() ); bool bHasCurveGeometry = false; for( int iGeom = 0; iGeom < nGeomCount; iGeom++ ) { OGRGeometry* poSubGeom = papoGeoms[iGeom]->getCurveGeometry(papszOptions); if( poSubGeom->hasCurveGeometry() ) bHasCurveGeometry = true; poGC->addGeometryDirectly( poSubGeom ); } if( !bHasCurveGeometry ) { delete poGC; return clone(); } return poGC; }
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; }
OGRErr OGRMultiCurve::importFromWkt( char ** ppszInput ) { int bIsMultiCurve = (wkbFlatten(getGeometryType()) == wkbMultiCurve); return importCurveCollectionFromWkt( ppszInput, TRUE, /* bAllowEmptyComponent */ bIsMultiCurve, /* bAllowLineString */ bIsMultiCurve, /* bAllowCurve */ bIsMultiCurve, /* bAllowCompoundCurve */ addCurveDirectlyFromWkt ); }
OGRErr OGRMultiCurve::importFromWkt( char ** ppszInput ) { const bool bIsMultiCurve = wkbFlatten(getGeometryType()) == wkbMultiCurve; return importCurveCollectionFromWkt( ppszInput, TRUE, // bAllowEmptyComponent. bIsMultiCurve, // bAllowLineString. bIsMultiCurve, // bAllowCurve. bIsMultiCurve, // bAllowCompoundCurve. addCurveDirectlyFromWkt ); }
OGRErr OGRPolygon::exportToWkb( OGRwkbByteOrder eByteOrder, unsigned char * pabyData ) const { int nOffset; int b3D = getCoordinateDimension() == 3; /* -------------------------------------------------------------------- */ /* Set the byte order. */ /* -------------------------------------------------------------------- */ pabyData[0] = DB2_V72_UNFIX_BYTE_ORDER((unsigned char) eByteOrder); /* -------------------------------------------------------------------- */ /* Set the geometry feature type. */ /* -------------------------------------------------------------------- */ GUInt32 nGType = getGeometryType(); if( eByteOrder == wkbNDR ) nGType = CPL_LSBWORD32( nGType ); else nGType = CPL_MSBWORD32( nGType ); memcpy( pabyData + 1, &nGType, 4 ); /* -------------------------------------------------------------------- */ /* Copy in the raw data. */ /* -------------------------------------------------------------------- */ if( OGR_SWAP( eByteOrder ) ) { int nCount; nCount = CPL_SWAP32( nRingCount ); memcpy( pabyData+5, &nCount, 4 ); } else { memcpy( pabyData+5, &nRingCount, 4 ); } nOffset = 9; /* ==================================================================== */ /* Serialize each of the rings. */ /* ==================================================================== */ for( int iRing = 0; iRing < nRingCount; iRing++ ) { papoRings[iRing]->_exportToWkb( eByteOrder, b3D, pabyData + nOffset ); nOffset += papoRings[iRing]->_WkbSize(b3D); } return OGRERR_NONE; }
OGRBoolean OGRCompoundCurve::Equals( OGRGeometry *poOther ) const { if( poOther == this ) return TRUE; if( poOther->getGeometryType() != getGeometryType() ) return FALSE; OGRCompoundCurve *poOCC = (OGRCompoundCurve *) poOther; return oCC.Equals(&(poOCC->oCC)); }
OGRErr OGRGeometryCollection::exportToWkb( OGRwkbByteOrder eByteOrder, unsigned char * pabyData ) const { int nOffset; /* -------------------------------------------------------------------- */ /* Set the byte order. */ /* -------------------------------------------------------------------- */ pabyData[0] = DB2_V72_UNFIX_BYTE_ORDER((unsigned char) eByteOrder); /* -------------------------------------------------------------------- */ /* Set the geometry feature type, ensuring that 3D flag is */ /* preserved. */ /* -------------------------------------------------------------------- */ GUInt32 nGType = getGeometryType(); if( eByteOrder == wkbNDR ) nGType = CPL_LSBWORD32( nGType ); else nGType = CPL_MSBWORD32( nGType ); memcpy( pabyData + 1, &nGType, 4 ); /* -------------------------------------------------------------------- */ /* Copy in the raw data. */ /* -------------------------------------------------------------------- */ if( OGR_SWAP( eByteOrder ) ) { int nCount; nCount = CPL_SWAP32( nGeomCount ); memcpy( pabyData+5, &nCount, 4 ); } else { memcpy( pabyData+5, &nGeomCount, 4 ); } nOffset = 9; /* ==================================================================== */ /* Serialize each of the Geoms. */ /* ==================================================================== */ for( int iGeom = 0; iGeom < nGeomCount; iGeom++ ) { papoGeoms[iGeom]->exportToWkb( eByteOrder, pabyData + nOffset ); nOffset += papoGeoms[iGeom]->WkbSize(); } return OGRERR_NONE; }
OGRBoolean OGRCurvePolygon::Equals( OGRGeometry * poOther ) const { if( poOther == this ) return TRUE; if( poOther->getGeometryType() != getGeometryType() ) return FALSE; if ( IsEmpty() && poOther->IsEmpty() ) return TRUE; OGRCurvePolygon *poOPoly = (OGRCurvePolygon *) poOther; return oCC.Equals( &(poOPoly->oCC) ); }
OGRErr OGRPoint::exportToWkb( OGRwkbByteOrder eByteOrder, unsigned char * pabyData ) const { /* -------------------------------------------------------------------- */ /* Set the byte order. */ /* -------------------------------------------------------------------- */ pabyData[0] = DB2_V72_UNFIX_BYTE_ORDER((unsigned char) eByteOrder); /* -------------------------------------------------------------------- */ /* Set the geometry feature type. */ /* -------------------------------------------------------------------- */ GUInt32 nGType = getGeometryType(); if( eByteOrder == wkbNDR ) nGType = CPL_LSBWORD32( nGType ); else nGType = CPL_MSBWORD32( nGType ); memcpy( pabyData + 1, &nGType, 4 ); /* -------------------------------------------------------------------- */ /* Copy in the raw data. */ /* -------------------------------------------------------------------- */ memcpy( pabyData+5, &nQual, 4 ); memcpy( pabyData+9, &x, 16 ); if( z != 0 ) { memcpy( pabyData + 9 + 16, &z, 8 ); } /* -------------------------------------------------------------------- */ /* Swap if needed. */ /* -------------------------------------------------------------------- */ if( OGR_SWAP( eByteOrder ) ) { CPL_SWAP32PTR( pabyData + 5 ); CPL_SWAPDOUBLE( pabyData + 9 ); CPL_SWAPDOUBLE( pabyData + 9 + 8 ); if( z != 0 ) CPL_SWAPDOUBLE( pabyData + 9 + 16 ); } return OGRERR_NONE; }
OGRGeometry* OGRGeometryCollection::getLinearGeometry(double dfMaxAngleStepSizeDegrees, const char* const* papszOptions) const { OGRGeometryCollection* poGC = (OGRGeometryCollection*) OGRGeometryFactory::createGeometry(OGR_GT_GetLinear(getGeometryType())); if( poGC == NULL ) return NULL; poGC->assignSpatialReference( getSpatialReference() ); for( int iGeom = 0; iGeom < nGeomCount; iGeom++ ) { OGRGeometry* poSubGeom = papoGeoms[iGeom]->getLinearGeometry(dfMaxAngleStepSizeDegrees, papszOptions); poGC->addGeometryDirectly( poSubGeom ); } return poGC; }
OGRGeometry *OGRCurvePolygon::clone() const { OGRCurvePolygon *poNewPolygon; poNewPolygon = (OGRCurvePolygon*) OGRGeometryFactory::createGeometry(getGeometryType()); poNewPolygon->assignSpatialReference( getSpatialReference() ); for( int i = 0; i < oCC.nCurveCount; i++ ) { poNewPolygon->addRing( oCC.papoCurves[i] ); } return poNewPolygon; }
shared_ptr<Geometry> ElementConverter::convertToGeometry(const shared_ptr<const Way>& e, const bool statsFlag) const { GeometryTypeId gid = getGeometryType(e, true, statsFlag); if (gid == GEOS_POLYGON) { return convertToPolygon(e); } else if (gid == GEOS_LINESTRING) { return convertToLineString(e); } else { // we don't recognize this geometry type. shared_ptr<Geometry> g(GeometryFactory::getDefaultInstance()->createEmptyGeometry()); return g; } }
OGRBoolean OGRPoint::Equals( OGRGeometry * poOther ) const { OGRPoint *poOPoint = (OGRPoint *) poOther; if( poOPoint== this ) return TRUE; if( poOther->getGeometryType() != getGeometryType() ) return FALSE; // we should eventually test the SRS. if( poOPoint->getX() != getX() || poOPoint->getY() != getY() || poOPoint->getZ() != getZ() ) return FALSE; else return TRUE; }
OGRGeometry *OGRGeometryCollection::clone() const { OGRGeometryCollection *poNewGC = OGRGeometryFactory::createGeometry(getGeometryType())-> toGeometryCollection(); poNewGC->assignSpatialReference( getSpatialReference() ); poNewGC->flags = flags; for( auto&& poSubGeom: *this ) { if( poNewGC->addGeometry( poSubGeom ) != OGRERR_NONE ) { delete poNewGC; return nullptr; } } return poNewGC; }
OGRGeometry * OGRPolygon::getCurveGeometry( const char* const* papszOptions ) const { OGRCurvePolygon* poCC = new OGRCurvePolygon(); poCC->assignSpatialReference( getSpatialReference() ); bool bHasCurveGeometry = false; for( auto&& poRing: *this ) { auto poSubGeom = poRing->getCurveGeometry(papszOptions); if( wkbFlatten(poSubGeom->getGeometryType()) != wkbLineString ) bHasCurveGeometry = true; poCC->addRingDirectly( poSubGeom->toCurve() ); } if( !bHasCurveGeometry ) { delete poCC; return clone(); } return poCC; }
shared_ptr<Geometry> ElementConverter::convertToGeometry(const shared_ptr<const Relation>& e, const bool statsFlag) const { GeometryTypeId gid = getGeometryType(e, true, statsFlag); if (gid == GEOS_MULTIPOLYGON) { return MultiPolygonCreator(_constProvider, e).createMultipolygon(); } else if (gid == GEOS_MULTILINESTRING) { MultiLineStringVisitor v; v.setElementProvider(_constProvider); e->visitRo(*_constProvider, v); shared_ptr<Geometry> result(v.createMultiLineString()); return result; } else { // we don't recognize this geometry type. shared_ptr<Geometry> g(GeometryFactory::getDefaultInstance()->createEmptyGeometry()); return g; } }
OGRGeometry *OGRGeometryCollection::clone() const { OGRGeometryCollection *poNewGC; poNewGC = (OGRGeometryCollection*) OGRGeometryFactory::createGeometry(getGeometryType()); if( poNewGC == NULL ) return NULL; poNewGC->assignSpatialReference( getSpatialReference() ); poNewGC->flags = flags; for( int i = 0; i < nGeomCount; i++ ) { if( poNewGC->addGeometry( papoGeoms[i] ) != OGRERR_NONE ) { delete poNewGC; return NULL; } } return poNewGC; }
OGRBoolean OGRPoint::Equals( OGRGeometry * poOther ) const { if( poOther== this ) return TRUE; if( poOther->getGeometryType() != getGeometryType() ) return FALSE; OGRPoint *poOPoint = (OGRPoint *) poOther; if ( nCoordDimension != poOPoint->nCoordDimension ) return FALSE; if ( IsEmpty() ) return TRUE; // we should eventually test the SRS. if( poOPoint->getX() != getX() || poOPoint->getY() != getY() || poOPoint->getZ() != getZ() ) return FALSE; else return TRUE; }
bool Matrix4::isIdentity() const { return getGeometryType() == kTypeIdentity; }
bool Matrix4::isSimple() const { return getGeometryType() <= (kTypeScale | kTypeTranslate); }
bool Matrix4::isPureTranslate() const { return getGeometryType() == kTypeTranslate; }
OGRErr OGRPolygon::exportToWkb( OGRwkbByteOrder eByteOrder, unsigned char * pabyData, OGRwkbVariant eWkbVariant ) const { /* -------------------------------------------------------------------- */ /* Set the byte order. */ /* -------------------------------------------------------------------- */ pabyData[0] = DB2_V72_UNFIX_BYTE_ORDER(static_cast<unsigned char>(eByteOrder)); /* -------------------------------------------------------------------- */ /* Set the geometry feature type. */ /* -------------------------------------------------------------------- */ GUInt32 nGType = getGeometryType(); if( eWkbVariant == wkbVariantPostGIS1 ) { nGType = wkbFlatten(nGType); if( Is3D() ) // Explicitly set wkb25DBit. nGType = static_cast<OGRwkbGeometryType>(nGType | wkb25DBitInternalUse); if( IsMeasured() ) nGType = static_cast<OGRwkbGeometryType>(nGType | 0x40000000); } else if( eWkbVariant == wkbVariantIso ) nGType = getIsoGeometryType(); if( OGR_SWAP( eByteOrder ) ) { nGType = CPL_SWAP32(nGType); } memcpy( pabyData + 1, &nGType, 4 ); /* -------------------------------------------------------------------- */ /* Copy in the raw data. */ /* -------------------------------------------------------------------- */ if( OGR_SWAP( eByteOrder ) ) { const int nCount = CPL_SWAP32( oCC.nCurveCount ); memcpy( pabyData+5, &nCount, 4 ); } else { memcpy( pabyData+5, &oCC.nCurveCount, 4 ); } /* ==================================================================== */ /* Serialize each of the rings. */ /* ==================================================================== */ int nOffset = 9; for( int iRing = 0; iRing < oCC.nCurveCount; iRing++ ) { OGRLinearRing* poLR = (OGRLinearRing*) oCC.papoCurves[iRing]; poLR->_exportToWkb( eByteOrder, flags, pabyData + nOffset ); nOffset += poLR->_WkbSize( flags ); } return OGRERR_NONE; }