⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mitab_capi.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 5 页
字号:
 *        coordinate systems, passing north,south,east,west as 0,0,0,0 will *        instruct MITAB to attempt to use the default bounds for that  *        projection.  If no default bounds are found for this projection then *        your data may not be stored properly in the file unless you provide *        valid bounds via the north,south,east,west parameters. * @param south the lower dataset bound. * @param east the right dataset bound. * @param west the left dataset bound. * @return a valid mitab_handle, or NULL if the file could not be created. */mitab_handle MITAB_STDCALLmitab_c_create( const char * filename,                const char * mif_or_tab,                const char * mif_projection,                double north, double south,                double east, double west ){    IMapInfoFile        *poFile;        CPLSetErrorHandler( CPLQuietErrorHandler );    if( mif_or_tab == NULL || !EQUAL(mif_or_tab,"mif") )    {        poFile = new TABFile;    }    else    {        poFile = new MIFFile;    }    if( poFile->Open( filename, "wb" ) != 0 )    {        delete poFile;        return NULL;    }    if( mif_projection != NULL && strlen(mif_projection) > 0 )    {        poFile->SetMIFCoordSys( mif_projection );    }    if (north != 0 || south != 0 || east != 0 || west != 0)        poFile->SetBounds( west, south, east, north );    return (mitab_handle) poFile;}/************************************************************************//*                         mitab_c_add_field()                          *//*                                                                      *//*      Add a new field to the schema.  Return the field id.            *//************************************************************************//** * Add a new field to the dataset's schema. * * Adding fields MUST be done immediately after creating a new dataset and * BEFORE creating the first feature.   * * @param dataset the mitab_handle of the newly created dataset. * @param field_name the name of the new field to create. * @param field_type the new field type, one of TABFT_Char (1),  *        TABFT_Integer (2), TABFT_SmallInt (3), TABFT_Decimal (4),  *        TABFT_Float (5), TABFT_Date (6), or TABFT_Logical (7) * @param width the width of the new field, applies only to char and decimal *        types. * @param precision the number of digits after the decimal point, applies only *        to the decimal field type. * @param indexed TRUE (1) to create an indexed field (or FALSE (0) for no  *        index) * @param unique for indexed fields, set this to TRUE (1) if the field values *        are guaranteed to be unique, or FALSE (0) otherwise. * @return the 0-based index of the new field, or -1 if the field could not *         be created. */int MITAB_STDCALLmitab_c_add_field( mitab_handle dataset, const char *field_name,                   int field_type, int width, int precision,                    int indexed, int unique ){    IMapInfoFile        *poFile = (IMapInfoFile *) dataset;    if( poFile->AddFieldNative( field_name, (TABFieldType) field_type,                                width, precision, indexed, unique ) != -1 )    {        return poFile->GetLayerDefn()->GetFieldCount() - 1;    }    else        return -1;}/************************************************************************//*                      mitab_c_destroy_feature()                       *//************************************************************************//** * Destroy a mitab_feature object and release all memory associated with it. * * @param feature the mitab_feature to destroy. */void MITAB_STDCALLmitab_c_destroy_feature( mitab_feature feature ){    TABFeature  *poFeature = (TABFeature *) feature;    if (poFeature)        delete poFeature;}/************************************************************************//*                      mitab_c_next_feature_id()                       *//*                                                                      *//*      Iterator to get the next feature id.  Use -1 as previous to     *//*      get first feature id.  Returns -1 when there are no more        *//*      feature ids.                                                    *//************************************************************************//** * Iterator to get the next valid feature id when reading a dataset opened * with mitab_c_open(). *  * @param handle the mitab_handle of the file opened for read access. * @param last_feature_id the id of the last feature that was read. *        Use -1 to get first feature id in the dataset. * @return the next valid feature id in the dataset, or -1 when there are *         no more feature ids. */int MITAB_STDCALLmitab_c_next_feature_id( mitab_handle handle, int last_feature_id ){    IMapInfoFile        *poFile = (IMapInfoFile *) handle;    return poFile->GetNextFeatureId( last_feature_id );}/************************************************************************//*                        mitab_c_read_feature()                        *//************************************************************************//** * Read a mitab_feature object from the file.   * * Works only with datasets opened with mitab_c_open(). * * @param handle the mitab_handle of the file opened for read access. * @param feature_id the id of the feature to read, obtained by calling *        mitab_c_next_feature_id(). * @return the mitab_feature object that was read.  The object will have to *         be destroyed using mitab_c_destroy_feature() once you are done  *         with it. */mitab_feature MITAB_STDCALLmitab_c_read_feature( mitab_handle handle, int feature_id ){    IMapInfoFile        *poFile = (IMapInfoFile *) handle;    TABFeature          *poFeature;    poFeature = poFile->GetFeatureRef( feature_id );    if( poFeature != NULL )        poFeature = poFeature->CloneTABFeature();    return (mitab_feature) poFeature;}/************************************************************************//*                       mitab_c_write_feature()                        *//************************************************************************//** * Write a new feature to a dataset. * * Works only with datasets created using mitab_c_create(). * * The feature to write should have been created using  * mitab_c_create_feature() and its attributes and coordinate information  * set prior to calling this function.   * * Also note that the mitab_feature object will NOT be owned by the dataset * after this call and it is still the responsibility of the caller * to destroy it. * * @param handle the mitab_handle of the dataset opened for write access. * @param feature the mitab_feature to write to the dataset.  * @return TRUE (1) on success, FALSE (0) on error. */int MITAB_STDCALLmitab_c_write_feature( mitab_handle handle, mitab_feature feature ){    IMapInfoFile        *poFile = (IMapInfoFile *) handle;    TABFeature          *poFeature = (TABFeature *) feature;    return poFile->SetFeature( poFeature ) != -1;}/************************************************************************//*                       mitab_c_create_feature()                       *//************************************************************************//** * Create a new mitab_feature object to be written to a dataset created * using mitab_c_create(). * * @param handle the handle of the dataset opened for write access. * @param feature_type the type of feature object to create.  At this point, *        only the following types can be created by this C API function: *        TABFC_NoGeom (0), TABFC_Point (1), TABFC_FontPoint (2),  *        TABFC_CustomPoint (3), TABFC_Text (4), TABFC_Polyline (5),  *        TABFC_Arc (6), TABFC_Region (7), TABFC_Rectangle (8),  *        TABFC_Ellipse (9) and TABFC_MultiPoint (10) * @return the new mitab_feature object, or NULL if creation failed.  Note that *         the new object will have to be released using  *         mitab_c_destroy_feature(). */mitab_feature MITAB_STDCALLmitab_c_create_feature( mitab_handle handle,                        int feature_type ){    IMapInfoFile        *poFile = (IMapInfoFile *) handle;    TABFeature  *poFeature = NULL;    if( poFile->GetLayerDefn() == NULL )    {        poFile->AddFieldNative( "NDX", TABFInteger, 10, 0 );    }    if( feature_type == TABFC_NoGeom )        poFeature = new TABFeature(poFile->GetLayerDefn());    else if( feature_type == TABFC_Point )        poFeature = new TABPoint(poFile->GetLayerDefn());    else if( feature_type == TABFC_FontPoint )        poFeature = new TABFontPoint(poFile->GetLayerDefn());    else if( feature_type == TABFC_CustomPoint )        poFeature = new TABCustomPoint(poFile->GetLayerDefn());    else if( feature_type == TABFC_Text )    {        TABText         *poText = new TABText(poFile->GetLayerDefn());        poText->SetTextString( "Default Text" );        poFeature = poText;    }    else if( feature_type == TABFC_Polyline )        poFeature = new TABPolyline(poFile->GetLayerDefn());    else if( feature_type == TABFC_Arc )        poFeature = new TABArc(poFile->GetLayerDefn());    else if( feature_type == TABFC_Region )        poFeature = new TABRegion(poFile->GetLayerDefn());    else if( feature_type == TABFC_Rectangle )        poFeature = new TABRectangle(poFile->GetLayerDefn());    else if( feature_type == TABFC_Ellipse )        poFeature = new TABEllipse(poFile->GetLayerDefn());    else if( feature_type == TABFC_MultiPoint )        poFeature = new TABMultiPoint(poFile->GetLayerDefn());    return poFeature;}/************************************************************************//*                         mitab_c_set_field()                          *//************************************************************************//** * Set the value of specified field in a feature object. * * @param feature the mitab_feature object. * @param field_index the 0-based index of the field to set. * @param field_value a string containing the value to set the field to. *        For any field type, the value should always be passed using its *        character string representation. */void MITAB_STDCALLmitab_c_set_field( mitab_feature feature, int field_index,                   const char *field_value ){    TABFeature  *poFeature = (TABFeature *) feature;    poFeature->SetField( field_index, field_value );}/************************************************************************//*                         mitab_c_set_points()                         *//************************************************************************//**  * Set the feature's coordinates. * * @param feature the mitab_feature object. * @param part the part number.  Applies only to a region or a polyline, it *        is ignored for other object types.  For regions and polyline, with *        multiple parts, call mitab_c_set_points() once for each part of *        the object (ring or polyline segment), starting with 0 for the *        first part.   *        Note that it is only possible to add parts in a sequential order, *        and it is not possible to overwrite or modify existing parts using *        this function. *        For regions with multiple islands and holes, passing a negative *        part number will result in adding a new island (i.e. polygon).   *        By default, parts > 1 are treated as holes in the last island  *        (polygon) that was created. * @param vertex_count the number of points (pairs of x,y values). * @param x the array of 'vertex_count' X values. *        Note: for rectangle objects, the MBR of the array of points *        defines rectangle corners. * @param y the array of 'vertex_count' Y values. */void MITAB_STDCALLmitab_c_set_points( mitab_feature feature, int part,                    int vertex_count, double * x, double * y ){    TABFeature  *poFeature = (TABFeature *) feature;    if( poFeature->GetFeatureClass() == TABFC_Point        || poFeature->GetFeatureClass() == TABFC_FontPoint        || poFeature->GetFeatureClass() == TABFC_CustomPoint        || poFeature->GetFeatureClass() == TABFC_Text )    {        CPLAssert( vertex_count == 1 );        poFeature->SetGeometryDirectly( new OGRPoint( x[0], y[0] ) );    }    else if( poFeature->GetFeatureClass() == TABFC_Polyline )    {        OGRLineString   *poLine = new OGRLineString();        poLine->setPoints( vertex_count, x, y );        if ( poFeature->GetGeometryRef() != NULL && part > 0 )        {            OGRGeometry *poGeom = poFeature->GetGeometryRef();            if (poGeom->getGeometryType() == wkbLineString && part == 1)            {                OGRMultiLineString *poMulti = new OGRMultiLineString();                /* Note: we use addGeometry() to add poGeom to poMulti since                 * original geometry object will be freed by call to                  * SetGeometryDirectly() below.                 */                poMulti->addGeometry(poGeom);                poMulti->addGeometryDirectly(poLine);                poFeature->SetGeometryDirectly( poMulti );            }            else if (poGeom->getGeometryType() == wkbMultiLineString)            {                CPLAssert( part > 1 );                OGRMultiLineString *poMulti = (OGRMultiLineString *)poGeom;                poMulti->addGeometryDirectly(poLine);            }        }        else        {            CPLAssert( part == 0 );            poFeature->SetGeometryDirectly( poLine );        }    }    else if( poFeature->GetFeatureClass() == TABFC_Region )    {        OGRLinearRing   *poRing = new OGRLinearRing();        OGRPolygon      *poPolygon, *poPoly;        OGRMultiPolygon *poMultiPolygon;        int iLastPolygon, numRingsTotal=0;        poRing->setPoints( vertex_count, x, y );        if( poFeature->GetGeometryRef() != NULL && part > 0 )        {            poMultiPolygon = (OGRMultiPolygon *) poFeature->GetGeometryRef();            iLastPolygon = poMultiPolygon->getNumGeometries() - 1;            poPolygon = (OGRPolygon *)                   poMultiPolygon->getGeometryRef( iLastPolygon );            // Get total number of rings            for(int iPoly=0; iPoly<poMultiPolygon->getNumGeometries(); iPoly++)            {                // We are guaranteed that all parts are OGRPolygons                poPoly = (OGRPolygon*)poMultiPolygon->getGeometryRef(iPoly);                if (poPoly  == NULL)                    continue;                numRingsTotal += poPoly->getNumInteriorRings()+1;            }/*for*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -