//--------------------------------------------------------- bool CSG_HTTP::Request(const CSG_String &Request, CSG_Bytes &Answer) { wxInputStream *pStream = _Request(Request); if( !pStream ) { return( false ); } // if( pStream->GetSize() == ((size_t)-1) ) // { // delete(pStream); // // return( false ); // } Answer.Clear(); while( pStream->CanRead() ) { char Byte; pStream->Read(&Byte, sizeof(Byte)); Answer += Byte; } delete(pStream); return( true ); }
//--------------------------------------------------------- bool CSG_CURL::Request(const CSG_String &Request, CSG_Bytes &Answer) { if( !is_Connected() ) { return( false ); } Answer.Clear(); CSG_String URL = m_Server + "/" + Request; CURL_SET_OPT(1, CURLOPT_URL , URL.b_str()); CURL_SET_OPT(1, CURLOPT_FOLLOWLOCATION, 1L); CURL_SET_OPT(1, CURLOPT_WRITEFUNCTION , _Callback_Write_Bytes); CURL_SET_OPT(1, CURLOPT_WRITEDATA , &Answer); return( _Perform() ); }
//--------------------------------------------------------- bool CSG_ODBC_Connection::_Table_Load(CSG_Table &Table, const CSG_String &Select, const CSG_String &Name, bool bLOB) { //----------------------------------------------------- if( !is_Connected() ) { _Error_Message(_TL("no database connection")); return( false ); } //----------------------------------------------------- try { int valInt, iField, nFields; long valLong; float valFloat; double valDouble; std_string valString; otl_long_string valRaw(m_Connection.get_max_long_size()); otl_column_desc *Fields; otl_stream Stream; CSG_Bytes BLOB; Stream.set_all_column_types (otl_all_date2str); Stream.set_lob_stream_mode (bLOB); Stream.open (bLOB ? 1 : m_Size_Buffer, Select, m_Connection); Fields = Stream.describe_select(nFields); if( Fields == NULL || nFields <= 0 ) { _Error_Message(_TL("no fields in selection")); return( false ); } //------------------------------------------------- Table.Destroy(); Table.Set_Name(Name); for(iField=0; iField<nFields; iField++) { if( _Get_Type_From_SQL(Fields[iField].otl_var_dbtype) == SG_DATATYPE_Undefined ) { return( false ); } Table.Add_Field(Fields[iField].name, _Get_Type_From_SQL(Fields[iField].otl_var_dbtype)); } //------------------------------------------------- while( !Stream.eof() && SG_UI_Process_Get_Okay() ) // while not end-of-data { CSG_Table_Record *pRecord = Table.Add_Record(); for(iField=0; iField<nFields; iField++) { switch( Table.Get_Field_Type(iField) ) { case SG_DATATYPE_String: Stream >> valString; if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, CSG_String(valString.c_str())); break; case SG_DATATYPE_Short: case SG_DATATYPE_Int: Stream >> valInt; if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valInt); break; case SG_DATATYPE_DWord: case SG_DATATYPE_Long: Stream >> valLong; if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valLong); break; case SG_DATATYPE_Float: Stream >> valFloat; if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valFloat); break; case SG_DATATYPE_Double: Stream >> valDouble; if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valDouble); break; case SG_DATATYPE_Binary: Stream >> valRaw; if( Stream.is_null() ) pRecord->Set_NoData(iField); else { BLOB.Clear(); for(int i=0; i<valRaw.len(); i++) { BLOB.Add((BYTE)valRaw[i]); } pRecord->Set_Value(iField, BLOB); } break; } } } } //----------------------------------------------------- catch( otl_exception &e ) { _Error_Message(e); return( false ); } return( true ); }
//--------------------------------------------------------- bool CSG_Grid_OGIS_Converter::to_WKBinary(CSG_Bytes &Bytes, class CSG_Grid *pGrid, int SRID) { Bytes.Clear(); //----------------------------------------------------- // Raster System if( pGrid->Get_Projection().Get_EPSG() > 0 ) { SRID = pGrid->Get_Projection().Get_EPSG(); } Bytes += (BYTE )1; // endiannes Bytes += (short )0; // version Bytes += (short )1; // number of bands Bytes += (double)pGrid->Get_Cellsize(); // scaleX Bytes += (double)pGrid->Get_Cellsize(); // scaleY Bytes += (double)pGrid->Get_XMin(true); // ipX Bytes += (double)pGrid->Get_YMax(true); // ipY Bytes += (double)0.0; // skewX Bytes += (double)0.0; // skewY Bytes += (int )SRID; // srid Bytes += (short )pGrid->Get_NX(); // width Bytes += (short )pGrid->Get_NY(); // height //----------------------------------------------------- // Band BYTE Flags; switch( pGrid->Get_Type() ) { case SG_DATATYPE_Bit : Flags = 0; break; // 0: 1-bit boolean // case SG_DATATYPE_ : Flags = 1; break; // 1: 2-bit unsigned integer // case SG_DATATYPE_ : Flags = 2; break; // 2: 4-bit unsigned integer case SG_DATATYPE_Char : Flags = 3; break; // 3: 8-bit signed integer case SG_DATATYPE_Byte : Flags = 4; break; // 4: 8-bit unsigned integer case SG_DATATYPE_Short : Flags = 5; break; // 5: 16-bit signed integer case SG_DATATYPE_Word : Flags = 6; break; // 6: 16-bit unsigned integer case SG_DATATYPE_Int : Flags = 7; break; // 7: 32-bit signed integer case SG_DATATYPE_DWord : Flags = 8; break; // 8: 32-bit unsigned integer case SG_DATATYPE_Float : Flags = 10; break; // 10: 32-bit float case SG_DATATYPE_Double: Flags = 11; break; // 11: 64-bit float default: break; } // Flags |= 0x80; // isOffline: no, never here! Flags |= 0x40; // hasNodataValue // Flags |= 0x20; // isNoDataValue: no, never here! // Flags |= 0x10; // reserved (unused) Bytes += Flags; switch( pGrid->Get_Type() ) { case SG_DATATYPE_Bit : Bytes += (BYTE )0; break; // 0: 1-bit boolean case SG_DATATYPE_Char : Bytes += (char )pGrid->Get_NoData_Value(); break; // 3: 8-bit signed integer case SG_DATATYPE_Byte : Bytes += (BYTE )pGrid->Get_NoData_Value(); break; // 4: 8-bit unsigned integer case SG_DATATYPE_Short : Bytes += (short )pGrid->Get_NoData_Value(); break; // 5: 16-bit signed integer case SG_DATATYPE_Word : Bytes += (WORD )pGrid->Get_NoData_Value(); break; // 6: 16-bit unsigned integer case SG_DATATYPE_Int : Bytes += (int )pGrid->Get_NoData_Value(); break; // 7: 32-bit signed integer case SG_DATATYPE_DWord : Bytes += (DWORD )pGrid->Get_NoData_Value(); break; // 8: 32-bit unsigned integer case SG_DATATYPE_Float : Bytes += (float )pGrid->Get_NoData_Value(); break; // 9: 32-bit float case SG_DATATYPE_Double: Bytes += (double)pGrid->Get_NoData_Value(); break; // 10: 64-bit float default: break; } for(int y=0; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++) { for(int x=0; x<pGrid->Get_NX(); x++) { switch( pGrid->Get_Type() ) { case SG_DATATYPE_Bit : Bytes += (BYTE )pGrid->asDouble(x, y); break; // 0: 1-bit boolean case SG_DATATYPE_Char : Bytes += (char )pGrid->asDouble(x, y); break; // 3: 8-bit signed integer case SG_DATATYPE_Byte : Bytes += (BYTE )pGrid->asDouble(x, y); break; // 4: 8-bit unsigned integer case SG_DATATYPE_Short : Bytes += (short )pGrid->asDouble(x, y); break; // 5: 16-bit signed integer case SG_DATATYPE_Word : Bytes += (WORD )pGrid->asDouble(x, y); break; // 6: 16-bit unsigned integer case SG_DATATYPE_Int : Bytes += (int )pGrid->asDouble(x, y); break; // 7: 32-bit signed integer case SG_DATATYPE_DWord : Bytes += (DWORD )pGrid->asDouble(x, y); break; // 8: 32-bit unsigned integer case SG_DATATYPE_Float : Bytes += (float )pGrid->asDouble(x, y); break; // 9: 32-bit float case SG_DATATYPE_Double: Bytes += (double)pGrid->asDouble(x, y); break; // 10: 64-bit float default: break; } } } return( true ); }