📄 mitab_imapinfofile.cpp
字号:
**********************************************************************/
OGRFeature *IMapInfoFile::GetNextFeature()
{
OGRFeature *poFeatureRef;
OGRGeometry *poGeom;
int nFeatureId;
while( (nFeatureId = GetNextFeatureId(m_nCurFeatureId)) != -1 )
{
poFeatureRef = GetFeatureRef(nFeatureId);
if (poFeatureRef == NULL)
return NULL;
else if( (m_poFilterGeom == NULL ||
((poGeom = poFeatureRef->GetGeometryRef()) != NULL &&
FilterGeometry( poGeom )))
&& (m_poAttrQuery == NULL
|| m_poAttrQuery->Evaluate( poFeatureRef )) )
{
// Avoid cloning feature... return the copy owned by the class
CPLAssert(poFeatureRef == m_poCurFeature);
m_poCurFeature = NULL;
return poFeatureRef;
}
}
return NULL;
}
/**********************************************************************
* IMapInfoFile::CreateFeature()
*
* Standard OGR CreateFeature implementation. This methode is used
* to create a new feature in current dataset
**********************************************************************/
OGRErr IMapInfoFile::CreateFeature(OGRFeature *poFeature)
{
TABFeature *poTABFeature;
OGRGeometry *poGeom;
OGRwkbGeometryType eGType;
OGRErr eErr;
TABPoint *poTABPointFeature = NULL;
TABRegion *poTABRegionFeature = NULL;
TABPolyline *poTABPolylineFeature = NULL;
/*-----------------------------------------------------------------
* MITAB won't accept new features unless they are in a type derived
* from TABFeature... so we have to do our best to map to the right
* feature type based on the geometry type.
*----------------------------------------------------------------*/
poGeom = poFeature->GetGeometryRef();
if( poGeom != NULL )
eGType = poGeom->getGeometryType();
else
eGType = wkbNone;
switch( wkbFlatten(eGType) )
{
/*-------------------------------------------------------------
* POINT
*------------------------------------------------------------*/
case wkbPoint:
poTABFeature = new TABPoint(poFeature->GetDefnRef());
if(poFeature->GetStyleString())
{
poTABPointFeature = (TABPoint*)poTABFeature;
poTABPointFeature->SetSymbolFromStyleString(
poFeature->GetStyleString());
}
break;
/*-------------------------------------------------------------
* REGION
*------------------------------------------------------------*/
case wkbPolygon:
case wkbMultiPolygon:
poTABFeature = new TABRegion(poFeature->GetDefnRef());
if(poFeature->GetStyleString())
{
poTABRegionFeature = (TABRegion*)poTABFeature;
poTABRegionFeature->SetPenFromStyleString(
poFeature->GetStyleString());
poTABRegionFeature->SetBrushFromStyleString(
poFeature->GetStyleString());
}
break;
/*-------------------------------------------------------------
* LINE/PLINE/MULTIPLINE
*------------------------------------------------------------*/
case wkbLineString:
case wkbMultiLineString:
poTABFeature = new TABPolyline(poFeature->GetDefnRef());
if(poFeature->GetStyleString())
{
poTABPolylineFeature = (TABPolyline*)poTABFeature;
poTABPolylineFeature->SetPenFromStyleString(
poFeature->GetStyleString());
}
break;
/*-------------------------------------------------------------
* Collection types that are not directly supported... convert
* to multiple features in output file through recursive calls.
*------------------------------------------------------------*/
case wkbGeometryCollection:
case wkbMultiPoint:
{
OGRErr eStatus = OGRERR_NONE;
int i;
OGRGeometryCollection *poColl = (OGRGeometryCollection*)poGeom;
OGRFeature *poTmpFeature = poFeature->Clone();
for (i=0; eStatus==OGRERR_NONE && i<poColl->getNumGeometries(); i++)
{
poTmpFeature->SetGeometry(poColl->getGeometryRef(i));
eStatus = CreateFeature(poTmpFeature);
}
delete poTmpFeature;
return eStatus;
}
break;
/*-------------------------------------------------------------
* Unsupported type.... convert to MapInfo geometry NONE
*------------------------------------------------------------*/
case wkbUnknown:
default:
poTABFeature = new TABFeature(poFeature->GetDefnRef());
break;
}
if( poGeom != NULL )
poTABFeature->SetGeometryDirectly(poGeom->clone());
for (int i=0; i< poFeature->GetDefnRef()->GetFieldCount();i++)
{
poTABFeature->SetField(i,poFeature->GetRawFieldRef( i ));
}
if (SetFeature(poTABFeature) > -1)
eErr = OGRERR_NONE;
else
eErr = OGRERR_FAILURE;
delete poTABFeature;
return eErr;
}
/**********************************************************************
* IMapInfoFile::GetFeature()
*
* Standard OGR GetFeature implementation. This methode is used
* to get the wanted (nFeatureId) feature, a NULL value will be
* returned on error.
**********************************************************************/
OGRFeature *IMapInfoFile::GetFeature(long nFeatureId)
{
OGRFeature *poFeatureRef;
poFeatureRef = GetFeatureRef(nFeatureId);
if (poFeatureRef)
{
// Avoid cloning feature... return the copy owned by the class
CPLAssert(poFeatureRef == m_poCurFeature);
m_poCurFeature = NULL;
return poFeatureRef;
}
else
return NULL;
}
/************************************************************************/
/* CreateField() */
/* */
/* Create a native field based on a generic OGR definition. */
/************************************************************************/
OGRErr IMapInfoFile::CreateField( OGRFieldDefn *poField, int bApproxOK )
{
TABFieldType eTABType;
int nWidth = poField->GetWidth();
if( poField->GetType() == OFTInteger )
{
eTABType = TABFInteger;
if( nWidth == 0 )
nWidth = 12;
}
else if( poField->GetType() == OFTReal )
{
eTABType = TABFFloat;
if( nWidth == 0 )
nWidth = 32;
}
else if( poField->GetType() == OFTString )
{
eTABType = TABFChar;
if( nWidth == 0 )
nWidth = 254;
else
nWidth = MIN(254,nWidth);
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"IMapInfoFile::CreateField() called with unsupported field"
" type %d.\n"
"Note that Mapinfo files don't support list field types.\n",
poField->GetType() );
return OGRERR_FAILURE;
}
if( AddFieldNative( poField->GetNameRef(), eTABType,
nWidth, poField->GetPrecision() ) > -1 )
return OGRERR_NONE;
else
return OGRERR_FAILURE;
}
/**********************************************************************
* IMapInfoFile::SetCharset()
*
* Set the charset for the tab header.
*
*
* Returns 0 on success, -1 on error.
**********************************************************************/
int IMapInfoFile::SetCharset(const char* pszCharset)
{
if(pszCharset && strlen(pszCharset) > 0)
{
CPLFree(m_pszCharset);
m_pszCharset = CPLStrdup(pszCharset);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -