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

📄 mitab_capi.cpp

📁 mitab,读取MapInfo的地图文件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
 *        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_STDCALL
mitab_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*/

            CPLAssert( part == numRingsTotal );
            poPolygon->addRingDirectly( poRing );
        }
        else
        {
            CPLAssert( part <= 0 );
            
            if( poFeature->GetGeometryRef() != NULL )
                poMultiPolygon = (OGRMultiPolygon *) poFeature->GetGeometryRef();
            else
                poMultiPolygon = new OGRMultiPolygon;

            poPolygon = new OGRPolygon;
            poPolygon->addRingDirectly( poRing );
            poMultiPolygon->addGeometryDirectly( poPolygon );
            if( poFeature->GetGeometryRef() == NULL )
                poFeature->SetGeometryDirectly( poMultiPolygon );
        }
    }

    else if( poFeature->GetFeatureClass() == TABFC_Rectangle )
    {
        if ( poFeature->GetGeometryRef() == NULL && part == 0 )
        {
            // Rectangle: The MBR of the first part defines the rectangle 
            // corners
            OGRPolygon      *poPoly = new OGRPolygon;
            OGRLinearRing   *poRing = new OGRLinearRing;

            poRing->setPoints( vertex_count, x, y );

            poPoly->addRingDirectly( poRing );
            poFeature->SetGeometryDirectly( poPoly );
        }
    }

    else if( poFeature->GetFeatureClass() == TABFC_MultiPoint )
    {
        OGRPoint        *poPoint;
        OGRMultiPoint   *poMultiPoint;
        int i;

        if( poFeature->GetGeometryRef() != NULL )
            poMultiPoint = (OGRMultiPoint *) poFeature->GetGeometryRef();
        else
            poMultiPoint = new OGRMultiPoint;

        for(i=0; i<vertex_count; i++)
        {
            poPoint =  new OGRPoint( x[i], y[i] );
            poMultiPoint->addGeometryDirectly( poPoint );
        }
        poFeature->SetGeometryDirectly( poMultiPoint );
    }

}

/************************************************************************/
/*                         mitab_c_set_arc()                            */
/************************************************************************/

/** 
 * Set an arc or ellipse feature parameters.
 *
 * @param feature the mitab_feature object.
 * @param center_x the arc/ellipse center X coordinate.
 * @param center_y the arc/ellipse center Y coordinate.
 * @param x_radius the arc/ellipse X radius.
 * @param y_radius the arc/ellipse Y radius.
 * @param start_angle for an arc: the start angle in degrees, counterclockwise.
 *                    for an ellipse, this parameter is ignored.
 * @param end_angle for an arc: the end angle in degrees, counterclockwise.
 *                  for an ellipse, this parameter is ignored.
 */

void MITAB_STDCALL
mitab_c_set_arc( mitab_feature feature, 
                 double center_x, double center_y,
                 double x_radius, double y_radius,
                 double start_angle, double end_angle)

{
    TABFeature  *poFeature = (TABFeature *) feature;

    if( poFeature->GetFeatureClass() == TABFC_Arc )
    {
        TABArc *poArc = (TABArc *)poFeature;

        poArc->m_dCenterX = center_x;
        poArc->m_dCenterY = center_y;
        poArc->m_dXRadius = x_radius;
        poArc->m_dYRadius = y_radius;
        poArc->SetStartAngle(start_angle);
        poArc->SetEndAngle(end_angle);

        // We also need a point geometry to make things legal.
        OGRPoint      oPoint( center_x, center_y );
        poArc->SetGeometry( &oPoint );
    }
    else if (poFeature->GetFeatureClass() == TABFC_Ellipse)
    {
        TABEllipse *poEllipse = (TABEllipse *)poFeature;

        poEllipse->m_dCenterX = center_x;
        poEllipse->m_dCenterY = center_y;
        poEllipse->m_dXRadius = x_radius;
        poEllipse->m_dYRadius = y_radius;

        // TABEllipse expects a polygon geometry... just use the MBR
        OGRPolygon      *poPoly = new OGRPolygon;
        OGRLinearRing   *poRing = new OGRLinearRing;

        poRing->setNumPoints(5);
        poRing->setPoint(0, center_x-x_radius, center_y-y_radius );
        poRing->setPoint(1, center_x-x_radius, center_y+y_radius );
        poRing->setPoint(2, center_x+x_radius, center_y+y_radius );
        poRing->setPoint(3, center_x+x_radius, center_y-y_radius );
        poRing->setPoint(4, center_x-x_radius, center_y-y_radius );

        poPoly->addRingDirectly( poRing );
        poEllipse->SetGeometryDirectly( poPoly );
    }

}

