コード例 #1
0
ファイル: RGISToolsPntExp.C プロジェクト: amiara/RGIS
int _RGISToolsPointExportARCInfo (DBObjData *data,char *selection)

	{
	FILE *file;
	DBInt pos;
	char coverName	[11], command    [FILENAME_MAX + 20]; 
	char asciiGenerate   [FILENAME_MAX];
	char asciiAttribDef  [FILENAME_MAX];
	char asciiAttribData [FILENAME_MAX];
	char amlFile    [FILENAME_MAX];

	sprintf (asciiGenerate,"%s/asciigen.tmp",selection);
	if (DBExportARCGenPoint (data,asciiGenerate) == DBFault) return (DBFault);
	sprintf (asciiAttribDef,"%s/asciiattrib.def",selection);
	if (DBExportARCTableDef (data,DBrNItems,asciiAttribDef) == DBFault)
		{ unlink (asciiGenerate); return (DBFault); }
	sprintf (asciiAttribData,"%s/asciiattrib.dat",selection);
	if (DBExportARCTableData (data,DBrNItems,asciiAttribData) == DBFault)
		{ unlink (asciiGenerate); unlink (asciiAttribDef); return (DBFault); }

	for (pos = strlen (data->FileName ());pos > 0;pos--) if ((data->FileName ()) [pos] == '/') break;
	strncpy (coverName,(data->FileName ()) + pos + 1,sizeof (coverName) - 1);
	coverName	[sizeof (coverName) - 1] = '\0';
	for (pos = 0;pos < (DBInt) strlen (coverName);++pos) if (coverName [pos] == '.') coverName [pos] = '\0';
	for (pos = 0;pos < (DBInt) strlen (coverName);++pos) coverName [pos] = tolower (coverName [pos]);
	sprintf (amlFile,"%s/pntcreate.aml",selection);
	if ((file = fopen (amlFile,"w")) == NULL)
		{
		unlink (asciiGenerate);
		unlink (asciiAttribDef);
		unlink (asciiAttribData);
		CMmsgPrint (CMmsgSysError, "Aml File Creation Error in: %s %d",__FILE__,__LINE__);
		return (DBFault);
		}
	fprintf (file,"&workspace %s\n",selection);
	fprintf (file,"generate c_%s\n",coverName);
	fprintf (file,"input %s\n",asciiGenerate);
	fprintf (file,"points\n");
	fprintf (file,"quit\n");
	fprintf (file,"build c_%s point\n",coverName);
	fprintf (file,"tables\n");
	fprintf (file,"define c_%s.pattr\n",coverName);
	fprintf (file,"&r %s\n",asciiAttribDef);
	fprintf (file,"~\n");
	fprintf (file,"alter id\n");
	fprintf (file,"c_%s-id,,,,\n",coverName);
	fprintf (file,"add\n");
	fprintf (file,"&r %s\n",asciiAttribData);
	fprintf (file,"~\n");
	fprintf (file,"q stop\n");
	fprintf (file,"joinitem c_%s.pat c_%s.pattr c_%s.pat c_%s-id c_%s-id\n",coverName,coverName,coverName,coverName,coverName);
	fprintf (file,"addxy C_%s point\n",coverName); 
	fprintf (file,"tables\n");
	fprintf (file,"select c_%s.pattr\n",coverName);
	fprintf (file,"erase c_%s.pattr\ny\n",coverName);
	fprintf (file,"q stop\n");
	fclose (file);

	if (getenv ("GHAAS_ARC") != NULL)
		{
		sprintf (command,getenv ("GHAAS_ARC"),amlFile);
		system (command);
		unlink (asciiGenerate);
		unlink (asciiAttribDef);
		unlink (asciiAttribData);
		unlink (amlFile);
		}
	return (DBSuccess);
	}
コード例 #2
0
ファイル: RGISToolsGrdExp.C プロジェクト: gyelnats/RGIS
int _RGISToolsGridExportARCInfo (DBObjData *data,char *selection)

	{
	DBInt layerID, i;
	FILE *file;
	char coverName	[11], command    [256]; 
	char asciiGrid   		[FILENAME_MAX];
	char attribDef   		[FILENAME_MAX];
	char attribData   	[FILENAME_MAX];
	char amlFile    [FILENAME_MAX];
	DBGridIF *gridIF = new DBGridIF (data);
	DBObjRecord *layerRec;

	for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
		{
		layerRec = gridIF->Layer (layerID);
		sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
		if (DBExportARCGridLayer (data,layerRec,asciiGrid) == DBFault) return (DBFault);
		}
	if (data->Type () == DBTypeGridDiscrete)
		{
		sprintf (attribDef,"%s/attrib.def",selection);
		if (DBExportARCTableDef (data,DBrNItems,attribDef) == DBFault)
			{ unlink (asciiGrid); return (DBFault); }
		sprintf (attribData,"%s/attrib.dat",selection);
		if (DBExportARCTableData (data,DBrNItems,attribData) == DBFault)
			{ unlink (asciiGrid); unlink (attribDef); return (DBFault); }
		}
	
	sprintf (amlFile,"%s/grdcreate.aml",selection);
	if ((file = fopen (amlFile,"w")) == NULL)
		{
		for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
			{
			layerRec = gridIF->Layer (layerID);
			sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
			unlink (asciiGrid);
			}
		if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); }
		CMmsgPrint (CMmsgAppError, "Aml File Creation Error in: %s %d",__FILE__,__LINE__);
		return (DBFault);
		}
	fprintf (file,"&workspace %s\n",selection);
	for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
		{
		layerRec = gridIF->Layer (layerID);
		strncpy (coverName,layerRec->Name (),sizeof (coverName) - 1);
		coverName	[sizeof (coverName) - 1] = '\0';
		for (i = 0;i < (DBInt) strlen (coverName);++i) if (coverName [i] == '.') coverName [i] = '\0';
		for (i = 0;i < (DBInt) strlen (coverName);++i) coverName [i] = tolower (coverName [i]);
		sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
		if (data->Type () == DBTypeGridContinuous)
			fprintf (file,"asciigrid %s g_%s float\n",asciiGrid,coverName);
		else
			fprintf (file,"asciigrid %s g_%s int\n",asciiGrid,coverName);
		if (data->Type () == DBTypeGridDiscrete)
			{
			fprintf (file,"tables\n");
			fprintf (file,"define g_%s.vattr\n",coverName);
			fprintf (file,"&r %s\n",attribDef);
			fprintf (file,"~\n");
			fprintf (file,"alter GridValue\n");
			fprintf (file,"value,,,,\n");
			fprintf (file,"add\n");
			fprintf (file,"&r %s\n",attribData);
			fprintf (file,"~\n");
			fprintf (file,"q stop\n");
			fprintf (file,"joinitem g_%s.vat g_%s.vattr g_%s.vat value count\n",coverName,coverName,coverName);
			fprintf (file,"tables\n");
			fprintf (file,"select g_%s.vattr\n",coverName);
			fprintf (file,"erase g_%s.vattr\ny\n",coverName);
			fprintf (file,"q stop\n");
			}
		}
	fclose (file);

	if (getenv ("GHAAS_ARC") != NULL)
		{
		sprintf (command,getenv ("GHAAS_ARC"),amlFile);

		system (command);
		for (layerID = 0;layerID < gridIF->LayerNum ();++layerID)
			{
			layerRec = gridIF->Layer (layerID);
			sprintf (asciiGrid,"%s/asciigrid%d.tmp",selection,layerID);
			unlink (asciiGrid);
			}
		if (data->Type () == DBTypeGridDiscrete) { unlink (attribDef); unlink (attribData); }
		unlink (amlFile);
		}
	return (DBSuccess);
	}
