Esempio n. 1
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;
}
void FdoRdbmsMySqlFilterProcessor::ProcessSpatialCondition (FdoSpatialCondition &filter)
{
//TODO: This function's implementation is a temporary one used by the MySql demo. It must be replaced
// by a proper implementation when full spatial support is added to the MySql provider.
//
// However, the following illustrates a problem that was encountered. Spatial query result sets become
// unreliable ( sometimes they work and sometimes they return no rows when there should be some ) when
// the spatial area coordinates contain fractional parts. This is currently worked around by casting 
// these coordinates to long.
    DbiConnection  *mDbiConnection = mFdoConnection->GetDbiConnection();
    const FdoSmLpClassDefinition *classDefinition = mDbiConnection->GetSchemaUtil()->GetClass(mCurrentClassName);
    if (classDefinition == NULL ||  classDefinition->GetClassType() != FdoClassType_FeatureClass)
        throw FdoFilterException::Create(NlsMsgGet(FDORDBMS_230, "Spatial condition can only be used with feature classes"));

    const FdoSmLpGeometricPropertyDefinition* geomProp =
                    GetGeometricProperty(classDefinition,
                                         FdoPtr<FdoIdentifier>(filter.GetPropertyName())->GetName());
    const FdoString* classTableName = classDefinition->GetDbObjectName();
    const FdoString* tableName = geomProp ? geomProp->GetContainingDbObjectName() : L""; // The geometry table name
    FdoStringP columnName = GetGeometryColumnNameForProperty(geomProp, true);
    FdoStringP columnName2 = GetGeometryColumnNameForProperty(geomProp, false);

    FdoStringP spatialClause;
    FdoPtr<FdoGeometryValue> geom = dynamic_cast<FdoGeometryValue*>(filter.GetGeometry());
    FdoPtr<FdoFgfGeometryFactory>  gf;
    FdoPtr<FdoByteArray> geomFgf;
    FdoPtr<FdoIGeometry> geometryObj;

    geomFgf = geom->GetGeometry();

    if (geomFgf == NULL)
        throw FdoFilterException::Create(NlsMsgGet(FDORDBMS_46, "No geometry value"));

    // Geometry factory
    gf = FdoFgfGeometryFactory::GetInstance();

    geometryObj = gf->CreateGeometryFromFgf(geomFgf);

    FdoPtr<FdoIEnvelope> env = geometryObj->GetEnvelope();

    double minx = env->GetMinX();
    double miny = env->GetMinY();
    double maxx = env->GetMaxX();
    double maxy = env->GetMaxY();

    wchar_t minxStr[NUMBER_FORMAT_SIZE];
    wchar_t minyStr[NUMBER_FORMAT_SIZE];
    wchar_t maxxStr[NUMBER_FORMAT_SIZE];
    wchar_t maxyStr[NUMBER_FORMAT_SIZE];

    FdoCommonStringUtil::FormatDouble(minx, minxStr, NUMBER_FORMAT_SIZE);
    FdoCommonStringUtil::FormatDouble(miny, minyStr, NUMBER_FORMAT_SIZE);
    FdoCommonStringUtil::FormatDouble(maxx, maxxStr, NUMBER_FORMAT_SIZE);
    FdoCommonStringUtil::FormatDouble(maxy, maxyStr, NUMBER_FORMAT_SIZE);

    // In MySQL 5.0, there really is no secondary filter -- the MBR family of functions
    // give the same results as the non-MBR functions, and often aren't even as selective
    // as advertised.  Plus, some clients pass in geometry conditions with extra dimensions.
    // For now, we'll take advantage of MySQL's limitations and reduce all geometry types
    // and dimensionalities to a 2D polygon with one ring, and just use the MBRIntersects operator.
    FdoStringP buf = FdoStringP::Format(L"MBRIntersects(GeomFromText('Polygon((%ls %ls,%ls %ls,%ls %ls,%ls %ls,%ls %ls))'),\"%ls\")",
            minxStr, minyStr,
            maxxStr, minyStr,
            maxxStr, maxyStr,
            minxStr, maxyStr,
            minxStr, minyStr,
            (FdoString*) columnName);
    AppendString((const wchar_t*)buf);
}