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

📄 shp.zip.rar.txt

📁 这个是关于arcview的shape下的shp后缀,在argic里面,能够很好地进行移植
💻 TXT
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct tagRleCode{
	int attrib;
	int lenth;
}RLECODE;
int GenCode(char* OutDirectory,int row,int col,int* data);

int main(int argc,char** argv)
{
	char* InputFileName;
	char* FileDirectory;
	FILE* fpInFile;
	int nRows;
	int nCols;
	char* chTemp;
	int* pData;
	int i,j;
	int nCodes;

	InputFileName = (char*)malloc(256*sizeof(char));
	if(!InputFileName) return 0;
	InputFileName[0]='\0';
	fpInFile=NULL;

	if(argc<2)
	{
		printf("Please input the file name\n");
		scanf("%s",InputFileName);
	}
	else 
		strcpy(InputFileName,argv[1]);

//	printf("%s\n",InputFileName);
	FileDirectory = (char*)malloc(256*sizeof(char));
	if(!FileDirectory) 
	{
		free(InputFileName);
		return 0;
	}
	char* substr = strrchr(InputFileName,'\\');
	i = (int)strlen(InputFileName);
	j = (int)strlen(substr);
	i -= (j-1);
	for(j=0;j<i;j++)
		FileDirectory[j]=InputFileName[j];
	FileDirectory[j]='\0';

	fpInFile = fopen(InputFileName,"r");
	if(!fpInFile)
	{
		printf("Can't open file for reading\n");
		free(InputFileName);	
		return 0;
	}
	
	chTemp = (char*)malloc(20*sizeof(char));
	if(!chTemp)
	{
		printf("Can't allocate memory\n");
		free(InputFileName);
		fclose(fpInFile);
		return 0;
	}
	chTemp[0]='\0';

	nCodes = 0;
	fscanf(fpInFile,"%s",chTemp);
	if(0==strcmp(chTemp,"Raster_Data"))
	{
		fscanf(fpInFile,"%d%d",&nRows,&nCols);
//		printf("%d,%d\n",nRows,nCols);
		pData = (int*)malloc(nRows*nCols*sizeof(int));
		if(pData)
		{
			for(i=0;i<nRows;i++)
				for(j=0;j<nCols;j++)
				{
					fscanf(fpInFile,"%d",&pData[i*nRows+j]);
				}
			nCodes = GenCode(FileDirectory,nRows,nCols,pData);
		}
	}

	if(nCodes>0)
	{
		i = nCodes*sizeof(RLECODE);
		j = nRows*nCols*sizeof(int);
		printf("The compression ratio is %.4f\n",(float)i/(float)j);
	}
	free(InputFileName);
	free(FileDirectory);
	free(chTemp);
	fclose(fpInFile);
	return 1;
}
//生成游程长度编码
//OutDirectory:输出编码文件的路径;
int GenCode(char* OutDirectory,int row,int col,int* data)
{
	FILE* fpOutFile;
	char* OutFileName;
	int i,j;
	int n;
	RLECODE code;
	int nCode;

	nCode = 0;
	OutFileName = strcat(OutDirectory,"RLE.text");
	
	fpOutFile=fopen(OutFileName,"w");
	if(fpOutFile)
	{
		for (i=0;i<row;i++)
		{
			n = 1;
			for(j=0;j<col-1;j++)
			{
				if(data[i*row+j]==data[i*row+j+1])
					n += 1;
				else
				{
					code.lenth = n;
					code.attrib = data[i*row+j];
					n=1;
					fprintf(fpOutFile,"(%d,%d) ",code.attrib ,code.lenth );
					nCode += 1;
				}
			}
			code.lenth = n;
			code.attrib = data[i*row+j];
			fprintf(fpOutFile,"(%d,%d) ",code.attrib ,code.lenth );	
			nCode += 1;
			
			fprintf(fpOutFile,"\n");
		}
		fclose(fpOutFile);
	}
	return nCode;
}

⌨️ 快捷键说明

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