コード例 #3
0
ファイル: RGISToolsNetExp.C プロジェクト: amiara/RGIS
int _RGISToolsNetworkExportARCInfo (DBObjData *netData,char *selection)

	{
	FILE *file;
	char command    [256]; 
	char asciiGridNet		[FILENAME_MAX]; 
	char asciiGridBasin	[FILENAME_MAX]; 
	char asciiGridOrder	[FILENAME_MAX]; 
	char asciiGridArea	[FILENAME_MAX]; 
	char asciiGridLength	[FILENAME_MAX]; 
	char asciiGridDistToMouth [FILENAME_MAX]; 
	char asciiGridDistToOcean [FILENAME_MAX]; 
	char arcGenArc  		[FILENAME_MAX]; 
	char arcGenNode 		[FILENAME_MAX]; 
	char arcAttribDef		[FILENAME_MAX]; 
	char arcAttribData	[FILENAME_MAX]; 
	char nodeAttribDef	[FILENAME_MAX]; 
	char nodeAttribData	[FILENAME_MAX]; 
	char amlFile    		[FILENAME_MAX]; 

	sprintf (asciiGridNet,"%s/asciigrid.tmp",selection);
	if (DBNetworkExportASCIIGridDir (netData,asciiGridNet) == DBFault) return (DBFault);

	sprintf (asciiGridBasin,"%s/asciibasin.tmp",selection);
	if (DBNetworkExportASCIIGridBasin (netData,asciiGridBasin) == DBFault)
		{
		unlink (asciiGridNet);
		return (DBFault);
		}

	sprintf (asciiGridOrder,"%s/asciiorder.tmp",selection);
	if (DBNetworkExportASCIIGridOrder (netData,asciiGridOrder) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		return (DBFault);
		}

	sprintf (asciiGridArea,"%s/asciiarea.tmp",selection);
	if (DBNetworkExportASCIIGridArea (netData,asciiGridArea) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		return (DBFault);
		}

	sprintf (asciiGridLength,"%s/asciilength.tmp",selection);
	if (DBNetworkExportASCIIGridLength (netData,asciiGridLength) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		return (DBFault);
		}

	sprintf (asciiGridDistToMouth,"%s/asciidist2mouth.tmp",selection);
	if (DBNetworkExportASCIIGridDistToMouth (netData,asciiGridDistToMouth) == DBFault)
		strcpy (asciiGridDistToMouth,"");

	sprintf (asciiGridDistToOcean,"%s/asciidist2ocean.tmp",selection);
	if (DBNetworkExportASCIIGridDistToOcean (netData,asciiGridDistToOcean) == DBFault)
		strcpy (asciiGridDistToOcean,"");

	sprintf (arcGenArc,"%s/arcgenarc.tmp",selection);
	if (DBNetworkExportArcGenARC (netData,arcGenArc) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		return (DBFault);
		}

	sprintf (arcGenNode,"%s/arcgennode.tmp",selection);
	if (DBNetworkExportArcGenNODE (netData,arcGenNode) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		unlink (arcGenArc);
		return (DBFault);
		}

	sprintf (arcAttribDef,"%s/arc_def.tmp",selection);
	if (DBExportARCTableDef (netData,DBrNCells,arcAttribDef) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		unlink (arcGenArc);
		unlink (arcGenNode);
		return (DBFault);
		}

	sprintf (arcAttribData,"%s/arc_data.tmp",selection);
	if (DBExportARCTableData (netData,DBrNCells,arcAttribData) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		unlink (arcGenArc);
		unlink (arcGenNode);
		unlink (arcAttribDef);
		return (DBFault);
		}
	sprintf (nodeAttribDef,"%s/node_def.tmp",selection);
	if (DBExportARCTableDef (netData,DBrNItems,nodeAttribDef) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		unlink (arcGenArc);
		unlink (arcGenNode);
		unlink (arcAttribDef);
		unlink (arcAttribData);
		return (DBFault);
		}
	sprintf (nodeAttribData,"%s/node_data.tmp",selection);
	if (DBExportARCTableData (netData,DBrNItems,nodeAttribData) == DBFault)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		unlink (arcGenArc);
		unlink (arcGenNode);
		unlink (arcAttribDef);
		unlink (arcAttribData);
		unlink (nodeAttribDef);
		return (DBFault);
		}

	sprintf (amlFile,"%s/netcreate.aml",selection);
	if ((file = fopen (amlFile,"w")) == NULL)
		{
		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		unlink (arcGenArc);
		unlink (arcGenNode);
		unlink (arcAttribDef);
		unlink (arcAttribData);
		unlink (nodeAttribData);
		unlink (nodeAttribDef);
		CMmsgPrint (CMmsgSysError, "File Creation Error in: %s %d",__FILE__,__LINE__);
		return (DBFault);
		}

	fprintf (file,"&workspace %s\n",selection);
	fprintf (file,"asciigrid %s g_network\n",asciiGridNet);
	fprintf (file,"asciigrid %s g_basin\n",asciiGridBasin);
	fprintf (file,"asciigrid %s g_order\n",asciiGridOrder);
	fprintf (file,"asciigrid %s g_cumularea float\n",asciiGridArea);
	fprintf (file,"asciigrid %s g_length float\n",asciiGridLength);
	if (strlen (asciiGridDistToMouth) > 1)
		fprintf (file,"asciigrid %s g_distmouth float\n",asciiGridDistToMouth);
	if (strlen (asciiGridDistToOcean) > 1)
		fprintf (file,"asciigrid %s g_distocean float\n",asciiGridDistToOcean);

	fprintf (file,"generate c_network\n");
	fprintf (file,"input %s\nlines\n",arcGenArc);
	fprintf (file,"input %s\npoints\n",arcGenNode);
	fprintf (file,"quit\n");
	fprintf (file,"build c_network arc\n");
	fprintf (file,"build c_network node\n");
	fprintf (file,"build c_network point\n");
	fprintf (file,"gridpoly g_basin c_basin\n");
	fprintf (file,"build c_basin arc\n");
	fprintf (file,"build c_basin node\n");

	fprintf (file,"tables\n");
	fprintf (file,"define c_network.aattr\n");
	fprintf (file,"&r %s\n",arcAttribDef);
	fprintf (file,"~\n");
	fprintf (file,"add\n");
	fprintf (file,"&r %s\n",arcAttribData);
	fprintf (file,"~\n");

	fprintf (file,"define c_network.pattr\n");
	fprintf (file,"&r %s\n",nodeAttribDef);
	fprintf (file,"~\n");
	fprintf (file,"alter\n");
	fprintf (file,"ID basinID,,,,\n");
	fprintf (file,"~\n");
	fprintf (file,"add\n");
	fprintf (file,"&r %s\n",nodeAttribData);
	fprintf (file,"~\n");

	fprintf (file,"additem G_BASIN.VAT row 4 8 b\n");
	fprintf (file,"select G_BASIN.VAT\n");
	fprintf (file,"calculate row = value + 1\n");
	fprintf (file,"select C_BASIN.PAT\n");
	fprintf (file,"alter\n");
	fprintf (file,"grid-code basinID,,,,\n");
	fprintf (file,"~\n");
	
	fprintf (file,"q stop\n");

	fprintf (file,"joinitem C_NETWORK.AAT C_NETWORK.AATTR C_NETWORK.AAT c_network# c_network-id link\n");
	fprintf (file,"joinitem C_NETWORK.PAT C_NETWORK.PATTR C_NETWORK.PAT c_network# c_network-id link\n");
	fprintf (file,"joinitem G_BASIN.VAT   C_NETWORK.PATTR G_BASIN.VAT   VALUE      count        link\n");
	fprintf (file,"joinitem C_BASIN.PAT   C_NETWORK.PATTR C_BASIN.PAT   BASINID      BASINID\n");
