Skip to content
Snippets Groups Projects
Commit 6ad83e79 authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

Ajout GDAL Nouvelle version

parent 34283e9d
Branches
Tags
No related merge requests found
/******************************************************************************
* $Id: jdemdataset.cpp,v 1.9 2005/05/05 15:54:48 fwarmerdam Exp $
*
* Project: JDEM Reader
* Purpose: All code for Japanese DEM Reader
* Author: Frank Warmerdam, warmerdam@pobox.com
*
******************************************************************************
* Copyright (c) 2000, Frank Warmerdam <warmerdam@pobox.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*
* $Log: jdemdataset.cpp,v $
* Revision 1.9 2005/05/05 15:54:48 fwarmerdam
* PAM Enabled
*
* Revision 1.8 2003/07/08 21:21:56 warmerda
* avoid warnings
*
* Revision 1.7 2002/09/04 06:50:37 warmerda
* avoid static driver pointers
*
* Revision 1.6 2002/06/12 21:12:25 warmerda
* update to metadata based driver info
*
* Revision 1.5 2001/11/11 23:51:00 warmerda
* added required class keyword to friend declarations
*
* Revision 1.4 2001/07/18 04:51:57 warmerda
* added CPL_CVSID
*
* Revision 1.3 2001/06/21 19:59:51 warmerda
* added help link
*
* Revision 1.2 2000/11/28 02:28:54 warmerda
* Added error checks, GetGeoTransform and GetProjection
*
* Revision 1.1 2000/11/27 19:03:26 warmerda
* New
*
*/
#include "gdal_pam.h"
CPL_CVSID("$Id: jdemdataset.cpp,v 1.9 2005/05/05 15:54:48 fwarmerdam Exp $");
CPL_C_START
void GDALRegister_JDEM(void);
CPL_C_END
/************************************************************************/
/* JDEMGetField() */
/************************************************************************/
static int JDEMGetField( char *pszField, int nWidth )
{
char szWork[32];
CPLAssert( nWidth < (int) sizeof(szWork) );
strncpy( szWork, pszField, nWidth );
szWork[nWidth] = '\0';
return atoi(szWork);
}
/************************************************************************/
/* JDEMGetAngle() */
/************************************************************************/
static double JDEMGetAngle( char *pszField )
{
int nAngle = JDEMGetField( pszField, 7 );
int nDegree, nMin, nSec;
// Note, this isn't very general purpose, but it would appear
// from the field widths that angles are never negative. Nice
// to be a country in the "first quadrant".
nDegree = nAngle / 10000;
nMin = (nAngle / 100) % 100;
nSec = nAngle % 100;
return nDegree + nMin / 60.0 + nSec / 3600.0;
}
/************************************************************************/
/* ==================================================================== */
/* JDEMDataset */
/* ==================================================================== */
/************************************************************************/
class JDEMRasterBand;
class JDEMDataset : public GDALPamDataset
{
friend class JDEMRasterBand;
FILE *fp;
GByte abyHeader[1012];
public:
~JDEMDataset();
static GDALDataset *Open( GDALOpenInfo * );
CPLErr GetGeoTransform( double * padfTransform );
const char *GetProjectionRef();
};
/************************************************************************/
/* ==================================================================== */
/* JDEMRasterBand */
/* ==================================================================== */
/************************************************************************/
class JDEMRasterBand : public GDALPamRasterBand
{
friend class JDEMDataset;
public:
JDEMRasterBand( JDEMDataset *, int );
virtual CPLErr IReadBlock( int, int, void * );
};
/************************************************************************/
/* JDEMRasterBand() */
/************************************************************************/
JDEMRasterBand::JDEMRasterBand( JDEMDataset *poDS, int nBand )
{
this->poDS = poDS;
this->nBand = nBand;
eDataType = GDT_Float32;
nBlockXSize = poDS->GetRasterXSize();
nBlockYSize = 1;
}
/************************************************************************/
/* IReadBlock() */
/************************************************************************/
CPLErr JDEMRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
{
JDEMDataset *poGDS = (JDEMDataset *) poDS;
char *pszRecord;
int nRecordSize = nBlockXSize*5 + 9 + 2;
int i;
VSIFSeek( poGDS->fp, 1011 + nRecordSize*nBlockYOff, SEEK_SET );
pszRecord = (char *) CPLMalloc(nRecordSize);
VSIFRead( pszRecord, 1, nRecordSize, poGDS->fp );
if( !EQUALN((char *) poGDS->abyHeader,pszRecord,6) )
{
CPLFree( pszRecord );
CPLError( CE_Failure, CPLE_AppDefined,
"JDEM Scanline corrupt. Perhaps file was not transferred\n"
"in binary mode?" );
return CE_Failure;
}
if( JDEMGetField( pszRecord + 6, 3 ) != nBlockYOff + 1 )
{
CPLFree( pszRecord );
CPLError( CE_Failure, CPLE_AppDefined,
"JDEM scanline out of order, JDEM driver does not\n"
"currently support partial datasets." );
return CE_Failure;
}
for( i = 0; i < nBlockXSize; i++ )
((float *) pImage)[i] = (float)
(JDEMGetField( pszRecord + 9 + 5 * i, 5) * 0.1);
return CE_None;
}
/************************************************************************/
/* ==================================================================== */
/* JDEMDataset */
/* ==================================================================== */
/************************************************************************/
/************************************************************************/
/* ~JDEMDataset() */
/************************************************************************/
JDEMDataset::~JDEMDataset()
{
FlushCache();
if( fp != NULL )
VSIFClose( fp );
}
/************************************************************************/
/* GetGeoTransform() */
/************************************************************************/
CPLErr JDEMDataset::GetGeoTransform( double * padfTransform )
{
double dfLLLat, dfLLLong, dfURLat, dfURLong;
dfLLLat = JDEMGetAngle( (char *) abyHeader + 29 );
dfLLLong = JDEMGetAngle( (char *) abyHeader + 36 );
dfURLat = JDEMGetAngle( (char *) abyHeader + 43 );
dfURLong = JDEMGetAngle( (char *) abyHeader + 50 );
padfTransform[0] = dfLLLong;
padfTransform[3] = dfURLat;
padfTransform[1] = (dfURLong - dfLLLong) / GetRasterXSize();
padfTransform[2] = 0.0;
padfTransform[4] = 0.0;
padfTransform[5] = -1 * (dfURLat - dfLLLat) / GetRasterYSize();
return CE_None;
}
/************************************************************************/
/* GetProjectionRef() */
/************************************************************************/
const char *JDEMDataset::GetProjectionRef()
{
return( "GEOGCS[\"Tokyo\",DATUM[\"Tokyo\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",7004]],TOWGS84[-148,507,685,0,0,0,0],AUTHORITY[\"EPSG\",6301]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]],UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",9108]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",4301]]" );
}
/************************************************************************/
/* Open() */
/************************************************************************/
GDALDataset *JDEMDataset::Open( GDALOpenInfo * poOpenInfo )
{
/* -------------------------------------------------------------------- */
/* Before trying JDEMOpen() we first verify that there is at */
/* least one "\n#keyword" type signature in the first chunk of */
/* the file. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->fp == NULL || poOpenInfo->nHeaderBytes < 50 )
return NULL;
/* check if century values seem reasonable */
if( (!EQUALN((char *)poOpenInfo->pabyHeader+11,"19",2)
&& !EQUALN((char *)poOpenInfo->pabyHeader+11,"20",2))
|| (!EQUALN((char *)poOpenInfo->pabyHeader+15,"19",2)
&& !EQUALN((char *)poOpenInfo->pabyHeader+15,"20",2))
|| (!EQUALN((char *)poOpenInfo->pabyHeader+19,"19",2)
&& !EQUALN((char *)poOpenInfo->pabyHeader+19,"20",2)) )
{
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
JDEMDataset *poDS;
poDS = new JDEMDataset();
poDS->fp = poOpenInfo->fp;
poOpenInfo->fp = NULL;
/* -------------------------------------------------------------------- */
/* Read the header. */
/* -------------------------------------------------------------------- */
VSIFSeek( poDS->fp, 0, SEEK_SET );
VSIFRead( poDS->abyHeader, 1, 1012, poDS->fp );
poDS->nRasterXSize = JDEMGetField( (char *) poDS->abyHeader + 23, 3 );
poDS->nRasterYSize = JDEMGetField( (char *) poDS->abyHeader + 26, 3 );
/* -------------------------------------------------------------------- */
/* Create band information objects. */
/* -------------------------------------------------------------------- */
poDS->SetBand( 1, new JDEMRasterBand( poDS, 1 ));
/* -------------------------------------------------------------------- */
/* Initialize any PAM information. */
/* -------------------------------------------------------------------- */
poDS->SetDescription( poOpenInfo->pszFilename );
poDS->TryLoadXML();
return( poDS );
}
/************************************************************************/
/* GDALRegister_JDEM() */
/************************************************************************/
void GDALRegister_JDEM()
{
GDALDriver *poDriver;
if( GDALGetDriverByName( "JDEM" ) == NULL )
{
poDriver = new GDALDriver();
poDriver->SetDescription( "JDEM" );
poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
"Japanese DEM (.mem)" );
poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC,
"frmt_various.html#JDEM" );
poDriver->SetMetadataItem( GDAL_DMD_EXTENSION, "mem" );
poDriver->pfnOpen = JDEMDataset::Open;
GetGDALDriverManager()->RegisterDriver( poDriver );
}
}
OBJ = jdemdataset.obj
EXTRAFLAGS = -I..\iso8211
GDAL_ROOT = ..\..
!INCLUDE $(GDAL_ROOT)\nmake.opt
default: $(OBJ)
copy *.obj ..\o
clean:
-del *.obj
REQUIREMENTS :
* Make sure you have a full PostgreSQL/Postgis clean source installation
* You need to have Proj4 installed and configured in Pstgis to get the driver work
INSTALL NOTES :
1* Go to frmts directory under GDAL source tree
2* Unpack pgchip archive in the frmts directory
3* Edit GNUMakefile to set your Postgis include path
4* Add registration entry point declaration :
- Open gdal/gcore/gdal_frmts.h
- Add "void CPL_DLL GDALRegister_PGCHIP(void);" between the CPL_C_START and CPL_C_END tags
5* Add a call to the registration function in frmts/gdalallregister.c
In the GDALAllRegister() function add the followinf lines :
#ifdef FRMT_pgchip
GDALRegister_PGCHIP();
#endif
6* Add the format short name to the GDAL_FORMATS macro in GDALmake.opt.in (and to GDALmake.opt) :
- Locate the variable GDAL_FORMATS and add "pgchip" (lowercase) to the list of formats
7* Add a format specific item to the EXTRAFLAGS macro in frmts/makefile.vc
8* Recompile your GDAL library :
- make clean
-./configure
- make
- make install
9* Test your pgchip installation :
execute gdalinfo --formats and search for pgchip
\ No newline at end of file
Important Drivers Restrictions :
* PGCHIP driver is currently under development which means it has NOT been fully tested and no stable release is downloadable.
* The driver only supports GDT_Byte and GDT_UInt16 datatypes and deals with 1 or 4 bands (GREY_SCALE, PALETTE and RGBA)
* The column name for the chip is not yet changeable and is "raster" by default
* In order to specify the database you want to connect to, you have to give a connection string. The differents connection parameters (host,port,dbname) must be delimited with a "#" character. The name of the Postgis layer should be given at the end of the string after a "%layer=" argument. Example :
$ gdalinfo PG:host=192.168.1.1#dbname=mydb%layer=myRasterTable
How can I test the driver :
* You can choose to build your own application using the GDAL API or use the utility programs.
* Some examples with gdal_translate :
Import BMP raster :
gdal_translate -of pgchip /DATA/myRaster.bmp PG:host=192.168.1.1#dbname=mydb#port=5432%layer=myRaster
Then export to PNG :
gdal_translate -of png -ot UInt16 PG:host=192.168.1.1#dbname=mydb#port=5432%layer=myRaster /DATA/myRaster.png
Author information and bug report :
website : http://simon.benjamin.free.fr/pgchip/
email : noumayoss@gmail.com
OBJ = pgChipdataset.obj
EXTRAFLAGS = -I..\iso8211
GDAL_ROOT = ..\..
!INCLUDE $(GDAL_ROOT)\nmake.opt
default: $(OBJ)
copy *.obj ..\o
clean:
-del *.obj
/******************************************************************************
*
* File : pgchip.h
* Project: PGCHIP Driver
* Purpose: Main header file for POSTGIS CHIP/GDAL Driver
* Author: Benjamin Simon, noumayoss@gmail.com
*
******************************************************************************
* Copyright (c) 2005, Benjamin Simon, noumayoss@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*
* Revision 1.1 2005/08/29 bsimon
* New
*
*/
#include "gdal_priv.h"
#include "libpq-fe.h"
#include "liblwgeom.h"
// External functions (what's again the reason for using explicit hex form ?)
extern void deparse_hex_string(unsigned char *strOut,char *strIn,int length);
extern void parse_hex_string(unsigned char *strOut,char *strIn,int length);
/* color types */
#define PGCHIP_COLOR_TYPE_GRAY 0
#define PGCHIP_COLOR_TYPE_PALETTE 1
#define PGCHIP_COLOR_TYPE_RGB_ALPHA 4
//pg_chip color struct
typedef struct pgchip_color_nohex_struct
{
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
} pgchip_color;
/************************************************************************/
/* ==================================================================== */
/* PGCHIPDataset */
/* ==================================================================== */
/************************************************************************/
class PGCHIPRasterBand;
class PGCHIPDataset : public GDALDataset{
friend class PGCHIPRasterBand;
PGconn *hPGConn;
char *pszConnectionString;
char *pszDBName;
char *pszName;
char *pszProjection;
int bHavePostGIS;
CHIP *PGCHIP;
int SRID;
int nBitDepth;
int nColorType; /* PGHIP_COLOR_TYPE_* */
GDALColorTable *poColorTable;
int bHaveNoData;
double dfNoDataValue;
double adfGeoTransform[6];
int bGeoTransformValid;
public:
PGCHIPDataset();
~PGCHIPDataset();
static GDALDataset *Open( GDALOpenInfo * );
void printChipInfo();
CPLErr GetGeoTransform( double * padfTransform );
virtual CPLErr SetGeoTransform( double * );
CPLErr SetProjection( const char *);
const char *GetProjectionRef();
};
/************************************************************************/
/* ==================================================================== */
/* PGCHIPRasterBand */
/* ==================================================================== */
/************************************************************************/
class PGCHIPRasterBand : public GDALRasterBand{
friend class PGCHIPDataset;
public:
PGCHIPRasterBand( PGCHIPDataset *, int );
virtual CPLErr IReadBlock( int, int, void * );
virtual GDALColorInterp GetColorInterpretation();
virtual GDALColorTable *GetColorTable();
};
This diff is collapsed.
/******************************************************************************
*
* File : pgchiprasterband.cpp
* Project: PGCHIP Driver
* Purpose: GDALRasterBand code for POSTGIS CHIP/GDAL Driver
* Author: Benjamin Simon, noumayoss@gmail.com
*
******************************************************************************
* Copyright (c) 2005, Benjamin Simon, noumayoss@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*
* Revision 1.1 2005/08/29 bsimon
* New
*
*/
/************************************************************************/
/* ==================================================================== */
/* PGCHIPRasterBand */
/* ==================================================================== */
/************************************************************************/
#include "pgchip.h"
/************************************************************************/
/* PGCHIPRasterBand() */
/************************************************************************/
PGCHIPRasterBand::PGCHIPRasterBand( PGCHIPDataset *poDS, int nBand ){
this->poDS = poDS;
this->nBand = nBand;
if( poDS->nBitDepth == 16 )
eDataType = GDT_UInt16;
else
eDataType = GDT_Byte;
nBlockXSize = poDS->GetRasterXSize();
nBlockYSize = 1;
}
/************************************************************************/
/* IReadBlock() */
/************************************************************************/
CPLErr PGCHIPRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage ){
char szCommand[1024];
PGCHIPDataset *poGDS = (PGCHIPDataset *) poDS;
PGconn *hPGConn;
PGresult *hResult;
int chipDataSize;
int bandSize;
int nPixelSize;
int nPixelOffset;
int nXSize;
int i;
hPGConn = poGDS->hPGConn;
// Must start on the very left
CPLAssert( nBlockXOff == 0 );
if( poGDS->nBitDepth == 16 )
nPixelSize = 2;
else
nPixelSize = 1;
nPixelOffset = poGDS->nBands * nPixelSize;
nXSize = GetXSize();
bandSize = nPixelSize * nXSize;
int sizePalette = 0;
if(poGDS->PGCHIP->future[2] == PGCHIP_COLOR_TYPE_PALETTE){
sizePalette = (int)poGDS->PGCHIP->compression * sizeof(pgchip_color);
}
// Determine size of whole Image Data
chipDataSize = poGDS->PGCHIP->size - sizeof(CHIP) - sizePalette;
/* -------------------------------------------------------------------- */
/* Reading Chip (first pas only) */
/* -------------------------------------------------------------------- */
if(poGDS->PGCHIP->data == NULL){
hResult = PQexec(hPGConn, "BEGIN");
if( hResult && PQresultStatus(hResult) == PGRES_COMMAND_OK )
{
PQclear( hResult );
sprintf( szCommand,"SELECT raster FROM %s",poGDS->pszName);
hResult = PQexec(hPGConn,szCommand);
char *chipData = PQgetvalue(hResult,0,0);
poGDS->PGCHIP->data = (char *) CPLMalloc(chipDataSize);
char *data = chipData + (sizePalette + sizeof(CHIP))*2;
// Reading whole data
for(i=0 ; i<chipDataSize ; i++){
((unsigned char *)poGDS->PGCHIP->data)[i] = parse_hex( &data[i*2]) ;
}
PQclear( hResult );
}
else {
CPLError( CE_Failure, CPLE_AppDefined, "%s", PQerrorMessage(hPGConn) );
PQclear( hResult );
}
hResult = PQexec(hPGConn, "COMMIT");
PQclear( hResult );
}
/* -------------------------------------------------------------------- */
/* Extracting band from pointer */
/* -------------------------------------------------------------------- */
if(poGDS->PGCHIP->data){
if( nPixelSize == 1 ){
char *bufferData = ((char *)poGDS->PGCHIP->data) + (nBlockYOff * poGDS->nBands * bandSize) + ((nBand-1) * nPixelSize);
for(i = 0; i < nXSize; i++ ){
((char *) pImage)[i] = bufferData[i*nPixelOffset];
}
}
else {
GUInt16 *bufferData = (GUInt16 *)(((char *)poGDS->PGCHIP->data) + (nBlockYOff * poGDS->nBands * bandSize) + ((nBand-1) * nPixelSize));
for(i = 0; i < nXSize; i++ ){
((GUInt16 *) pImage)[i] = bufferData[i*poGDS->nBands];
}
}
}
return CE_None;
}
/************************************************************************/
/* GetColorInterpretation() */
/************************************************************************/
GDALColorInterp PGCHIPRasterBand::GetColorInterpretation(){
PGCHIPDataset *poGDS = (PGCHIPDataset *) poDS;
if( poGDS->nColorType == PGCHIP_COLOR_TYPE_GRAY ){
return GCI_GrayIndex;
}
else if( poGDS->nColorType == PGCHIP_COLOR_TYPE_PALETTE ){
return GCI_PaletteIndex;
}
else if(poGDS->nColorType == PGCHIP_COLOR_TYPE_RGB_ALPHA){
if( nBand == 1 )
return GCI_RedBand;
else if( nBand == 2 )
return GCI_GreenBand;
else if( nBand == 3 )
return GCI_BlueBand;
else
return GCI_AlphaBand;
}
return GCI_GrayIndex;
}
/************************************************************************/
/* GetColorTable() */
/************************************************************************/
GDALColorTable *PGCHIPRasterBand::GetColorTable(){
PGCHIPDataset *poGDS = (PGCHIPDataset *) poDS;
if( nBand == 1 )
return poGDS->poColorTable;
else
return NULL;
}
/******************************************************************************
*
* File : pgchiputilities.cpp
* Project: PGCHIP Driver
* Purpose: Utility functions for POSTGIS CHIP/GDAL Driver
* Author: Benjamin Simon, noumayoss@gmail.com
*
******************************************************************************
* Copyright (c) 2005, Benjamin Simon, noumayoss@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*
* Revision 1.1 2005/08/29 bsimon
* New
*
*/
#include "pgchip.h"
/************************************************************************/
/* ==================================================================== */
/* Utility Hex Functions */
/* ==================================================================== */
/************************************************************************/
void deparse_hex(unsigned char str, unsigned char *result){
int input_high;
int input_low;
input_high = (str>>4);
input_low = (str & 0x0F);
switch (input_high)
{
case 0:
result[0] = '0';
break;
case 1:
result[0] = '1';
break;
case 2:
result[0] = '2';
break;
case 3:
result[0] = '3';
break;
case 4:
result[0] = '4';
break;
case 5:
result[0] = '5';
break;
case 6:
result[0] = '6';
break;
case 7:
result[0] = '7';
break;
case 8:
result[0] = '8';
break;
case 9:
result[0] = '9';
break;
case 10:
result[0] = 'A';
break;
case 11:
result[0] = 'B';
break;
case 12:
result[0] = 'C';
break;
case 13:
result[0] = 'D';
break;
case 14:
result[0] = 'E';
break;
case 15:
result[0] = 'F';
break;
}
switch (input_low)
{
case 0:
result[1] = '0';
break;
case 1:
result[1] = '1';
break;
case 2:
result[1] = '2';
break;
case 3:
result[1] = '3';
break;
case 4:
result[1] = '4';
break;
case 5:
result[1] = '5';
break;
case 6:
result[1] = '6';
break;
case 7:
result[1] = '7';
break;
case 8:
result[1] = '8';
break;
case 9:
result[1] = '9';
break;
case 10:
result[1] = 'A';
break;
case 11:
result[1] = 'B';
break;
case 12:
result[1] = 'C';
break;
case 13:
result[1] = 'D';
break;
case 14:
result[1] = 'E';
break;
case 15:
result[1] = 'F';
break;
}
}
//given a string with at least 2 chars in it, convert them to
// a byte value. No error checking done!
unsigned char parse_hex(char *str){
//do this a little brute force to make it faster
unsigned char result_high = 0;
unsigned char result_low = 0;
switch (str[0])
{
case '0' :
result_high = 0;
break;
case '1' :
result_high = 1;
break;
case '2' :
result_high = 2;
break;
case '3' :
result_high = 3;
break;
case '4' :
result_high = 4;
break;
case '5' :
result_high = 5;
break;
case '6' :
result_high = 6;
break;
case '7' :
result_high = 7;
break;
case '8' :
result_high = 8;
break;
case '9' :
result_high = 9;
break;
case 'A' :
result_high = 10;
break;
case 'B' :
result_high = 11;
break;
case 'C' :
result_high = 12;
break;
case 'D' :
result_high = 13;
break;
case 'E' :
result_high = 14;
break;
case 'F' :
result_high = 15;
break;
}
switch (str[1])
{
case '0' :
result_low = 0;
break;
case '1' :
result_low = 1;
break;
case '2' :
result_low = 2;
break;
case '3' :
result_low = 3;
break;
case '4' :
result_low = 4;
break;
case '5' :
result_low = 5;
break;
case '6' :
result_low = 6;
break;
case '7' :
result_low = 7;
break;
case '8' :
result_low = 8;
break;
case '9' :
result_low = 9;
break;
case 'A' :
result_low = 10;
break;
case 'B' :
result_low = 11;
break;
case 'C' :
result_low = 12;
break;
case 'D' :
result_low = 13;
break;
case 'E' :
result_low = 14;
break;
case 'F' :
result_low = 15;
break;
}
return (unsigned char) ((result_high<<4) + result_low);
}
/* Parse an hex string */
void parse_hex_string(unsigned char *strOut,char *strIn,int length){
int i;
for(i=0;i<length;i++){
//printf("Before = %c\n",strIn[i]);
strOut[i] = parse_hex(&strIn[i]);
//printf("After = %c\n",strOut[i]);
}
}
/* Deparse an hex string */
void deparse_hex_string(unsigned char *strOut,char *strIn,int length){
int i;
for(i=0;i<length;i++)
deparse_hex(strIn[i],&strOut[i]);
}
TODO List :
* Test Driver compatibility with various raster formats
* Modify the connection string to cope with the name of the raster column
* Improve the number of color interpretation options
* Manage geoTrasnform
* Deal with more datatypes
* Improve SRID conversion
* Test makefile.vc (Visual C)
OBJ = xpmdataset.obj
GDAL_ROOT = ..\..
EXTRAFLAGS = -I..\mem
!INCLUDE $(GDAL_ROOT)\nmake.opt
default: $(OBJ)
copy *.obj ..\o
clean:
-del *.obj
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment