Пример #1
0
int OGRAVCBinLayer::CheckSetupTable()

{
    if( szTableName[0] == '\0' )
        return FALSE;

/* -------------------------------------------------------------------- */
/*      Scan for the indicated section.                                 */
/* -------------------------------------------------------------------- */
    AVCE00ReadPtr psInfo = ((OGRAVCBinDataSource *) poDS)->GetInfo();
    int           iSection;
    AVCE00Section *psSection = NULL;
    char	  szPaddedName[65];
    
    sprintf( szPaddedName, "%s%32s", szTableName, " " );
    szPaddedName[32] = '\0';

    for( iSection = 0; iSection < psInfo->numSections; iSection++ )
    {
        if( EQUAL(szPaddedName,psInfo->pasSections[iSection].pszName) 
            && psInfo->pasSections[iSection].eType == AVCFileTABLE )
            psSection = psInfo->pasSections + iSection;
    }

    if( psSection == NULL )
    {
        szTableName[0] = '\0';
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Try opening the table.                                          */
/* -------------------------------------------------------------------- */
    hTable = AVCBinReadOpen( psInfo->pszInfoPath,  szTableName,
                             psInfo->eCoverType, AVCFileTABLE,
                             psInfo->psDBCSInfo);
    
    if( hTable == NULL )
    {
        szTableName[0] = '\0';
        return FALSE;
    }
    
/* -------------------------------------------------------------------- */
/*      Setup attributes.                                               */
/* -------------------------------------------------------------------- */
    nTableBaseField = poFeatureDefn->GetFieldCount();
    
    AppendTableDefinition( hTable->hdr.psTableDef );

/* -------------------------------------------------------------------- */
/*      Close table so we don't have to many files open at once.        */
/* -------------------------------------------------------------------- */
    AVCBinReadClose( hTable );

    hTable = NULL;

    return TRUE;
}
Пример #2
0
SEXP get_tol_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,n;
	void **pdata;
	char pathtofile[PATH];
	AVCTol *reg;
	AVCBinFile *file;
	SEXP *table, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));
	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)), 1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileTOL)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextTol(file)){n++;}

	Rprintf("Number of TOLERANCES:%d\n", n);
	
	table=calloc(3, sizeof(SEXP));
	pdata=calloc(3, sizeof(void *));

	PROTECT(table[0]=NEW_INTEGER(n));
	pdata[0]=INTEGER(table[0]);
	PROTECT(table[1]=NEW_INTEGER(n));
	pdata[1]=INTEGER(table[1]);
	PROTECT(table[2]=NEW_NUMERIC(n));
	pdata[2]=REAL(table[2]);

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		if(!(reg=(AVCTol*)AVCBinReadNextTol(file)))
			error("Error while reading register");

		((int *)pdata[0])[i]=reg->nIndex;

		((int *)pdata[1])[i]=reg->nFlag;

		((double *)pdata[2])[i]=reg->dValue;
	}

	PROTECT(aux=NEW_LIST(3));
	for(i=0;i<3;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	UNPROTECT(4);

	free(table);
	free(pdata);

	return aux;
}
Пример #3
0
int OGRAVCBinLayer::AppendTableFields( OGRFeature *poFeature )

{
    AVCE00ReadPtr psInfo = ((OGRAVCBinDataSource *) poDS)->GetInfo();

    if( szTableName[0] == '\0' )
        return FALSE;

/* -------------------------------------------------------------------- */
/*      Open the table if it is currently closed.                       */
/* -------------------------------------------------------------------- */
    if( hTable == NULL )
    {
        hTable = AVCBinReadOpen( psInfo->pszInfoPath,  szTableName,
                                 psInfo->eCoverType, AVCFileTABLE,
                                 psInfo->psDBCSInfo);
    }

    if( hTable == NULL )
        return FALSE;

/* -------------------------------------------------------------------- */
/*      Read the info record.                                           */
/*                                                                      */
/*      We usually assume the FID of the feature is the key but in a    */
/*      polygon coverage we need to use the PolyId attribute of LAB     */
/*      features to lookup the related attributes.  In this case        */
/*      nTableAttrIndex will already be setup to refer to the           */
/*      PolyId field.                                                   */
/* -------------------------------------------------------------------- */
    int	nRecordId;
    void *hRecord;

    if( nTableAttrIndex == -1 )
        nRecordId = (int) poFeature->GetFID();
    else
        nRecordId = poFeature->GetFieldAsInteger( nTableAttrIndex );

    hRecord = AVCBinReadObject( hTable, nRecordId );
    if( hRecord == NULL )
        return FALSE;

/* -------------------------------------------------------------------- */
/*      Translate it.                                                   */
/* -------------------------------------------------------------------- */
    return TranslateTableFields( poFeature, nTableBaseField, 
                                 hTable->hdr.psTableDef, 
                                 (AVCField *) hRecord );
}
Пример #4
0
OGRFeature *OGRAVCBinLayer::GetFeature( GIntBig nFID )

{
    if( !CPL_INT64_FITS_ON_INT32(nFID) )
        return NULL;

/* -------------------------------------------------------------------- */
/*      If we haven't started yet, open the file now.                   */
/* -------------------------------------------------------------------- */
    if( hFile == NULL )
    {
        AVCE00ReadPtr psInfo = ((OGRAVCBinDataSource *) poDS)->GetInfo();

        hFile = AVCBinReadOpen(psInfo->pszCoverPath, 
                               psSection->pszFilename, 
                               psInfo->eCoverType, 
                               psSection->eType,
                               psInfo->psDBCSInfo);
    }

/* -------------------------------------------------------------------- */
/*      Read the raw feature - the -3 fid is a special flag             */
/*      indicating serial access.                                       */
/* -------------------------------------------------------------------- */
    void *pFeature;

    if( nFID == -3 )
    {
        while( (pFeature = AVCBinReadNextObject( hFile )) != NULL
               && !MatchesSpatialFilter( pFeature ) )
        {
            nNextFID++;
        }
    }
    else
    {
        bNeedReset = TRUE;
        pFeature = AVCBinReadObject( hFile, (int)nFID );
    }
        
    if( pFeature == NULL )
        return NULL;

/* -------------------------------------------------------------------- */
/*      Translate the feature.                                          */
/* -------------------------------------------------------------------- */
    OGRFeature *poFeature;

    poFeature = TranslateFeature( pFeature );
    if( poFeature == NULL )
        return NULL;

/* -------------------------------------------------------------------- */
/*      LAB's we have to assign the FID to directly, since it           */
/*      doesn't seem to be stored in the file structure.                */
/* -------------------------------------------------------------------- */
    if( psSection->eType == AVCFileLAB )
    {
        if( nFID == -3 )
            poFeature->SetFID( nNextFID++ );
        else
            poFeature->SetFID( nFID );
    }

/* -------------------------------------------------------------------- */
/*      If this is a polygon layer, try to assemble the arcs to form    */
/*      the whole polygon geometry.                                     */
/* -------------------------------------------------------------------- */
    if( psSection->eType == AVCFilePAL 
        || psSection->eType == AVCFileRPL )
        FormPolygonGeometry( poFeature, (AVCPal *) pFeature );

/* -------------------------------------------------------------------- */
/*      If we have an attribute table, append the attributes now.       */
/* -------------------------------------------------------------------- */
    AppendTableFields( poFeature );

    return poFeature;
}
Пример #5
0
int OGRAVCBinDataSource::Open( const char * pszNewName, int bTestOpen )

{
/* -------------------------------------------------------------------- */
/*      Open the source file.  Supress error reporting if we are in     */
/*      TestOpen mode.                                                  */
/* -------------------------------------------------------------------- */
    if( bTestOpen )
        CPLPushErrorHandler( CPLQuietErrorHandler );

    psAVC = AVCE00ReadOpen( pszNewName );

    if( bTestOpen )
    {
        CPLPopErrorHandler();
        CPLErrorReset();
    }

    if( psAVC == NULL )
        return FALSE;

    pszName = CPLStrdup( pszNewName );
    pszCoverageName = CPLStrdup( psAVC->pszCoverName );

/* -------------------------------------------------------------------- */
/*      Create layers for the "interesting" sections of the coverage.   */
/* -------------------------------------------------------------------- */
    int		iSection;

    papoLayers = (OGRLayer **)
        CPLCalloc( sizeof(OGRLayer *), psAVC->numSections );
    nLayers = 0;

    for( iSection = 0; iSection < psAVC->numSections; iSection++ )
    {
        AVCE00Section *psSec = psAVC->pasSections + iSection;

        switch( psSec->eType )
        {
          case AVCFileARC:
          case AVCFilePAL:
          case AVCFileCNT:
          case AVCFileLAB:
          case AVCFileRPL:
          case AVCFileTXT:
          case AVCFileTX6:
            papoLayers[nLayers++] = new OGRAVCBinLayer( this, psSec );
            break;

          case AVCFilePRJ:
          {
              char 	**papszPRJ;
              AVCBinFile *hFile;
              
              hFile = AVCBinReadOpen(psAVC->pszCoverPath, 
                                     psSec->pszFilename, 
                                     psAVC->eCoverType, 
                                     psSec->eType,
                                     psAVC->psDBCSInfo);
              if( hFile && poSRS == NULL )
              {
                  papszPRJ = AVCBinReadNextPrj( hFile );

                  poSRS = new OGRSpatialReference();
                  if( poSRS->importFromESRI( papszPRJ ) != OGRERR_NONE )
                  {
                      CPLError( CE_Warning, CPLE_AppDefined, 
                                "Failed to parse PRJ section, ignoring." );
                      delete poSRS;
                      poSRS = NULL;
                  }
                  AVCBinReadClose( hFile );
              }
          }
          break;

          default:
            ;
        }
    }
    
    return nLayers > 0;
}
Пример #6
0
SEXP get_table_data(SEXP infodir, SEXP tablename) 
{
	int i,j,n;
	char pathtoinfodir[PATH];
	void **pdata;
	AVCTableDef *tabledef;
	AVCField *reg;
	AVCBinFile *file;
	SEXP *table,aux;

	strcpy(pathtoinfodir, CHAR(STRING_ELT(infodir,0)));
	complete_path(pathtoinfodir, "", 1);

	if(!(file=AVCBinReadOpen(pathtoinfodir,CHAR(STRING_ELT(tablename,0)),AVCFileTABLE)))
	{
		error("Couldn't open table file\n");
	}

	n=0;

	while(AVCBinReadNextTableRec(file)){n++;}

	AVCBinReadRewind(file);


	tabledef=(file->hdr).psTableDef;

	table=calloc(tabledef->numFields, sizeof(SEXP));
	pdata=calloc(tabledef->numFields, sizeof(void *));


	for(i=0;i<tabledef->numFields;i++)
        {
/*printf("%d %d %d\n",i,j,tabledef->pasFieldDef[j].nType1);*/
		switch(tabledef->pasFieldDef[i].nType1)
		{
			case 1:
			case 2: PROTECT(table[i]=NEW_STRING(n));break;

			case 3: PROTECT(table[i]=NEW_INTEGER(n));
				pdata[i]=(int *)INTEGER(table[i]);break;

			case 4: PROTECT(table[i]=NEW_NUMERIC(n));
				pdata[i]=(double *)REAL(table[i]);break;
                                
			case 5: PROTECT(table[i]=NEW_INTEGER(n));
				pdata[i]=(int *)INTEGER(table[i]);break;

			case 6: PROTECT(table[i]=NEW_NUMERIC(n));
				pdata[i]=(double *)REAL(table[i]);break;
		}
	}		


	for(i=0;i<n;i++)
	{
		reg=AVCBinReadNextTableRec(file);

		for(j=0;j<tabledef->numFields;j++)
		{
/*			printf("%d %d %d\n",i,j,tabledef->pasFieldDef[j].nType1);*/
			switch(tabledef->pasFieldDef[j].nType1)
			{
				case 1: 
				case 2:
	SET_STRING_ELT(table[j],i, COPY_TO_USER_STRING(reg[j].pszStr)); 
				break;

				case 3:
				((int *)pdata[j])[i]=atoi(reg[j].pszStr);
				break;

				case 4:
				((double *)pdata[j])[i]=atof(reg[j].pszStr);
				break;

				case 5:
				if(reg[j].nInt16!=0)/*Single precision*/
					((int *)pdata[j])[i]=reg[j].nInt16;
				else/*Default and double precision*/
					((int *)pdata[j])[i]=reg[j].nInt32;
				break;
				
				case 6:
				if(reg[j].fFloat!=0)/*Single precision*/
					((double *)pdata[j])[i]=reg[j].fFloat;
				else/*Default and double precision*/
					((double *)pdata[j])[i]=reg[j].dDouble;
				break;
			}
		}
	}

	PROTECT(aux=NEW_LIST(tabledef->numFields));

	for(i=0;i<tabledef->numFields;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	UNPROTECT(1+tabledef->numFields);

	free(table);
	free(pdata);

	return aux;
}
Пример #7
0
SEXP get_txt_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n;
	int **idata;
	double *x, *y;
	char pathtofile[PATH];
	AVCTxt *reg;
	AVCBinFile *file;
	SEXP *table, points,aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));
	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)), 1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileTXT)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextTxt(file)){n++;}

	Rprintf("Number of TxT ANNOTATIONS:%d\n",n);


	table=calloc(6, sizeof(SEXP));
	idata=calloc(5, sizeof(int *));


	PROTECT(table[0]=NEW_INTEGER(n));/*nTxtId*/
	idata[0]=INTEGER(table[0]);
	PROTECT(table[1]=NEW_INTEGER(n));/*nUserId*/
	idata[1]=INTEGER(table[1]);
	PROTECT(table[2]=NEW_INTEGER(n));/*nLevel*/
	idata[2]=INTEGER(table[2]);
	PROTECT(table[3]=NEW_INTEGER(n));/*numVerticesLine*/
	idata[3]=INTEGER(table[3]);
	PROTECT(table[4]=NEW_INTEGER(n));/*numVerticesArrow*/
	idata[4]=INTEGER(table[4]);

	PROTECT(table[5]=NEW_STRING(n));/*Character strings*/


	PROTECT(points=NEW_LIST(n));

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		if(!(reg=(AVCTxt*)AVCBinReadNextTxt(file)))
			error("Error while reading register");

		((int *)idata[0])[i]=reg->nTxtId;
		((int *)idata[1])[i]=reg->nUserId;
		((int *)idata[2])[i]=reg->nLevel;
		((int *)idata[3])[i]=reg->numVerticesLine;
		((int *)idata[4])[i]=reg->numVerticesArrow;

		SET_STRING_ELT(table[5],i, COPY_TO_USER_STRING(reg->pszText));

		SET_VECTOR_ELT(points, i, NEW_LIST(2));
		aux=VECTOR_ELT(points, i);

/*This can be improved storing only the right numnber of vertices*/
		SET_VECTOR_ELT(aux, 0, NEW_NUMERIC(4));
		x=REAL(VECTOR_ELT(aux,0));
		SET_VECTOR_ELT(aux, 1, NEW_NUMERIC(4));
		y=REAL(VECTOR_ELT(aux,1));

		for(j=0;j<4;j++)
		{
			x[j]=reg->pasVertices[j].x;
			y[j]=reg->pasVertices[j].y;
		}

	}

	PROTECT(aux=NEW_LIST(7));

	for(i=0;i<6;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	SET_VECTOR_ELT(aux, i, points);

	UNPROTECT(8);

	free(table);
	free(idata);

	return aux;
}
Пример #8
0
SEXP get_cnt_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n, *ilabel;
	void **pdata;
	char pathtofile[PATH];
	AVCCnt *reg;
	AVCBinFile *file;
	SEXP *table, label, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));
	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)),1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileCNT)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextCnt(file)){n++;}

	Rprintf("Number of CENTROIDS:%d\n",n);

	table=calloc(4, sizeof(SEXP));
	pdata=calloc(4,sizeof(void *));

	PROTECT(table[0]=NEW_INTEGER(n));
	pdata[0]=INTEGER(table[0]);

	PROTECT(table[1]=NEW_NUMERIC(n));
	pdata[1]=REAL(table[1]);

	PROTECT(table[2]=NEW_NUMERIC(n));
	pdata[2]=REAL(table[2]);

	PROTECT(table[3]=NEW_INTEGER(n));
	pdata[3]=INTEGER(table[3]);

	PROTECT(label=NEW_LIST(n));

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		
		if(!(reg=(AVCCnt*)AVCBinReadNextCnt(file)))
			error("Error while reading register");

		((int *)pdata[0])[i]=reg->nPolyId;

		((double *)pdata[1])[i]=reg->sCoord.x;
		((double *)pdata[2])[i]=reg->sCoord.y;

		((int *)pdata[3])[i]=reg->numLabels;

		SET_VECTOR_ELT(label,i,NEW_INTEGER(reg->numLabels));
		ilabel=INTEGER(VECTOR_ELT(label,i));
		if(reg->numLabels >0)
		{
			for(j=0;j<reg->numLabels;j++)
			{
/*				printf("%d\n", reg->panLabelIds[j]);*/
				ilabel[j]=reg->panLabelIds[j];
			}
		}

	}


	PROTECT(aux=NEW_LIST(5));

	for(i=0;i<4;i++)
		SET_VECTOR_ELT(aux, i, table[i]);

	SET_VECTOR_ELT(aux, 4, label);

	UNPROTECT(6);

	free(table);
	free(pdata);

	return aux;
}
Пример #9
0
SEXP get_lab_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,n;
	void **pdata;
	char pathtofile[PATH];
	AVCLab *reg;
	AVCBinFile *file;
	SEXP *table,aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));

	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)),1);/*FIXME*/

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileLAB)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextLab(file)){n++;}

	Rprintf("Number of LABELS:%d\n",n);


	table=calloc(8, sizeof(SEXP));
	pdata=calloc(8, sizeof(void *));

	PROTECT(table[0]=NEW_INTEGER(n));
	pdata[0]=INTEGER(table[0]);
	PROTECT(table[1]=NEW_INTEGER(n));
	pdata[1]=INTEGER(table[1]);

	for(i=2;i<8;i++)
	{
		PROTECT(table[i]=NEW_NUMERIC(n));
		pdata[i]=REAL(table[i]);

	}

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		if(!(reg=(AVCLab*)AVCBinReadNextLab(file)))
			error("Error while reading register");


		((int *)pdata[0])[i]=reg->nValue;
		((int *)pdata[1])[i]=reg->nPolyId;

		((double*)pdata[2])[i]=reg->sCoord1.x;
		((double*)pdata[3])[i]=reg->sCoord1.y;
		((double*)pdata[4])[i]=reg->sCoord2.x;
		((double*)pdata[5])[i]=reg->sCoord2.y;
		((double*)pdata[6])[i]=reg->sCoord3.x;
		((double*)pdata[7])[i]=reg->sCoord3.y;
		
	}


	PROTECT(aux=NEW_LIST(8));

	for(i=0;i<8;i++)
	{
		SET_VECTOR_ELT(aux,i,table[i]);
	}

	UNPROTECT(9);

	free(table);
	free(pdata);

	return aux;
}
Пример #10
0
SEXP get_pal_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n;
	int **idata;
	char pathtofile[PATH];
	void **ptable;
	AVCPal *reg;
	AVCBinFile *file;
	SEXP *table, points, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));


	complete_path(pathtofile, (char *) CHAR(STRING_ELT(coverage,0)), 1);


	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFilePAL)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextPal(file)){n++;}

	Rprintf("Number of POLYGONS:%d\n",n);

	idata=calloc(3,sizeof(int *));

        table=calloc(6,sizeof(SEXP));
        ptable=(void **)calloc(6, sizeof(void *));

        PROTECT(table[0]=NEW_INTEGER(n));  /*Polygon ID*/
        ptable[0]=(int *)INTEGER(table[0]);
        PROTECT(table[1]=NEW_NUMERIC(n));  /*Min X. coordinate*/
        ptable[1]=(double *)REAL(table[1]);
        PROTECT(table[2]=NEW_NUMERIC(n));  /*Min Y. coordinate*/
        ptable[2]=(double *)REAL(table[2]);
        PROTECT(table[3]=NEW_NUMERIC(n));  /*Max X. coordinate*/
        ptable[3]=(double *)REAL(table[3]);
        PROTECT(table[4]=NEW_NUMERIC(n));  /*Max Y. coordinate*/
        ptable[4]=(double *)REAL(table[4]);
        PROTECT(table[5]=NEW_INTEGER(n));  /*Number of arcs*/
        ptable[5]=(int *)INTEGER(table[5]);
 
 
        PROTECT(points=NEW_LIST(n));  


	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		
		if(!(reg=(AVCPal*)AVCBinReadNextPal(file)))
			error("Error while reading register");


		((int *)ptable[0])[i]=reg->nPolyId;

		((double *)ptable[1])[i]=reg->sMin.x;
		((double *)ptable[2])[i]=reg->sMin.y;

		((double *)ptable[3])[i]=reg->sMax.x;
		((double *)ptable[4])[i]=reg->sMax.y;

		((int *)ptable[5])[i]=reg->numArcs;


		SET_VECTOR_ELT(points,i,NEW_LIST(3));
		aux=VECTOR_ELT(points,i);

		SET_VECTOR_ELT(aux,0,NEW_INTEGER(reg->numArcs));
		idata[0]=INTEGER(VECTOR_ELT(aux,0));
		SET_VECTOR_ELT(aux,1,NEW_INTEGER(reg->numArcs));
		idata[1]=INTEGER(VECTOR_ELT(aux,1));
		SET_VECTOR_ELT(aux,2,NEW_INTEGER(reg->numArcs));
		idata[2]=INTEGER(VECTOR_ELT(aux,2));

		for(j=0;j<reg->numArcs;j++)
		{
			idata[0][j]=reg->pasArcs[j].nArcId;
			idata[1][j]=reg->pasArcs[j].nFNode;
			idata[2][j]=reg->pasArcs[j].nAdjPoly;
		}

	}


        PROTECT(aux=NEW_LIST(7));
 
        for(i=0;i<6;i++)
        {
                SET_VECTOR_ELT(aux,i,table[i]);
        }
 
        SET_VECTOR_ELT(aux,6,points);
 
        UNPROTECT(8);  


	free(ptable);
	free(idata);

	return aux;
}
Пример #11
0
/*It imports the data from an arc file*/
SEXP get_arc_data(SEXP directory, SEXP coverage, SEXP filename) 
{
	int i,j,n, **ptable;
	double *x,*y;
	char pathtofile[PATH];
	AVCArc *reg;
	AVCBinFile *file;
	SEXP *table, points, aux;


	strcpy(pathtofile, CHAR(STRING_ELT(directory,0)));

	complete_path(pathtofile, (char *)CHAR(STRING_ELT(coverage,0)), 1);

	if(!(file=AVCBinReadOpen(pathtofile,CHAR(STRING_ELT(filename,0)), AVCFileARC)))
		error("Error opening file");

	n=0;

	while(AVCBinReadNextArc(file)){n++;}

	Rprintf("Number of ARCS:%d\n",n);


	table=calloc(7,sizeof(SEXP));
	ptable=(int **)calloc(7, sizeof(int *));
	for(i=0;i<7;i++)
	{
		PROTECT(table[i]=NEW_INTEGER(n));
		ptable[i]=(int *)INTEGER(table[i]);
	}


	PROTECT(points=NEW_LIST(n));

	if(AVCBinReadRewind(file))
		error("Rewind");

	for(i=0;i<n;i++)
	{
		
		if(!(reg=(AVCArc*)AVCBinReadNextArc(file)))
			error("Error while reading register");


		ptable[0][i]=reg->nArcId;

		ptable[1][i]=reg->nUserId;

		ptable[2][i]=reg->nFNode;

		ptable[3][i]=reg->nTNode;

		ptable[4][i]=reg->nLPoly;

		ptable[5][i]=reg->nRPoly;

		ptable[6][i]=reg->numVertices;

		SET_VECTOR_ELT(points,i,NEW_LIST(2));

		aux=VECTOR_ELT(points,i);

		SET_VECTOR_ELT(aux,0,NEW_NUMERIC(reg->numVertices));
		SET_VECTOR_ELT(aux,1,NEW_NUMERIC(reg->numVertices));

		x=REAL(VECTOR_ELT(aux,0));
		y=REAL(VECTOR_ELT(aux,1));

		for(j=0;j<reg->numVertices;j++)
		{
			x[j]=reg->pasVertices[j].x;
			y[j]=reg->pasVertices[j].y;
		}

	}

	PROTECT(aux=NEW_LIST(8));

	for(i=0;i<7;i++)
	{
		SET_VECTOR_ELT(aux,i,table[i]);
	}

	SET_VECTOR_ELT(aux,7,points);

	UNPROTECT(9);

	free(table);
	return aux;
}
Пример #12
0
bool OGRAVCBinLayer::CheckSetupTable()