/*	fprintf (file,"arcedit\nec c_network\nef arc\n");
	fprintf (file,"select LENGTH < %f\ndelete\n",pow ((double) 10.0,(double) netData->Precision ()) * 2.0);
	fprintf (file,"save\nq\n");
*/	fprintf (file,"tables\n");
	fprintf (file,"dropitem G_BASIN.VAT row\n");
	fprintf (file,"select C_NETWORK.AATTR\nerase C_NETWORK.AATTR\ny\n");
	fprintf (file,"select C_NETWORK.PATTR\nerase C_NETWORK.PATTR\ny\n");
	fprintf (file,"q stop\n");
	fprintf (file,"addxy C_NETWORK point\n"); 
	fclose  (file);

	if (getenv ("GHAAS_ARC") != NULL)
		{
		sprintf (command,getenv ("GHAAS_ARC"),amlFile);

		system (command);

		unlink (asciiGridNet);
		unlink (asciiGridBasin);
		unlink (asciiGridOrder);
		unlink (asciiGridArea);
		unlink (asciiGridLength);
		if (strlen (asciiGridDistToMouth) > 1) unlink (asciiGridDistToMouth);
		if (strlen (asciiGridDistToOcean) > 1) unlink (asciiGridDistToOcean);
		unlink (arcGenArc);
		unlink (arcGenNode);
		unlink (arcAttribDef);
		unlink (arcAttribData);
		unlink (nodeAttribData);
		unlink (nodeAttribDef);
		unlink (amlFile);
		}
	return (DBSuccess);
	}