Пример #1
0
void CShapefileFeatureClass::InitFields()
{
	m_allFields.clear();
	int iField;
	int lFieldnum =DBFGetFieldCount(m_dbfHandle);
	char            szFieldName[20];
	int             nWidth, nPrecision;
	char            chNativeType;
	DBFFieldType    eDBFType;
	//获得属性字段的信息
	for( iField = 0; 
		m_dbfHandle != NULL && iField < lFieldnum; 
		iField++ )
	{
		CField *pField =new CField();



		chNativeType = DBFGetNativeFieldType( m_dbfHandle, iField );
		eDBFType = DBFGetFieldInfo( m_dbfHandle, iField, szFieldName,
			&nWidth, &nPrecision );

		pField->SetName(szFieldName);

		pField->SetLength(nWidth);

		pField->SetPrecision(nPrecision);

		if( chNativeType == 'D' )
		{
			/* XXX - mloskot:
			* Shapefile date has following 8-chars long format: 20060101.
			* OGR splits it as YYYY/MM/DD, so 2 additional characters are required.
			* Is this correct assumtion? What about time part of date?
			* Shouldn't this format look as datetime: YYYY/MM/DD HH:MM:SS
			* with 4 additional characters?
			*/
			pField->SetLength( nWidth + 2 );
			pField->SetType( FTYPE_DATE );
		}
		else if( eDBFType == FTDouble )
			pField->SetType( FTYPE_DOUBLE);
		else if( eDBFType == FTInteger )
			pField->SetType(FTYPE_LONG);
		else if(eDBFType==FTLogical)
			pField->SetType(FTYPE_BOOL);
		else
			pField->SetType( FTYPE_STRING);

		m_allFields.push_back(CFieldPtr(pField));
	}
}
Пример #2
0
void CShapefileFeatureClass::Init()
{

	//获得矢量的图形类型
	switch( m_shpHandle->nShapeType )
	{
	case SHPT_POINT:
	case SHPT_POINTM:
	case SHPT_POINTZ:
		m_lshptype =GEOMETRY::geom::GEOS_POINT;
		break;

	case SHPT_ARC:
	case SHPT_ARCM:
	case SHPT_ARCZ:
		m_lshptype =GEOMETRY::geom::GEOS_MULTILINESTRING;
		break;

	case SHPT_MULTIPOINT:
	case SHPT_MULTIPOINTM:
	case SHPT_MULTIPOINTZ:
		m_lshptype =GEOMETRY::geom::GEOS_MULTIPOINT;
		break;

	case SHPT_POLYGON:
	case SHPT_POLYGONM:
	case SHPT_POLYGONZ:
		m_lshptype =GEOMETRY::geom::GEOS_POLYGON;
		break;
	default:
		m_lshptype =GEOMETRY::geom::GEOM_NULL;
		break;

	}
	int iField;
	int lFieldnum =DBFGetFieldCount(m_dbfHandle);
	char            szFieldName[20];
	int             nWidth, nPrecision;
	char            chNativeType;
	DBFFieldType    eDBFType;
    //获得属性字段的信息
	for( iField = 0; 
		m_dbfHandle != NULL && iField < lFieldnum; 
		iField++ )
	{
		CField *pField =new CField();



		chNativeType = DBFGetNativeFieldType( m_dbfHandle, iField );
		eDBFType = DBFGetFieldInfo( m_dbfHandle, iField, szFieldName,
			&nWidth, &nPrecision );

		pField->SetName(szFieldName);

		pField->SetLength(nWidth);

        pField->SetPrecision(nPrecision);

		if( chNativeType == 'D' )
		{
			/* XXX - mloskot:
			* Shapefile date has following 8-chars long format: 20060101.
			* OGR splits it as YYYY/MM/DD, so 2 additional characters are required.
			* Is this correct assumtion? What about time part of date?
			* Shouldn't this format look as datetime: YYYY/MM/DD HH:MM:SS
			* with 4 additional characters?
			*/
			pField->SetLength( nWidth + 2 );
			pField->SetType( FTYPE_DATE );
		}
		else if( eDBFType == FTDouble )
			pField->SetType( FTYPE_DOUBLE);
		else if( eDBFType == FTInteger )
			pField->SetType(FTYPE_LONG);
		else
			pField->SetType( FTYPE_STRING);

		m_allFields.push_back(CFieldPtr(pField));
	}

	//获得投影信息
    ReadPrj();

    //如果记录大于10000条,则建立空间索引
	if(m_shpHandle->nRecords>=SPATIALINDEX_MIN_SHAPE)
	{
		BuildSpatialIndex();
	}


}