const void* FdoRdbmsSQLDataReader::GetGeometry(FdoInt32 index, FdoInt32* len, bool noExcOnInvalid)
{
    ValidateIndex(index);
    if( ! mHasMoreRows )
        throw FdoCommandException::Create(NlsMsgGet(FDORDBMS_62, noMoreRows));

    if (mGeomIdx != index)
    {
        FdoIGeometry* geom = NULL;
        bool isSupportedType = false;
        bool isNull = false;

        mGeomIdx = index;
        if (mWkbBuffer)
            *mWkbBuffer = 0;
        mQueryResult->GetBinaryValue (index+1, sizeof(FdoIGeometry *), (char*)&geom, &isNull, NULL);

        if ( !isNull && geom && geom->GetDerivedType() != FdoGeometryType_None )
            isSupportedType = true;

        if ( !isNull && geom != NULL )
        {
            if ( isSupportedType )
            {
                FdoPtr<FdoFgfGeometryFactory>  gf = FdoFgfGeometryFactory::GetInstance();
                FdoPtr<FdoByteArray> fgf = gf->GetFgf(geom);
                if (fgf != NULL && fgf->GetCount() != 0)
                {
                    mWkbGeomLen = fgf->GetCount();
                    if (mWkbBufferLen < mWkbGeomLen)
                    {
                        delete[] mWkbBuffer;
                        mWkbBufferLen = mWkbGeomLen;
                        mWkbBuffer = new unsigned char[mWkbGeomLen];
                    }
                    memcpy(mWkbBuffer, fgf->GetData(), mWkbGeomLen);
                }
                else
                    mWkbGeomLen = 0;
            }
            else
                mWkbGeomLen = -1;
        }
        else // isNull indicator is not set by dbi_get_val_b for geometry columns
            mWkbGeomLen = 0;
    }
    *len = mWkbGeomLen;
    if (*len <= 0)
    {
        if (noExcOnInvalid)
            return NULL;
        else if (*len == 0)
            throw FdoCommandException::Create(NlsMsgGet1( FDORDBMS_385, "Property '%1$ls' value is NULL; use IsNull method before trying to access the property value", mColList[index].column ));
        else
            throw FdoCommandException::Create( NlsMsgGet(FDORDBMS_116, "Unsupported geometry type" ) );
    }

    return mWkbBuffer;
}
FdoByteArray* FdoXmlFeatureReaderImpl::GetGeometry(FdoString* propertyName)
{
	FdoPtr<FdoXmlGeometry> geometry = GetCurrentFeatureForRead()->GetGeometricProperty(propertyName);
	if(geometry != NULL)
		return geometry->GetFgf();

	return NULL;
}
FdoByteArray* SpatialContextTest::SerializeExtent( double minX, double minY, double maxX, double maxY )
{
    // Create a byte array 
  	FdoPtr<FdoFgfGeometryFactory>  gf = FdoFgfGeometryFactory::GetInstance();
    FdoPtr<FdoIEnvelope>            env = gf->CreateEnvelopeXY(minX, minY, maxX, maxY );  
    FdoPtr<FdoIGeometry>            geom = gf->CreateGeometry(env); 

    return( gf->GetFgf(geom) );
}
void FdoImportExportTest::AddFeature( FdoIInsert* insertCommand, FdoInt32 idx )
{
    FdoPtr<FdoPropertyValueCollection> propertyValues = insertCommand->GetPropertyValues();
    FdoPtr<FdoDataValue> dataValue;
    FdoPtr<FdoPropertyValue> propertyValue;
    FdoPtr<FdoIConnection> connection = insertCommand->GetConnection();
    bool supportsZ = (FdoPtr<FdoIGeometryCapabilities>(connection->GetGeometryCapabilities())->GetDimensionalities() & FdoDimensionality_Z);

    dataValue = FdoDataValue::Create((FdoInt64) idx);
    propertyValue = AddNewProperty( propertyValues, L"Prop1");
    propertyValue->SetValue(dataValue);

    dataValue = FdoDataValue::Create((FdoString*)FdoStringP::Format(L"Prop2_Val%d",idx));
    propertyValue = AddNewProperty( propertyValues, L"Prop2");
    propertyValue->SetValue(dataValue);

    dataValue = FdoDataValue::Create((FdoString*)FdoStringP::Format(L"SubProp1_Val%d",idx));
    propertyValue = AddNewProperty( propertyValues, L"SubProp1");
    propertyValue->SetValue(dataValue);

    double       coordsBuffer[3];
    int          segCount = 1;

    coordsBuffer[0] = 5 * idx;
    coordsBuffer[1] = 10 * idx;
    coordsBuffer[2] = 0;

    propertyValue = AddNewProperty( propertyValues, L"Geometry");
    FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();
    
    FdoPtr<FdoIPoint> point1;
    if ( supportsZ ) 
        point1 = gf->CreatePoint(FdoDimensionality_XY|FdoDimensionality_Z, coordsBuffer);
    else
       point1 = gf->CreatePoint(FdoDimensionality_XY, coordsBuffer);
    
    FdoPtr<FdoByteArray> byteArray = gf->GetFgf(point1);
    FdoPtr<FdoGeometryValue> geometryValue = FdoGeometryValue::Create(byteArray);
    propertyValue->SetValue(geometryValue);

    FdoPtr<FdoIFeatureReader> reader = insertCommand->Execute();
}
bool FdoXmlFeatureReaderImpl::IsNull(FdoString* propertyName) 
{
	// implementation of this method is important
	FdoXmlFeatureReaderImpl* current = GetCurrentFeatureForRead();
	if (current->GetDataProperty(propertyName) != NULL)
		return false;
	FdoPtr<FdoXmlGeometry> geometry = current->GetGeometricProperty(propertyName);
	if (geometry != NULL) {
		FdoPtr<FdoByteArray> geomBin = geometry->GetFgf();
		if (geomBin != NULL)
			return false;
		return true;
	}
	FdoPtr<FdoLOBValue> lobValue = current->GetBLOBProperty(propertyName);
	if (lobValue != NULL)
		return false;
	FdoPtr<FdoXmlFeatureReaderImpl> assoValue = current->GetAssociationProperty(propertyName);
	if (assoValue != NULL)
		return false;

	return true;
}
bool FdoXmlSpatialContextReader::ReadNext()
{
    FdoXmlSaxContextP context = FdoXmlSaxContext::Create( mXmlReader );

    // Clear out extents for previously read spatial context
    mExtent = NULL;

    // Re-initialze the read handler so the next spatial context can be read.
    mSCHandler->Setup( mXmlFlags );

    // Read the next spatial context from XML.
    mXmlReader->Parse( this, context, true );

    context->ThrowErrors();

    if ( mSCHandler->mSCName.GetLength() > 0 ) {
        // A spatial context was found. Convert extents to byte array.
 	    FdoPtr<FdoFgfGeometryFactory>  gf = FdoFgfGeometryFactory::GetInstance();
        FdoPtr<FdoIEnvelope>            env = gf->CreateEnvelopeXY(
                                                mSCHandler->mMinX, 
                                                mSCHandler->mMinY, 
                                                mSCHandler->mMaxX, 
                                                mSCHandler->mMaxY 
                                              ); 

        FdoPtr<FdoIGeometry>            geom = gf->CreateGeometry(env); 

        mExtent =  gf->GetFgf(geom);
        mSCHandler->mFirst = false;

        return true;
    }
    else {
        // No spatial context found. We're done reading.
        return false;
    }
}
void FdoSpatialContextTest::InsertFeatures( FdoIConnection* connection )
{
    FdoPtr<FdoIInsert> insertCommand;
    FdoPtr<FdoPropertyValueCollection> propertyValues;
    FdoPtr<FdoDataValue> dataValue;
    FdoPtr<FdoPropertyValue> propertyValue;
    FdoPtr<FdoIFeatureReader> reader;


    insertCommand = (FdoIInsert *) connection->CreateCommand(FdoCommandType_Insert);
    insertCommand->SetFeatureClassName(L"ClassB1");

    propertyValues = insertCommand->GetPropertyValues();
    propertyValue;

    double       coordsBuffer[4];
    int          segCount = 2;
    FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();

    coordsBuffer[0] = 2.1;
    coordsBuffer[1] = 3.1;
    coordsBuffer[2] = 4.1;
    coordsBuffer[3] = 5.1;

    FdoPtr<FdoILineString> line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer);
    FdoPtr<FdoByteArray> byteArray = gf->GetFgf(line1);
    FdoPtr<FdoGeometryValue> geometryValue = FdoGeometryValue::Create(byteArray); 
    propertyValue = FdoPropertyValue::Create(L"Geometry1", geometryValue);
    propertyValues->Add(propertyValue);

    coordsBuffer[0] += 0.1;
    coordsBuffer[1] += 0.1;
    coordsBuffer[2] += 0.1;
    coordsBuffer[3] += 0.1;

    line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer);
    byteArray = gf->GetFgf(line1);
    geometryValue = FdoGeometryValue::Create(byteArray); 
    propertyValue = FdoPropertyValue::Create(L"Geometry2", geometryValue);
    propertyValues->Add(propertyValue);

    coordsBuffer[0] += 0.1;
    coordsBuffer[1] += 0.1;
    coordsBuffer[2] += 0.1;
    coordsBuffer[3] += 0.1;

    line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer);
    byteArray = gf->GetFgf(line1);
    geometryValue = FdoGeometryValue::Create(byteArray); 
    propertyValue = FdoPropertyValue::Create(L"Geometry3", geometryValue);
    propertyValues->Add(propertyValue);

    coordsBuffer[0] += 0.1;
    coordsBuffer[1] += 0.1;
    coordsBuffer[2] += 0.1;
    coordsBuffer[3] += 0.1;

    line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer);
    byteArray = gf->GetFgf(line1);
    geometryValue = FdoGeometryValue::Create(byteArray); 
    propertyValue = FdoPropertyValue::Create(L"Geometry4", geometryValue);
    propertyValues->Add(propertyValue);

    coordsBuffer[0] += 0.1;
    coordsBuffer[1] += 0.1;
    coordsBuffer[2] += 0.1;
    coordsBuffer[3] += 0.1;

    line1 = gf->CreateLineString(FdoDimensionality_XY, segCount*2, coordsBuffer);
    byteArray = gf->GetFgf(line1);
    geometryValue = FdoGeometryValue::Create(byteArray); 
    propertyValue = FdoPropertyValue::Create(L"Geometry5", geometryValue);
    propertyValues->Add(propertyValue);

    reader = insertCommand->Execute();
}