예제 #1
0
OGRErr OGRSpatialReference::exportToXML(char **ppszRawXML,
                                        const char *pszDialect) const

{
    CPLXMLNode *psXMLTree = NULL;

    if (IsGeographic())
    {
        psXMLTree = exportGeogCSToXML(this);
    }
    else if (IsProjected())
    {
        psXMLTree = exportProjCSToXML(this);
    }
    else
        return OGRERR_UNSUPPORTED_SRS;

    *ppszRawXML = CPLSerializeXMLTree(psXMLTree);
    CPLDestroyXMLNode(psXMLTree);

    return OGRERR_NONE;
}
예제 #2
0
OGRErr OGRSpatialReference::exportToERM( char *pszProj, char *pszDatum, 
                                         char *pszUnits )

{
    strcpy( pszProj, "RAW" );
    strcpy( pszDatum, "RAW" );
    strcpy( pszUnits, "METERS" );

    if( !IsProjected() && !IsGeographic() )
        return TRUE;

/* -------------------------------------------------------------------- */
/*      Try to find the EPSG code.                                      */
/* -------------------------------------------------------------------- */
    int nEPSGCode = 0;

    if( IsProjected() )
    {
        const char *pszAuthName = GetAuthorityName( "PROJCS" );

        if( pszAuthName != NULL && EQUAL(pszAuthName,"epsg") )
        {
            nEPSGCode = atoi(GetAuthorityCode( "PROJCS" ));
        }
    }
    else if( IsGeographic() )
    {
        const char *pszAuthName = GetAuthorityName( "GEOGCS" );

        if( pszAuthName != NULL && EQUAL(pszAuthName,"epsg") )
        {
            nEPSGCode = atoi(GetAuthorityCode( "GEOGCS" ));
        }
    }

/* -------------------------------------------------------------------- */
/*      Is our GEOGCS name already defined in ecw_cs.dat?               */
/* -------------------------------------------------------------------- */
    OGRSpatialReference oSRSWork;
    const char *pszWKTDatum = GetAttrValue( "DATUM" );

    if( pszWKTDatum != NULL 
        && oSRSWork.importFromDict( "ecw_cs.wkt", pszWKTDatum ) == OGRERR_NONE)
    {
        strncpy( pszDatum, pszWKTDatum, 32 );
        pszDatum[31] = '\0';
    }

/* -------------------------------------------------------------------- */
/*      Is this a "well known" geographic coordinate system?            */
/* -------------------------------------------------------------------- */
    if( EQUAL(pszDatum,"RAW") )
    {
        int nEPSGGCSCode = GetEPSGGeogCS();

        if( nEPSGGCSCode == 4326 )
            strcpy( pszDatum, "WGS84" );

        else if( nEPSGGCSCode == 4322 )
            strcpy( pszDatum, "WGS72DOD" );
        
        else if( nEPSGGCSCode == 4267 )
            strcpy( pszDatum, "NAD27" );
        
        else if( nEPSGGCSCode == 4269 )
            strcpy( pszDatum, "NAD83" );

        else if( nEPSGGCSCode == 4277 )
            strcpy( pszDatum, "OSGB36" );

        else if( nEPSGGCSCode == 4278 )
            strcpy( pszDatum, "OSGB78" );

        else if( nEPSGGCSCode == 4201 )
            strcpy( pszDatum, "ADINDAN" );

        else if( nEPSGGCSCode == 4202 )
            strcpy( pszDatum, "AGD66" );

        else if( nEPSGGCSCode == 4203 )
            strcpy( pszDatum, "AGD84" );

        else if( nEPSGGCSCode == 4209 )
            strcpy( pszDatum, "ARC1950" );

        else if( nEPSGGCSCode == 4210 )
            strcpy( pszDatum, "ARC1960" );

        else if( nEPSGGCSCode == 4275 )
            strcpy( pszDatum, "NTF" );

        else if( nEPSGGCSCode == 4283 )
            strcpy( pszDatum, "GDA94" );

        else if( nEPSGGCSCode == 4284 )
            strcpy( pszDatum, "PULKOVO" );
    }

/* -------------------------------------------------------------------- */
/*      Are we working with a geographic (geodetic) coordinate system?  */
/* -------------------------------------------------------------------- */

    if( IsGeographic() )
    {
        if( EQUAL(pszDatum,"RAW") )
            return OGRERR_UNSUPPORTED_SRS;
        else
        {
            strcpy( pszProj, "GEODETIC" );
            return OGRERR_NONE;
        }
    }

/* -------------------------------------------------------------------- */
/*      Is this a UTM projection?                                       */
/* -------------------------------------------------------------------- */
    int bNorth, nZone;

    nZone = GetUTMZone( &bNorth );
    if( nZone > 0 )
    {
        if( EQUAL(pszDatum,"GDA94") && !bNorth && nZone >= 48 && nZone <= 58)
        {
            sprintf( pszProj, "MGA%02d", nZone );
        }
        else
        {
            if( bNorth )
                sprintf( pszProj, "NUTM%02d", nZone );
            else
                sprintf( pszProj, "SUTM%02d", nZone );
        }
    }

/* -------------------------------------------------------------------- */
/*      Is our PROJCS name already defined in ecw_cs.dat?               */
/* -------------------------------------------------------------------- */
    else
    {
        const char *pszPROJCS = GetAttrValue( "PROJCS" );

        if( pszPROJCS != NULL 
            && oSRSWork.importFromDict( "ecw_cs.wkt", pszPROJCS ) == OGRERR_NONE 
            && oSRSWork.IsProjected() )
        {
            strncpy( pszProj, pszPROJCS, 32 );
            pszProj[31] = '\0';
        }
    }

/* -------------------------------------------------------------------- */
/*      If we have not translated it yet, but we have an EPSG code      */
/*      then use EPSG:n notation.                                       */
/* -------------------------------------------------------------------- */
    if( (EQUAL(pszDatum,"RAW") || EQUAL(pszProj,"RAW")) && nEPSGCode != 0 )
    {
        sprintf( pszProj, "EPSG:%d", nEPSGCode );
        sprintf( pszDatum, "EPSG:%d", nEPSGCode );
    }

/* -------------------------------------------------------------------- */
/*      Handle the units.                                               */
/* -------------------------------------------------------------------- */
    double dfUnits = GetLinearUnits();

    if( fabs(dfUnits-0.3048) < 0.0001 )
        strcpy( pszUnits, "FEET" );
    else
        strcpy( pszUnits, "METERS" );
       
    if( EQUAL(pszProj,"RAW") )
        return OGRERR_UNSUPPORTED_SRS;
    else
        return OGRERR_NONE;
}
예제 #3
0
파일: Writer.cpp 프로젝트: xhy20070406/PDAL
void Writer::CreatePCEntry(Schema const& buffer_schema)
{


    boost::uint32_t precision = getDefaultedOption<boost::uint32_t>("stream_output_precision");
    boost::uint32_t capacity = getDefaultedOption<boost::uint32_t>("capacity");




    std::ostringstream oss;


    oss.setf(std::ios_base::fixed, std::ios_base::floatfield);
    oss.precision(precision);

    std::ostringstream columns;
    std::ostringstream values;

    if (!m_base_table_aux_columns.empty())
    {
        columns << m_cloud_column_name << "," << m_base_table_aux_columns;

        values << "pc," << m_base_table_aux_values;
    }
    else
    {
        columns << m_cloud_column_name;
        values << "pc";
    }

    int nPCPos = 1;
    int nSchemaPos = 1;
    nSchemaPos++;

    int nPos = nSchemaPos; // Bind column position

    if (!m_base_table_boundary_column.empty())
    {
        columns << "," << m_base_table_boundary_column;
        nPos++;
        values <<", SDO_GEOMETRY(:"<<nPos;
        nPos++;
        values <<", :"<<nPos<<")";
    }



    std::ostringstream s_srid;
    std::ostringstream s_geom;
    std::ostringstream s_schema;


    // IsGeographic(srid);

    if (m_srid == 0)
    {
        s_srid << "NULL";
    }
    else
    {
        s_srid << m_srid;
    }

    s_schema << "xmltype(:"<<nSchemaPos<<")";



    std::string eleminfo = CreatePCElemInfo();

    pdal::Bounds<double> base_table_bounds = getDefaultedOption<pdal::Bounds<double> >("base_table_bounds");

    if (base_table_bounds.empty())
    {
        if (IsGeographic(m_srid))
        {
            base_table_bounds.setMinimum(0, -179.99);
            base_table_bounds.setMinimum(1, -89.99);
            base_table_bounds.setMinimum(2, 0.0);
            base_table_bounds.setMaximum(0, 179.99);
            base_table_bounds.setMaximum(1, 89.99);
            base_table_bounds.setMaximum(2, 20000.0);
        }
        else
        {
            base_table_bounds.setMinimum(0, 0.0);
            base_table_bounds.setMinimum(1, 0.0);
            base_table_bounds.setMinimum(2, 0.0);
            base_table_bounds.setMaximum(0, 100.0);
            base_table_bounds.setMaximum(1, 100.0);
            base_table_bounds.setMaximum(2, 20000.0);
        }
    }
    s_geom << "           mdsys.sdo_geometry("<< m_gtype <<", "<<s_srid.str()<<", null,\n"
           "              mdsys.sdo_elem_info_array"<< eleminfo <<",\n"
           "              mdsys.sdo_ordinate_array(\n";

    s_geom << base_table_bounds.getMinimum(0) << "," << base_table_bounds.getMinimum(1) << ",";

    if (m_is3d)
    {
        s_geom << base_table_bounds.getMinimum(2) << ",";
    }

    s_geom << base_table_bounds.getMaximum(0) << "," << base_table_bounds.getMaximum(1);

    if (m_is3d)
    {
        s_geom << "," << base_table_bounds.getMaximum(2);
    }

    s_geom << "))";

    boost::uint32_t dimensions = 8;

    oss << "declare\n"
        "  pc_id NUMBER := :"<<nPCPos<<";\n"
        "  pc sdo_pc;\n"

        "begin\n"
        "  -- Initialize the Point Cloud object.\n"
        "  pc := sdo_pc_pkg.init( \n"
        "          '"<< m_base_table_name<<"', -- Table that has the SDO_POINT_CLOUD column defined\n"
        "          '"<< m_cloud_column_name<<"',   -- Column name of the SDO_POINT_CLOUD object\n"
        "          '"<< m_block_table_name <<"', -- Table to store blocks of the point cloud\n"
        "           'blk_capacity="<< capacity <<"', -- max # of points per block\n"
        << s_geom.str() <<
        ",  -- Extent\n"
        "     0.5, -- Tolerance for point cloud\n"
        "           "<<dimensions<<", -- Total number of dimensions\n"
        "           NULL,"
        "            NULL,"
        "            "<< s_schema.str() <<");\n"
        "  :"<<nPCPos<<" := pc.pc_id;\n"

        "  -- Insert the Point Cloud object  into the \"base\" table.\n"
        "  insert into " << m_base_table_name << " ( ID, "<< columns.str() <<
        ") values ( pc.pc_id, " << values.str() << ");\n"

        "  "
        "end;\n";

    Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str()));

    statement->Bind(&m_pc_id);


    OCILobLocator* schema_locator ;
    OCILobLocator* boundary_locator ;

    std::string schema_data;

    bool pack = getOptions().getValueOrDefault<bool>("pack_ignored_fields", true);
    if (pack)
    {
        schema::index_by_index const& idx = buffer_schema.getDimensions().get<schema::index>();
        log()->get(logDEBUG3) << "Packing ignored dimension from PointBuffer " << std::endl;

        boost::uint32_t position(0);
        
        pdal::Schema clean_schema;
        schema::index_by_index::size_type i(0);
        for (i = 0; i < idx.size(); ++i)
        {
            if (! idx[i].isIgnored())
            {
                
                Dimension d(idx[i]);
                d.setPosition(position);
                
                // Wipe off parent/child relationships if we're ignoring 
                // same-named dimensions
                d.setParent(boost::uuids::nil_uuid());
                clean_schema.appendDimension(d);
                position++;
            }
        }
        schema_data = pdal::Schema::to_xml(clean_schema);
            
    } else
    {
        schema_data = pdal::Schema::to_xml(buffer_schema);
        
    }

    char* schema = (char*) malloc(schema_data.size() * sizeof(char) + 1);
    strncpy(schema, schema_data.c_str(), schema_data.size());
    schema[schema_data.size()] = '\0';
    statement->WriteCLob(&schema_locator, schema);
    statement->Bind(&schema_locator);

    std::ostringstream wkt_s;

    if (!m_base_table_boundary_column.empty())
    {
        if (!FileUtils::fileExists(m_base_table_boundary_wkt))
        {
            if (!IsValidWKT(m_base_table_boundary_wkt))
            {
                std::ostringstream oss;
                oss << "WKT for base_table_boundary_wkt was not valid and '" << m_base_table_boundary_wkt
                    << "' doesn't exist as a file";
                throw pdal::pdal_error(oss.str());
            }
            wkt_s << m_base_table_boundary_wkt;
        }
        else
        {
            std::string wkt = LoadSQLData(m_base_table_boundary_wkt);
            if (!IsValidWKT(wkt))
            {
                std::ostringstream oss;
                oss << "WKT for base_table_boundary_wkt was from file '" << m_base_table_boundary_wkt
                    << "' is not valid";
                throw pdal::pdal_error(oss.str());
            }
            wkt_s << wkt;
        }
    }

    std::string wkt_string = wkt_s.str();
    char* wkt = (char*) malloc(wkt_string.size() * sizeof(char)+1);
    strncpy(wkt, wkt_string.c_str(), wkt_string.size());
    wkt[wkt_string.size()] = '\0';
    if (!m_base_table_boundary_column.empty())
    {
        statement->WriteCLob(&boundary_locator, wkt);
        statement->Bind(&boundary_locator);
        statement->Bind((int*)&m_srid);

    }

    try
    {
        statement->Execute();
    }
    catch (std::runtime_error const& e)
    {
        std::ostringstream oss;
        oss << "Failed at creating Point Cloud entry into " << m_base_table_name << " table. Does the table exist? "  << e.what();
        throw pdal_error(oss.str());
    }

    free(wkt);

    try
    {
        Option& pc_id = getOptions().getOptionByRef("pc_id");
        pc_id.setValue(m_pc_id);
    }
    catch (pdal::option_not_found&)
    {
        Option pc_id("pc_id", m_pc_id, "Point Cloud Id");
        getOptions().add(pc_id);
    }

}
예제 #4
0
파일: Writer.cpp 프로젝트: xhy20070406/PDAL
void Writer::CreateSDOEntry()
{

    boost::uint32_t precision = getDefaultedOption<boost::uint32_t>("stream_output_precision");


    std::ostringstream oss;

    std::ostringstream oss_geom;

    oss.setf(std::ios_base::fixed, std::ios_base::floatfield);
    oss.precision(precision);

    std::ostringstream s_srid;


    if (m_srid == 0)
    {
        s_srid << "NULL";
    }
    else
    {
        s_srid << m_srid;
    }

    double tolerance = 0.05;


    pdal::Bounds<double> e = m_bounds;

    if (IsGeographic(m_srid))
    {
        // FIXME: This should be overrideable
        e.setMinimum(0,-180.0);
        e.setMaximum(0,180.0);
        e.setMinimum(1,-90.0);
        e.setMaximum(1,90.0);
        e.setMinimum(2,0.0);
        e.setMaximum(2,20000.0);

        tolerance = 0.0005;
    }


    oss <<  "INSERT INTO user_sdo_geom_metadata VALUES ('" << m_block_table_name <<
        "','blk_extent', MDSYS.SDO_DIM_ARRAY(";

    oss << "MDSYS.SDO_DIM_ELEMENT('X', " << e.getMinimum(0) << "," << e.getMaximum(0) <<"," << tolerance << "),"
        "MDSYS.SDO_DIM_ELEMENT('Y', " << e.getMinimum(1) << "," << e.getMaximum(1) <<"," << tolerance << ")";

    if (m_is3d)
    {
        oss << ",";
        oss <<"MDSYS.SDO_DIM_ELEMENT('Z', "<< e.getMinimum(2) << "," << e.getMaximum(2) << "," << tolerance << ")";
    }
    oss << ")," << s_srid.str() << ")";

    run(oss);
    oss.str("");

}