/************************************************************************/
/*                          mitab_c_set_text()                          */
/************************************************************************/

/**
 * Set the text string on a TABFC_Text object.
 *
 * @param feature the mitab_feature object.
 * @param text the text string to set in the object.
 */

void MITAB_STDCALL
mitab_c_set_text( mitab_feature feature, const char * text )

{
    TABText     *poFeature = (TABText *) feature;

    if( poFeature->GetFeatureClass() == TABFC_Text )
        poFeature->SetTextString( text );
}

/************************************************************************/
/*                          mitab_c_get_text()                          */
/************************************************************************/

/**
 * Get the text string on a TABFC_Text object.
 *
 * @param feature the mitab_feature object.
 * @return the text string in the object.
 */

const char * MITAB_STDCALL
mitab_c_get_text( mitab_feature feature )

{
    TABText     *poFeature = (TABText *) feature;

    if( poFeature->GetFeatureClass() == TABFC_Text )
        return poFeature->GetTextString( );

    return "";
}

/************************************************************************/
/*                          mitab_c_get_text_vb()                       */
/************************************************************************/

/**
 * Get the text string on a TABFC_Text object (VB Version).
 *
 * @param feature the mitab_feature object.
 * @param text string buffer to return the text string in the object.
 * @param l the maximum length of the text string including terminating null.
 * @return the length of the text string in the object.
 */

int MITAB_STDCALL 
mitab_c_get_text_vb( mitab_feature feature, char * text, int l )

{
    TABText     *poFeature = (TABText *) feature;

    if( poFeature->GetFeatureClass() == TABFC_Text )
    {  
      strncpy (text,poFeature->GetTextString( ),l); 
      return strlen(text);
    }

    return 0;
}


/************************************************************************/
/*                          mitab_c_set_text_display()                  */
/************************************************************************/

/**
 * Set a TABFC_Text object's display properties.
 *
 * See the MIF specs for more details on the meaning and valid values of
 * each parameter.
 *
 * @param feature the mitab_feature object.
 * @param angle the text angle in degrees.
 * @param height the height of the text's MBR in ground units.
 * @param width the width of the text's MBR in ground units.
 * @param fg_color foreground color (24 bits RGB value).
 * @param bg_color background color.
 * @param justification one of TABTJ_Left (0), TABTJ_Center (1), or 
 *        TABTJ_Right (2).
 * @param spacing one of TABTS_1 (0), TABTS_1_5 (1), or TABTS_2 (2)
 * @param linetype one of TABTL_NoLine (0), TABTL_Simple (1), or 
 *        TABTL_Arrow (2).
 */

void MITAB_STDCALL
mitab_c_set_text_display( mitab_feature feature,
                          double angle, double height, double width,
                          int fg_color, int bg_color,
                          int justification, int spacing, int linetype )
    
{
    TABText     *poFeature = (TABText *) feature;

    if( poFeature->GetFeatureClass() == TABFC_Text )
    {
        poFeature->SetTextAngle( angle );
        if( height > 0 )
            poFeature->SetTextBoxHeight( height );
        if( width > 0 )
            poFeature->SetTextBoxWidth( width );
        if( fg_color != -1 )
            poFeature->SetFontFGColor( fg_color );
        if( bg_color != -1 )
            poFeature->SetFontBGColor( bg_color );

        if( justification != -1 )
            poFeature->SetTextJustification( (TABTextJust) justification );
        if( spacing != -1 )
            poFeature->SetTextSpacing( (TABTextSpacing) justification );
        if( linetype != -1 )
            poFeature->SetTextLineType( (TABTextLineType) linetype );
    }
}

/************************************************************************/
/*                       mitab_c_get_text_angle()                       */
/************************************************************************/

/**
 * Fetch a TABFC_Text object's angle property.
 *
 * @param feature the mitab_feature object.
 * @return the text angle in degrees.
 */

double MITAB_STDCALL
mitab_c_get_text_angle( mitab_feature feature )
    
{
    TABText     *poFeature = (TABText *) feature;

    if( poFeature->GetFeatureClass() == TABFC_Text )
    {
        return poFeature->GetTextAngle();
    }
    return 0.0;
}

/************************************************************************/
/*                       mitab_c_get_text_height()                       */
/************************************************************************/

/**
 * Fetch a TABFC_Text object's MBR height property.
 *
 * @param feature the mitab_feature object.
 * @return  the height of the text's MBR in ground units.
 */

double MITAB_STDCALL

⌨️ 快捷键说明

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