{
    if( szTableName[0] == '\0' )
        return false;

/* -------------------------------------------------------------------- */
/*      Scan for the indicated section.                                 */
/* -------------------------------------------------------------------- */
    AVCE00ReadPtr psInfo
        = static_cast<OGRAVCBinDataSource *>( poDS )->GetInfo();
    const size_t BUFSIZE = 32;
    char szPaddedName[BUFSIZE+1] = { 0 };

    // Fill szPaddedName with szTableName up to 32 chars and fill the remaining
    // ones with ' '
    strncpy( szPaddedName, szTableName, BUFSIZE );
    if( strlen(szTableName) < BUFSIZE )
    {
        memset( szPaddedName + strlen(szTableName), ' ',
                BUFSIZE - strlen(szTableName) );
    }

    AVCE00Section *l_psSection = NULL;
    for( int iSection = 0; iSection < psInfo->numSections; iSection++ )
    {
        if( EQUAL(szPaddedName,psInfo->pasSections[iSection].pszName)
            && psInfo->pasSections[iSection].eType == AVCFileTABLE )
            l_psSection = psInfo->pasSections + iSection;
    }

    if( l_psSection == NULL )
    {
        szTableName[0] = '\0';
        return false;
    }

/* -------------------------------------------------------------------- */
/*      Try opening the table.                                          */
/* -------------------------------------------------------------------- */
    hTable = AVCBinReadOpen( psInfo->pszInfoPath,  szTableName,
                             psInfo->eCoverType, AVCFileTABLE,
                             psInfo->psDBCSInfo);

    if( hTable == NULL )
    {
        szTableName[0] = '\0';
        return false;
    }

/* -------------------------------------------------------------------- */
/*      Setup attributes.                                               */
/* -------------------------------------------------------------------- */
    nTableBaseField = poFeatureDefn->GetFieldCount();

    AppendTableDefinition( hTable->hdr.psTableDef );

/* -------------------------------------------------------------------- */
/*      Close table so we don't have to many files open at once.        */
/* -------------------------------------------------------------------- */
    AVCBinReadClose( hTable );

    hTable = NULL;

    return true;
}