void FdoImportExportTest::Test8 ()
{
    try {
        FdoIoStreamP configStream = FdoIoMemoryStream::Create();

        CreateConfigBadWkt( configStream );

        // Test 8 tries adding a spatial context whose WKT differs
        // from what Oracle defines for its coordinate system.
        // This test should fail for Oracle and pass for the others.
        printf( "Test8 (junk WKT) ... \n" );

        printf( "\tOpening Source Connection ... \n" );
        FdoPtr<FdoIConnection> connection = UnitTestUtil::CreateConnection(
		    true,
		    true,
            DB_NAME_SRC_SUFFIX,
            NULL,
            NULL,
            0
	    );

        FdoPtr<FdoIConnectionCapabilities> cap = connection->GetConnectionCapabilities();

        // Import from the input XML document
        printf( "\tImporting ...\n" );

        Import(
            connection, 
            configStream,
            NULL,
            true,
            false
        );

        FdoPtr<FdoIGetSpatialContexts> cmd = (FdoIGetSpatialContexts*) connection->CreateCommand( FdoCommandType_GetSpatialContexts );
        cmd->SetActiveOnly(false);

        FdoPtr<FdoISpatialContextReader> reader = cmd->Execute();

        while ( reader->ReadNext() ) {
            // Skip default spatial context if not writing it.
            if ( wcscmp(reader->GetName(), L"Manhole1") == 0 ) {
                if ( cap->SupportsCSysWKTFromCSysName() )
                    CPPUNIT_ASSERT( wcscmp(reader->GetCoordinateSystemWkt(), L"LOCAL_CS [ \"Non-Earth (Meter)\", LOCAL_DATUM [\"Local Datum\", 0], UNIT [\"Meter\", 1.0], AXIS [\"X\", EAST], AXIS[\"Y\", NORTH]]") == 0 );
                else
                    CPPUNIT_ASSERT( wcscmp(reader->GetCoordinateSystemWkt(), L"nonsense wkt") == 0 );
            }
        }
    }
	catch ( FdoException* e ) 
	{
		UnitTestUtil::FailOnException( e );
    }

	printf( "Done\n" );
}
void SuperMapConnection::CreateSpatialContext(
								FdoString* name,
								FdoString* description,
								FdoString* coordinateSystem,
								FdoString* coordinateSystemWkt,
								FdoSpatialContextExtentType extentType,
								FdoByteArray * extent,
								double xyTolerance,
								double zTolerance,
								bool   update
							)
{
	bool found = false;

	// 检查是否有同一个WKT空间语义存在
	for(FdoInt32 i = 0; i < m_SpatialContextColl->GetCount() && !found; ++i)
	{
		FdoPtr<SuperMapSpatialContext>	sp = m_SpatialContextColl->GetItem(i);
		found = (coordinateSystemWkt == sp->GetCoordinateSystemWkt());
	}

	// 赋新的坐标系
	if(!found)
	{
		FdoPtr<SuperMapSpatialContext> newSp = new SuperMapSpatialContext();
		FdoInt32 idxGenName = 1;
		FdoStringP newName = name;

		// 查找重复的空间语义名,在名字后加数字避免重名
		while(m_SpatialContextColl->FindItem(newName))
		{
			newName = FdoStringP::Format(L"%ls_%d", (FdoString*)name, idxGenName);
			idxGenName++;
		}

		//设置新的空间语义
		newSp->SetName(newName);
		newSp->SetCoordSysName(coordinateSystem);
		newSp->SetCoordinateSystemWkt(coordinateSystemWkt);

		newSp->SetDescription(description); 
		newSp->SetExtent(extent);
		newSp->SetExtentType(extentType);
		newSp->SetXYTolerance(xyTolerance);
		newSp->SetZTolerance(zTolerance);

		m_SpatialContextColl->Add(newSp);
		
		//Todo: 往物理数据源中添加投影信息是否在此做?
		
	}

}
Example #3
0
EGwsStatus GwsCommonFdoUtils::DescribeSC (
    FdoIConnection               * conn,
    FdoString                    * scname,
    GwsSpatialContextDescription & scdesc
)
{

    FdoPtr<FdoIGetSpatialContexts>   cmd;
    FdoPtr<FdoISpatialContextReader> reader;
    scdesc.SetClassName (GWSQualifiedName ());
    scdesc.SetPropertyName (NULL);
    scdesc.SetSpatialContextName (NULL);
    scdesc.SetSpatialContextDesc (NULL);
    scdesc.SetCsNameWkt (NULL);

    if (scname == NULL || * scname == 0)
        return eGwsOk;

    try {
        cmd = (FdoIGetSpatialContexts *) conn->CreateCommand (FdoCommandType_GetSpatialContexts);
        reader = cmd->Execute ();
        while (reader->ReadNext ()) {
            if (wcscmp (reader->GetName (), scname) == 0) {
                FdoString * cswkt = reader->GetCoordinateSystemWkt ();
                FdoString * desc  = reader->GetDescription ();
                double xytol = reader->GetXYTolerance();
                scdesc.SetCsNameWkt (cswkt);
                scdesc.SetSpatialContextDesc (desc);
                scdesc.SetSpatialContextName (scname);
                scdesc.SetXYTolerance(xytol);

                FdoPtr<FdoByteArray> pByteArray = reader->GetExtent();
                if (pByteArray) {
                    FdoPtr<FdoFgfGeometryFactory> pAwkbFactory = FdoFgfGeometryFactory::GetInstance();
                    FdoPtr<FdoIGeometry> pGeometry = pAwkbFactory->CreateGeometryFromFgf(pByteArray);
                    FdoPtr<FdoIEnvelope> pEnvelope = pGeometry->GetEnvelope();
                    scdesc.SetExtents (pEnvelope);
                }

                return eGwsOk;
            }
        }
        return eGwsSCNotFound;

    } catch (FdoException * fdoEx) {
        fdoEx->Release ();
    }
    // in case when exception thrown, assume that sc are not
    // supported.
    return eGwsNotSupported;
}