/////////////////////////////////////////////////////////////////////////////// // Eine MapInfodatei öffnen HRESULT CMiTabDatasource::OpenFile(const char *pszNewName, bool fUpdate, bool fTestOpen) { _ASSERTE(NULL != pszNewName); if (NULL == pszNewName) return E_POINTER; mitab_handle hMIF = NULL; #if defined(_READWRITE) if (fUpdate) hMIF = mitab_c_create(pszNewName, NULL, NULL, 0.0, 0.0, 0.0, 0.0); else #endif // defined(_READWRITE) hMIF = mitab_c_open (pszNewName); if (NULL == hMIF) return S_FALSE; // Extract the basename of the file. COM_TRY { // Create the layer object and add layer to data source layer list. os_path path (pszNewName); m_Layers.push_back (new CMiTabLayer(path.base().c_str(), hMIF, fUpdate)); } COM_CATCH; return S_OK; }
static void ReportFile( const char * pszFilename ) { mitab_handle dataset; int feature_id, num_fields; dataset = mitab_c_open( pszFilename ); if( dataset == NULL ) { printf( "mitab_c_open(%s) failed.\n%s\n", pszFilename, mitab_c_getlasterrormsg() ); exit( 1 ); } num_fields = mitab_c_get_field_count(dataset); for( feature_id = mitab_c_next_feature_id(dataset,-1); feature_id != -1; feature_id = mitab_c_next_feature_id(dataset,feature_id) ) { mitab_feature feature; int feature_type, num_parts, partno, pointno, fieldno; /* -------------------------------------------------------------------- */ /* Read next feature object */ /* -------------------------------------------------------------------- */ feature = mitab_c_read_feature( dataset, feature_id ); if( feature == NULL ) { printf( "Failed to read feature %d.\n%s\n", feature_id, mitab_c_getlasterrormsg() ); exit( 1 ); } feature_type = mitab_c_get_type(feature); num_parts = mitab_c_get_parts(feature); printf( "Read feature %d: type=%d, num_parts=%d.\n", feature_id, feature_type, num_parts ); /* -------------------------------------------------------------------- */ /* Dump the feature attributes... */ /* -------------------------------------------------------------------- */ for(fieldno = 0; fieldno < num_fields; fieldno++) { printf(" %s = %s\n", mitab_c_get_field_name(dataset, fieldno), mitab_c_get_field_as_string(feature, fieldno) ); } /* -------------------------------------------------------------------- */ /* ... and coordinates. */ /* In real applications, we would probably want to handle each */ /* object type differently but we won't do it here. */ /* -------------------------------------------------------------------- */ for(partno = 0; partno < num_parts; partno++) { int num_points = mitab_c_get_vertex_count(feature, partno); if (num_parts > 1) printf(" Part no %d:\n", partno); for(pointno = 0; pointno < num_points; pointno++) { double dX, dY; dX = mitab_c_get_vertex_x(feature, partno, pointno); dY = mitab_c_get_vertex_y(feature, partno, pointno); printf(" %.16g %.16g\n", dX, dY); } } mitab_c_destroy_feature( feature ); } mitab_c_close( dataset ); }