[Gdal-dev] [C# bindings] TIF Point or Area

Jean Michel PIERRET jmp at geosys.com
Tue Jan 30 08:04:45 EST 2007


Hi, 

It works now using the function getMetadata,
Thanks for your help.

Best Regards

PIERRET Jean michel.

-----Message d'origine-----
De : Tamas Szekeres [mailto:szekerest at gmail.com] 
Envoyé : lundi 29 janvier 2007 00:11
À : Chapman, Martin
Cc : Jean Michel PIERRET; gdal-dev at lists.maptools.org
Objet : Re: [Gdal-dev] [C# bindings] TIF Point or Area

Hi All,

This kind of information can now be obtained by using the GDAL SWIG C#
interface as well. And there's no need to compile project with /unsafe
in this case.
I've committed a sample (/csharp/apps/GDALInfo.cs) to show how to
display various information about the raster data.
To use this functionality the latest SVN trunk should be checked out.

Best Regards,


Tamas



2007/1/28, Chapman, Martin <MChapman at sanz.com>:
>
>
>
>
> Jean,
>
>
>
> Here is a function I use to get a bunch of metadata from any image.  If
the
> image has the value AREA_OR_POINT in a tiff file then it will be in the
list
> output by the first for loop in the function below and the value will be
> "Point" or "Area".  To do it in c# just use the __unsafe {} block in your
> code and use the c++ code below.  The classes that start with IVP
 and
CVP

> are my own classes.  Let me know if you have questions.
>
>
>
> Best regards,
>
>
>
> Martin chapman
>
>
>
> vector< string>* CVPGdalRasterSet::GetMetaData()
>
> {
>
>       try
>
>       {
>
>             if (m_pMetaData) return (vector< string>*) m_pMetaData;
>
>             m_pMetaData = new vector< string>;
>
>
>
>             if
> (!((CVPGdalConnection*)m_spConnection.p)->m_pDataSource)
> return m_pMetaData;
>
>
>
>             GDALDataset* pDataSource =
> ((CVPGdalConnection*)m_spConnection.p)->m_pDataSource;
>
>             char** ppszMetadata = pDataSource->GetMetadata();
>
>             if (ppszMetadata)
>
>             {
>
>                   for (int i = 0; ppszMetadata[i] != NULL; i++)
>
>                   {
>
>                         string sMetaItem = (string) (char*)
ppszMetadata[i];
>
>
>
>                         if (sMetaItem.size() == 0)
>
>                               continue;
>
>
>
>                         string sLastChar =
sMetaItem.substr(sMetaItem.size()
> - 1, 1);
>
>                         if (sLastChar == "=")
>
>                               sMetaItem += "Undefined";
>
>
>
>                         m_pMetaData->push_back(sMetaItem);
>
>                   }
>
>             }
>
>
>
>             for (int iBand = 0; iBand < pDataSource->GetRasterCount();
> iBand++)
>
>             {
>
>                   double dfMin, dfMax, dfNoData;
>
>                   int bGotMin, bGotMax, bGotNodata;
>
>                   int nBlockXSize, nBlockYSize;
>
>
>
>                   GDALRasterBand* pBand =
> pDataSource->GetRasterBand(iBand+1);
>
>
>
>                   /*float afSample[10000];
>
>                   int nCount =
> GDALGetRandomRasterSample(pBand, 10000, afSample);
>
>                   stringstream sSamples;
>
>                   sSamples << "BAND " << iBand + 1 << " SAMPLES=" <<
nCount;
>
>                   m_pMetaData->push_back(sSamples.str());*/
>
>
>
>                   pBand->GetBlockSize(&nBlockXSize,
> &nBlockYSize);
>
>                   stringstream sBlock;
>
>                   sBlock << "BAND " << iBand + 1 << " BLOCK=" <<
nBlockXSize
> << "x" << nBlockYSize;
>
>                   m_pMetaData->push_back(sBlock.str());
>
>
>
>                   string sDataTypeName = (string) (char*)
> GDALGetDataTypeName(pBand->GetRasterDataType());
>
>                   stringstream sDataTypeNameStream;
>
>                   sDataTypeNameStream << "BAND " << iBand + 1 << " DATA
> TYPE=" << sDataTypeName.c_str();
>
>                   m_pMetaData->push_back(sDataTypeNameStream.str());
>
>
>
>                   string sColorInterpret = (string) (char*)
> GDALGetColorInterpretationName(pBand->GetColorInterpretation());
>
>                   stringstream sColorInterpretStream;
>
>                   sColorInterpretStream << "BAND " << iBand + 1 << " COLOR
> INTERPRETATION=" << sColorInterpret.c_str();
>
>                   m_pMetaData->push_back(sColorInterpretStream.str());
>
>
>
>                   string sDescription = (char*) pBand->GetDescription();
>
>                   if (sDescription.size() > 0)
>
>                   {
>
>                         if (sDescription == "") sDescription = " ";
>
>                         stringstream sStream;
>
>                         sStream << "BAND " << iBand + 1 << " DESCRIPTION="
> << (char*) sDescription.c_str();
>
>                         m_pMetaData->push_back(sStream.str());
>
>                   }
>
>
>
>                   dfMin = pBand->GetMinimum(&bGotMin);
>
>                   dfMax = pBand->GetMaximum(&bGotMax);
>
>                   stringstream sStreamMin;
>
>                   sStreamMin << "BAND " << iBand + 1 << " MINIMUM=" <<
> dfMin;
>
>                   m_pMetaData->push_back(sStreamMin.str());
>
>
>
>                   stringstream sStreamMax;
>
>                   sStreamMax << "BAND " << iBand + 1 << " MAXIMUM=" <<
> dfMax;
>
>                   m_pMetaData->push_back(sStreamMax.str());
>
>
>
>                   dfNoData =
> pBand->GetNoDataValue(&bGotNodata);
>
>                   stringstream sStreamNoData;
>
>                   sStreamNoData << "BAND " << iBand + 1 << " NO DATA
VALUE="
> << dfNoData;
>
>                   m_pMetaData->push_back(sStreamNoData.str());
>
>             }
>
>
>
>             return (vector< string>*) m_pMetaData;
>
>       }
>
>       catch(exception e)
>
>             {throw e;}
>
>       catch(char* e)
>
>             {throw e;}
>
>       catch(...)
>
>             {throw "An unexpected error occurred in
> CVPGdalRasterSet::GetMetaData().";}
>
> }
>
>
>
>
>
> Martin Chapman
>
> SANZ Inc.
>
> Software Developer
>
> http://www.earthwhere.com
>
> W - 303.495.6326
>
> C  - 303.898.0397
>
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
>
>





More information about the Gdal-dev mailing list