Beispiel #1
0
OGRLayer *OGRDataSource::GetLayerByName( const char *pszName )

{
    int  i;

    /* first a case sensitive check */
    for( i = 0; i < GetLayerCount(); i++ )
    {
        OGRLayer *poLayer = GetLayer(i);

        if( strcmp( pszName, poLayer->GetLayerDefn()->GetName() ) == 0 )
            return poLayer;
    }

    /* then case insensitive */
    for( i = 0; i < GetLayerCount(); i++ )
    {
        OGRLayer *poLayer = GetLayer(i);

        if( EQUAL( pszName, poLayer->GetLayerDefn()->GetName() ) )
            return poLayer;
    }

    return NULL;
}
Beispiel #2
0
void duZorderList::DispatchOnCreate()
{
	duCtrlManager *pCtrlManager = GetCtrlManager(m_pRoot->GetHwnd());
	if (pCtrlManager == NULL)
		return;

	duPlugin *pPlugin = NULL;
	int i, j;
	int nLevelCount = GetLayerCount();
	for (i = 0;i < nLevelCount; i++)
	{
		int nCtrlCount = GetLayerChildCount(i);
		for (j = nCtrlCount - 1;j >= 0; j--)
		{
			pPlugin = GetPlugin(i, j);
			if (pPlugin == NULL || !Plugin_IsValid(pPlugin))
				continue;

			pCtrlManager->AddName(pPlugin);
		}
	}

	for (i = 0;i < nLevelCount; i++)
	{
		int nCtrlCount = GetLayerChildCount(i);
		for (j = nCtrlCount - 1;j >= 0; j--)
		{
			pPlugin = GetPlugin(i, j);
			if (pPlugin == NULL || !Plugin_IsValid(pPlugin))
				continue;

			pPlugin->OnCreate();
		}
	}
}
Beispiel #3
0
BOOL duZorderList::Delete(duPlugin *pPlugin)
{
	if (pPlugin == NULL)
		return FALSE;

	int nLayerCount = GetLayerCount();
	int i;
	UINT uZorder = pPlugin->GetZorder();
	duPlugin *pTempPlugin = NULL;
	for (i = 0;i < nLayerCount; i++)
	{
		ZorderItem *pZorderItem = m_dqZorderList[i];
		if (pZorderItem == NULL)
			return FALSE;

		if (pZorderItem->uZorder != uZorder)
			continue;

		vector<duPlugin *>::iterator iterPlugin = pZorderItem->vtPlugin.begin();
		for ( ;iterPlugin != pZorderItem->vtPlugin.end(); iterPlugin++)
		{
			pTempPlugin = *iterPlugin;
			if (pTempPlugin != pPlugin)
				continue;
			
			pZorderItem->vtPlugin.erase(iterPlugin);
			if (pZorderItem->vtPlugin.empty())
				DeleteZorderItem(pZorderItem);
			return TRUE;
		}
	}
	
	return FALSE;
}
OGRLayer *OGRTABDataSource::GetLayer( int iLayer )

{
    if( iLayer < 0 || iLayer >= GetLayerCount() )
        return nullptr;
    else
        return m_papoLayers[iLayer];
}
Beispiel #5
0
OGRLayer *OGRGeoconceptDataSource::GetLayer( int iLayer )

{
    if( iLayer < 0 || iLayer >= GetLayerCount() )
      return nullptr;

    OGRLayer *poFile = _papoLayers[iLayer];
    return poFile;
}
Beispiel #6
0
CPLErr GNMFileNetwork::DeleteNetworkLayers()
{
    while(GetLayerCount() > 0)
    {
        OGRErr eErr = DeleteLayer(0);
        if(eErr != OGRERR_NONE)
            return CE_Failure;
    }
    return CE_None;
}
OGRLayer *OGRGeoconceptDataSource::GetLayer( int iLayer )

{
    OGRLayer *poFile;
    if( iLayer < 0 || iLayer >= GetLayerCount() )
        poFile= NULL;
    else
        poFile= _papoLayers[iLayer];
    return poFile;
}
Beispiel #8
0
int main()
{
	
	FILE* fp = nullptr;
	fopen_s(&fp, "import.psd", "rb");

	if (fp == nullptr) return 0;

	std::vector<uint8_t> data;
	fseek(fp, 0, SEEK_END);
	auto length = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	data.resize(length);
	fread(data.data(), 1, length, fp);
	fclose(fp);

	auto doc = PSDParser::Document::Create(data.data(), data.size());

	for (auto i = 0; i < doc->GetLayerCount(); i++)
	{
		auto layer = doc->GetLayer(i);

		auto name = layer->GetName();
		auto rect = layer->GetRect();
		
		std::vector<uint8_t> bmp;
		auto height = rect.Bottom - rect.Top;
		auto width = rect.Right - rect.Left;
		bmp.resize(width * height * 4);

		for (int32_t y = 0; y < height; y++)
		{
			for (int32_t x = 0; x < width; x++)
			{
				auto p = (uint8_t*) layer->GetData();

				bmp[(x + y * width) * 4 + 0] = p[x * 4 + width * y + 0];
				bmp[(x + y * width) * 4 + 1] = p[x * 4 + width * y + 1];
				bmp[(x + y * width) * 4 + 2] = p[x * 4 + width * y + 2];
				bmp[(x + y * width) * 4 + 3] = p[x * 4 + width * y + 3];

			}
		}

		

		BitmapWriter::Write("test.bmp", (uint32_t*)(bmp.data()), width, height);

		//break;
	}

	return 0;
}
OGRLayer *OGRShapeDataSource::GetLayer( int iLayer )

{
    /* To ensure that existing layers are created */
    GetLayerCount();

    if( iLayer < 0 || iLayer >= nLayers )
        return NULL;
    else
        return papoLayers[iLayer];
}
///////////////////////////////////////////////////////////////////////////
/// Perform the actual activation of the neural net: for a given set of
/// inputs, one for each unit in the input layer, calculate what the
/// activations would be in the output layer.
///
/// \param [in] VectorXd inputActivations - vector of input activations.
///
/// \return VectorXd - the list of output unit activations. the
///                     size of this vector == outputUnitCount
VectorXd LayeredFeedForwardNeuralNet::Evaluate(const VectorXd& inputActivations) const
{
    VectorXd layerInput = inputActivations;
    // iteratively activate the layers (not the dummy input layer as this is inputActivations).
    for (size_t idx = 1; idx < GetLayerCount(); idx++)
    {
        layerInput = FireSingleLayer(layerInput, idx);
    }
    // (last layer + 1) "input" are the output activations
    return layerInput;
}
Beispiel #11
0
int duZorderList::GetLayerChildCount(int nLayer)
{
	int nLayerCount = GetLayerCount();
	if (nLayer < 0 || nLayer >= nLayerCount)
		return 0;
	
	ZorderItem *pZorderItem = m_dqZorderList[nLayer];
	if (pZorderItem == NULL)
		return 0;

	return (int)pZorderItem->vtPlugin.size();
}
Beispiel #12
0
UINT duZorderList::GetLayerZorder(int nLayer)
{
	int nLayerCount = GetLayerCount();
	if (nLayer < 0 || nLayer >= nLayerCount)
		return 0;
	
	ZorderItem *pZorderItem = m_dqZorderList[nLayer];
	if (pZorderItem == NULL)
		return 0;

	return pZorderItem->uZorder;
}
void LayeredFeedForwardNeuralNet::SetLayerInputWeights(const MatrixXd& layerWeights, long layerIndex)
{
    if (layerIndex < 1)
    {
        throw NeuralNetTopologyMismatch("input weights for dummy input layer 0 do not exist.");
    }
    if (layerIndex >= GetLayerCount())
    {
        throw NeuralNetTopologyMismatch("neural unit layer specified does not exist in this neural network topology.");
    }
    m_neuralNetLayerWeights[layerIndex - 1] = layerWeights;
}
// Validate the print data
bool PrintDataDirectory::Validate()
{
    int numLayers = GetLayerCount();

    if (numLayers < 1)
        return false;  // a valid print must contain at least one slice image
    
    // check that the slice images are named/numbered as expected
    for(int i = 1; i <= numLayers; i++)
        if (!std::ifstream(GetLayerFileName(i).c_str())) 
            return false;
    
    return true;
}
// note index is 0 based: 0 -> n-1 (where n = number of network layers). layerIndex=0 is invalid (as dummy layer)
const MatrixXd& LayeredFeedForwardNeuralNet::GetLayerInputWeights(long layerIndex) const
{
    if (layerIndex < 1)
    {
        throw NeuralNetTopologyMismatch("input weights for dummy input layer 0 do not exist.");
    }
    if (layerIndex >= GetLayerCount())
    {
        throw NeuralNetTopologyMismatch("neural unit layer specified does not exist in this neural network topology.");
    }
    
    // get layer input weights
    return m_neuralNetLayerWeights[layerIndex - 1];
}
Beispiel #16
0
duPlugin *duZorderList::GetPlugin(int nLayer, int nIndex)
{
	int nLayerCount = GetLayerCount();
	if (nLayer < 0 || nLayer >= nLayerCount)
		return NULL;
	
	ZorderItem *pZorderItem = m_dqZorderList[nLayer];
	if (pZorderItem == NULL)
		return NULL;
		
	if (nIndex < 0 || nIndex >= (int)pZorderItem->vtPlugin.size())
		return NULL;
	
	return pZorderItem->vtPlugin[nIndex];
}
Beispiel #17
0
bool wxGISMapView::CanRotate(void)
{
    for(size_t i = 0; i < GetLayerCount(); ++i)
    {
        wxGISLayer* const pLayer = GetLayer(i);
        if(pLayer)
        {
            wxGISDataset* const pDSet = pLayer->GetDataset();
            if(pDSet && pDSet->IsCaching())
            {
               return false;
            }
        }
    }
    return true;
}
Beispiel #18
0
OGRLayer *GNMDatabaseNetwork::ICreateLayer(const char *pszName,
                                CPL_UNUSED OGRSpatialReference *poSpatialRef,
                                OGRwkbGeometryType eGType, char **papszOptions)
{
    //check if layer with such name exist
    for(int i = 0; i < GetLayerCount(); ++i)
    {
        OGRLayer* pLayer = GetLayer(i);
        if(NULL == pLayer)
            continue;
        if(EQUAL(pLayer->GetName(), pszName))
        {
            CPLError( CE_Failure, CPLE_IllegalArg,
                      "The network layer '%s' already exist.", pszName );
            return NULL;
        }
    }

    OGRSpatialReference oSpaRef(m_soSRS);

    OGRLayer *poLayer = m_poDS->CreateLayer( pszName, &oSpaRef, eGType, papszOptions );
    if( poLayer == NULL )
    {
        CPLError( CE_Failure, CPLE_FileIO, "Layer creation failed." );
        return NULL;
    }

    OGRFieldDefn oField( GNM_SYSFIELD_GFID, GNMGFIDInt );
    if( poLayer->CreateField( &oField ) != OGRERR_NONE )
    {
        CPLError( CE_Failure, CPLE_FileIO, "Creating global identificator field failed." );
        return NULL;
    }


    OGRFieldDefn oFieldBlock(GNM_SYSFIELD_BLOCKED, OFTInteger);
    if( poLayer->CreateField( &oFieldBlock ) != OGRERR_NONE )
    {
        CPLError( CE_Failure, CPLE_FileIO, "Creating is blocking field failed." );
        return NULL;
    }

    GNMGenericLayer* pGNMLayer = new GNMGenericLayer(poLayer, this);
    m_apoLayers.push_back(pGNMLayer);
    return pGNMLayer;
}
Beispiel #19
0
int duZorderList::GetNextLayer(UINT uZorder)
{
	int nLayerCount = GetLayerCount();
	ZorderItem *pZorderItem = NULL;
	int i;
	for (i = 0;i < nLayerCount; i++)
	{
		pZorderItem = m_dqZorderList[i];
		if (pZorderItem == NULL)
			return FALSE;
		
		if (pZorderItem->uZorder > uZorder)		
			return i;
	}
	
	return -1;
}
Beispiel #20
0
void duZorderList::Destroy()
{
	int i;
	int nLayerCount = GetLayerCount();
	ZorderItem *pZorderItem = NULL;
	for (i = 0;i < nLayerCount; i++)
	{
		pZorderItem = m_dqZorderList[i];
		if (pZorderItem)
		{
			pZorderItem->vtPlugin.clear();
			delete pZorderItem;
			pZorderItem = NULL;
		}
	}
	m_dqZorderList.clear();
	m_pRoot = NULL;
}
Beispiel #21
0
OGRErr OGRDataSource::SyncToDisk()

{
    int i;
    OGRErr eErr;

    for( i = 0; i < GetLayerCount(); i++ )
    {
        OGRLayer *poLayer = GetLayer(i);

        if( poLayer )
        {
            eErr = poLayer->SyncToDisk();
            if( eErr != OGRERR_NONE )
                return eErr;
        }
    }

    return OGRERR_NONE;
}
Beispiel #22
0
BOOL duZorderList::Add(duPlugin *pPlugin)
{
	if (pPlugin == NULL)
		return FALSE;

	int nLayerCount = GetLayerCount();
	ZorderItem *pZorderItem = NULL;
	int i;
	UINT uZorder = pPlugin->GetZorder();
	for (i = 0;i < nLayerCount; i++)
	{
		pZorderItem = m_dqZorderList[i];
		if (pZorderItem == NULL)
			return FALSE;
		
		if (pZorderItem->uZorder == uZorder)
		{
			pZorderItem->vtPlugin.push_back(pPlugin);
			return TRUE;
		}
	}
	
	ZorderItem *pNewZorderItem = new ZorderItem;
	pNewZorderItem->uZorder = uZorder;
	pNewZorderItem->vtPlugin.clear();
	pNewZorderItem->vtPlugin.push_back(pPlugin);

	for (i = 0;i < nLayerCount; i++)
	{
		pZorderItem = m_dqZorderList[i];
		if (pZorderItem == NULL)
			return FALSE;
		
		if (pZorderItem->uZorder < uZorder)
			break;
	}
	
	deque<ZorderItem *>::iterator iterInsert = m_dqZorderList.begin() + i;
	m_dqZorderList.insert(iterInsert, pNewZorderItem);
	return TRUE;
}
Beispiel #23
0
OGRLayer *OGROCIDataSource::GetLayerByName( const char *pszNameIn )

{
    OGROCILayer *poLayer = NULL;
    int  i, count;

    if ( !pszNameIn )
        return NULL;

    count = GetLayerCount();

    /* first a case sensitive check */
    for( i = 0; i < count; i++ )
    {
        poLayer = papoLayers[i];

        if( strcmp( pszNameIn, poLayer->GetName() ) == 0 )
        {
            return poLayer;
        }
    }

    char *pszSafeLayerName = CPLStrdup( pszNameIn );
    poSession->CleanName( pszSafeLayerName );

    /* then case insensitive and laundered */
    for( i = 0; i < count; i++ )
    {
        poLayer = papoLayers[i];

        if( EQUAL( pszSafeLayerName, poLayer->GetName() ) )
        {
            break;
        }
    }

    CPLFree( pszSafeLayerName );

    return i < count ? poLayer : NULL;
}
Beispiel #24
0
OGRErr OGRDataSource::ProcessSQLDropIndex( const char *pszSQLCommand )

{
    char **papszTokens = CSLTokenizeString( pszSQLCommand );

/* -------------------------------------------------------------------- */
/*      Do some general syntax checking.                                */
/* -------------------------------------------------------------------- */
    if( (CSLCount(papszTokens) != 4 && CSLCount(papszTokens) != 6)
        || !EQUAL(papszTokens[0],"DROP")
        || !EQUAL(papszTokens[1],"INDEX")
        || !EQUAL(papszTokens[2],"ON") 
        || (CSLCount(papszTokens) == 6 && !EQUAL(papszTokens[4],"USING")) )
    {
        CSLDestroy( papszTokens );
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Syntax error in DROP INDEX command.\n"
                  "Was '%s'\n"
                  "Should be of form 'DROP INDEX ON <table> [USING <field>]'",
                  pszSQLCommand );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Find the named layer.                                           */
/* -------------------------------------------------------------------- */
    int  i;
    OGRLayer *poLayer=NULL;

    for( i = 0; i < GetLayerCount(); i++ )
    {
        poLayer = GetLayer(i);
        
        if( EQUAL(poLayer->GetLayerDefn()->GetName(),papszTokens[3]) )
            break;
    }

    if( i >= GetLayerCount() )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "CREATE INDEX ON failed, no such layer as `%s'.",
                  papszTokens[3] );
        CSLDestroy( papszTokens );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Does this layer even support attribute indexes?                 */
/* -------------------------------------------------------------------- */
    if( poLayer->GetIndex() == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Indexes not supported by this driver." );
        CSLDestroy( papszTokens );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      If we weren't given a field name, drop all indexes.             */
/* -------------------------------------------------------------------- */
    OGRErr eErr;

    if( CSLCount(papszTokens) == 4 )
    {
        for( i = 0; i < poLayer->GetLayerDefn()->GetFieldCount(); i++ )
        {
            OGRAttrIndex *poAttrIndex;

            poAttrIndex = poLayer->GetIndex()->GetFieldIndex(i);
            if( poAttrIndex != NULL )
            {
                eErr = poLayer->GetIndex()->DropIndex( i );
                if( eErr != OGRERR_NONE )
                    return eErr;
            }
        }

        CSLDestroy(papszTokens);
        return OGRERR_NONE;
    }

/* -------------------------------------------------------------------- */
/*      Find the named field.                                           */
/* -------------------------------------------------------------------- */
    for( i = 0; i < poLayer->GetLayerDefn()->GetFieldCount(); i++ )
    {
        if( EQUAL(papszTokens[5],
                  poLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()) )
            break;
    }

    CSLDestroy( papszTokens );

    if( i >= poLayer->GetLayerDefn()->GetFieldCount() )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "`%s' failed, field not found.",
                  pszSQLCommand );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Attempt to drop the index.                                      */
/* -------------------------------------------------------------------- */
    eErr = poLayer->GetIndex()->DropIndex( i );

    return eErr;
}
Beispiel #25
0
int CPMCodeDecode::DecodePMCode () {

	CQRCodeDecode	*pQRCodeDecode						= NULL;
	UINT			uiDecodeDataSize;
	char			*szQRCodeImage = NULL;
	int				iQRCodeImageSize;
	int				iQRCodeLengthSize;
	long			lColorCode;
	int				iRet;
	CReedSolomon	cReedSolomon;
	BOOL			bRet;
	int				iDataSize;
	int				iBlockSize;
	int				iCorrectPos = 0;
	int				iCorrectDataSize;
	int				iRSBlock1;
	int				iRSBlock2;
	BYTE			szCorrectBuf [256];
	BYTE			szWork [256];
	char			*szDecodeData = NULL;

	if (m_szDecodeData != NULL) {
		free (m_szDecodeData);
		m_szDecodeData = NULL;
		m_uiDecodeDataSize = 0;
	}

	if (m_szBaseImage == NULL || m_uiBaseImageSize == 0) {
		return RESULT_ERROR_IMAGEFILE_READ_YET;
	}

	m_iVersion		= SYM2VER(m_Width);
	m_iSymbolSize	= m_Width;

	iRet = GetColorCode (g_PMCodeColor, m_szBaseImage, m_uiBaseImageSize, m_iSymbolSize, m_iVersion);
	if(RESULT_OK != iRet){
		return iRet;
	}

	m_iLayer = GetLayerCount (m_szBaseImage, m_uiBaseImageSize, m_iSymbolSize);

	if(0 == m_iLayer){
		return RESULT_ERROR_ANALYSIS_LAYER;
	}

	if (m_iVersion < 3) {
		MakeColorTable (3, m_iLayer);
	} else {
		MakeColorTable (6, m_iLayer);
	}

	iQRCodeLengthSize	= CalcPitch (BIT_COUNT_8, m_iSymbolSize);
	iQRCodeImageSize	= iQRCodeLengthSize * m_iSymbolSize;

	if (szQRCodeImage != NULL){
		free (szQRCodeImage);
		szQRCodeImage = NULL;
	}
	szQRCodeImage = (char *)malloc (iQRCodeImageSize + 1);
	if (szQRCodeImage == NULL) {
		return RESULT_ERROR_SECURE_MEMORY;
	}
	memset (szQRCodeImage, '\0', iQRCodeImageSize + 1);				
	pQRCodeDecode = new CQRCodeDecode;

	m_szDecodeData = (char *)realloc (m_szDecodeData, (QR_VersonInfo[m_iVersion].ncAllCodeWord * m_iLayer) + 1);
	memset (m_szDecodeData, '\0', (QR_VersonInfo[m_iVersion].ncAllCodeWord * m_iLayer) + 1);

	for (int i = 0; i < m_iLayer; i ++ ) {
#if PM_CODE_COLOR
		if (g_ColorCodeSetting == 0) {
			lColorCode = g_ColorCodeSettingDefinition [i];	
		} else {
			if (m_iLayer == 3) {
				lColorCode = g_ColorCodeSetting3 [i];	
			} else if (m_iLayer >9) {
				lColorCode = g_ColorCodeSetting10to24 [i];	
			} else {
				lColorCode = g_ColorCodeSetting4to9 [i];	
			}
		}
#else
		lColorCode = g_PMCodeColor [i];
#endif
		if (lColorCode == 0) {
			delete pQRCodeDecode;
			pQRCodeDecode = NULL;
			free (szQRCodeImage);
			szQRCodeImage = NULL;
			return RESULT_ERROR_NON_SUPORT_COLOR;
		}
		iRet = PMCodeToQRCode (m_szBaseImage, m_uiBaseImageSize, lColorCode
										, szQRCodeImage, iQRCodeImageSize, m_iSymbolSize);
		if(RESULT_OK != iRet){
			free (szQRCodeImage);
			szQRCodeImage = NULL;
			return RESLUT_ERROR_LAYER_RESOLUTION;
		}

		iRet = pQRCodeDecode->SetQRCodeImage (szQRCodeImage, iQRCodeImageSize, m_iVersion);
		if(RESULT_OK != iRet){
			free (szQRCodeImage);
			szQRCodeImage = NULL;
			delete pQRCodeDecode;
			pQRCodeDecode = NULL;
			return RESULT_ERROR_SECURE_MEMORY;
		}

		uiDecodeDataSize = pQRCodeDecode->DecodeQRCodeImage ();
		if(0 == uiDecodeDataSize){
			free (szQRCodeImage);
			szQRCodeImage = NULL;
			delete pQRCodeDecode;
			pQRCodeDecode = NULL;
			return RESULT_ERROR_ANALYSIS_QR_IMAGE;
		}

		m_iMaskPattern [i] = pQRCodeDecode->GetMaskNumber ();
		iRet = pQRCodeDecode->GetQRCodeStatus (&m_iRSLevel);
		if(RESULT_OK != iRet){
			free (szQRCodeImage);
			szQRCodeImage = NULL;
			delete pQRCodeDecode;
			pQRCodeDecode = NULL;
			return RESULT_ERROR_ANALYSIS_QR_STATUS;
		}
		if (szDecodeData != NULL) {
			free (szDecodeData);
			szDecodeData = NULL;
		}
		szDecodeData = (char *)malloc (uiDecodeDataSize + 1);
		memset (szDecodeData, '\0', uiDecodeDataSize + 1);
		iRet = pQRCodeDecode->GetDecodeData (szDecodeData, uiDecodeDataSize);

		if(RESULT_OK != iRet){
			free (szQRCodeImage);
			szQRCodeImage = NULL;
			delete pQRCodeDecode;
			pQRCodeDecode = NULL;
			return RESULT_ERROR_ANALYSIS_QR_DECODE;
		}

		iDataSize = uiDecodeDataSize;
		iCorrectPos = 0;
		iRSBlock1 = QR_VersonInfo[m_iVersion].RS_BlockInfo1 [m_iRSLevel].ncRSBlock;
		iRSBlock2 = QR_VersonInfo[m_iVersion].RS_BlockInfo2 [m_iRSLevel].ncRSBlock;

		for (int j = 0; j < (iRSBlock1 + iRSBlock2); j ++) {
			if (QR_VersonInfo[m_iVersion].RS_BlockInfo1 [m_iRSLevel].ncRSBlock > j){
				iBlockSize = QR_VersonInfo[m_iVersion].RS_BlockInfo1 [m_iRSLevel].ncAllCodeWord;
				cReedSolomon.SetCorrectCodeSize (iBlockSize	- QR_VersonInfo[m_iVersion].RS_BlockInfo1 [m_iRSLevel].ncDataCodeWord);
			} else {
				iBlockSize = QR_VersonInfo[m_iVersion].RS_BlockInfo2 [m_iRSLevel].ncAllCodeWord;
				cReedSolomon.SetCorrectCodeSize (iBlockSize - QR_VersonInfo[m_iVersion].RS_BlockInfo2 [m_iRSLevel].ncDataCodeWord);
			}
			memset (szWork, NULL, sizeof (szWork));
			memset (szCorrectBuf, NULL, sizeof (szCorrectBuf));

			if (iDataSize < iBlockSize) {
				memcpy (szWork, &szDecodeData [iCorrectPos], iDataSize);
				bRet = cReedSolomon.Decode (szWork, iBlockSize, szCorrectBuf, &iCorrectDataSize);
				if(bRet != TRUE){
					free (szQRCodeImage);
					szQRCodeImage = NULL;
					delete pQRCodeDecode;
					pQRCodeDecode = NULL;
					free (szDecodeData);
					szDecodeData = NULL;
					return RESULT_ERROR_ANALYSIS_QR_BIG_BLOCK_DECODE;
				}
			} else {
				memcpy (szWork, &szDecodeData [iCorrectPos], iBlockSize);
				bRet = cReedSolomon.Decode (szWork, iBlockSize, szCorrectBuf, &iCorrectDataSize);
				if(bRet != TRUE){
					free (szQRCodeImage);
					szQRCodeImage = NULL;
					delete pQRCodeDecode;
					pQRCodeDecode = NULL;
					free (szDecodeData);
					szDecodeData = NULL;
					return RESULT_ERROR_ANALYSIS_QR_SMALL_BLOCK_DECODE;
				}
			}
			memcpy (&m_szDecodeData [m_uiDecodeDataSize], szCorrectBuf, iCorrectDataSize);
			m_uiDecodeDataSize += iCorrectDataSize;
			iCorrectPos += iBlockSize;
			iDataSize -= iBlockSize;
		}
		if (szDecodeData != NULL) {
			free (szDecodeData);
			szDecodeData = NULL;
		}
	}
	delete pQRCodeDecode;
	pQRCodeDecode = NULL;

	if (szQRCodeImage != NULL) {
		free (szQRCodeImage);
		szQRCodeImage = NULL;
	}
	return m_uiDecodeDataSize;
}
Beispiel #26
0
OGRLayer *
OGRKMLDataSource::ICreateLayer( const char * pszLayerName,
                                OGRSpatialReference *poSRS,
                                OGRwkbGeometryType eType,
                                CPL_UNUSED char ** papszOptions )
{
    CPLAssert( NULL != pszLayerName);

/* -------------------------------------------------------------------- */
/*      Verify we are in update mode.                                   */
/* -------------------------------------------------------------------- */
    if( fpOutput_ == NULL )
    {
        CPLError( CE_Failure, CPLE_NoWriteAccess,
                  "Data source %s opened for read access.\n"
                  "New layer %s cannot be created.\n",
                  pszName_, pszLayerName );

        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Close the previous layer (if there is one open)                 */
/* -------------------------------------------------------------------- */
    if (GetLayerCount() > 0)
    {
        if( nLayers_ == 1 && papoLayers_[0]->nWroteFeatureCount_ == 0 )
        {
            VSIFPrintfL( fpOutput_, "<Folder><name>%s</name>\n", papoLayers_[0]->GetName() );
        }

        VSIFPrintfL( fpOutput_, "</Folder>\n");
        ((OGRKMLLayer*)GetLayer(GetLayerCount()-1))->SetClosedForWriting();
    }
    
/* -------------------------------------------------------------------- */
/*      Ensure name is safe as an element name.                         */
/* -------------------------------------------------------------------- */
    char *pszCleanLayerName = CPLStrdup( pszLayerName );

    CPLCleanXMLElementName( pszCleanLayerName );
    if( strcmp(pszCleanLayerName, pszLayerName) != 0 )
    {
        CPLError( CE_Warning, CPLE_AppDefined, 
                  "Layer name '%s' adjusted to '%s' for XML validity.",
                  pszLayerName, pszCleanLayerName );
    }
    
    if (GetLayerCount() > 0)
    {
        VSIFPrintfL( fpOutput_, "<Folder><name>%s</name>\n", pszCleanLayerName);
    }
    
/* -------------------------------------------------------------------- */
/*      Create the layer object.                                        */
/* -------------------------------------------------------------------- */
    OGRKMLLayer *poLayer;
    poLayer = new OGRKMLLayer( pszCleanLayerName, poSRS, TRUE, eType, this );
    
    CPLFree( pszCleanLayerName );

/* -------------------------------------------------------------------- */
/*      Add layer to data source layer list.                            */
/* -------------------------------------------------------------------- */
    papoLayers_ = (OGRKMLLayer **)
        CPLRealloc( papoLayers_,  sizeof(OGRKMLLayer *) * (nLayers_+1) );
    
    papoLayers_[nLayers_++] = poLayer;

    return poLayer;
}
Beispiel #27
0
OGRLayer *OGRPLScenesDataV1Dataset::GetLayer(int idx)
{
    if( idx < 0 || idx >= GetLayerCount() )
        return nullptr;
    return m_papoLayers[idx];
}
OGRLayer *
OGRShapeDataSource::ICreateLayer( const char * pszLayerName,
                                 OGRSpatialReference *poSRS,
                                 OGRwkbGeometryType eType,
                                 char ** papszOptions )

{
    SHPHandle   hSHP;
    DBFHandle   hDBF;
    int         nShapeType;

    /* To ensure that existing layers are created */
    GetLayerCount();

/* -------------------------------------------------------------------- */
/*      Check that the layer doesn't already exist.                     */
/* -------------------------------------------------------------------- */
    if (GetLayerByName(pszLayerName) != NULL)
    {
        CPLError( CE_Failure, CPLE_AppDefined, "Layer '%s' already exists",
                    pszLayerName);
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Verify we are in update mode.                                   */
/* -------------------------------------------------------------------- */
    if( !bDSUpdate )
    {
        CPLError( CE_Failure, CPLE_NoWriteAccess,
                  "Data source %s opened read-only.\n"
                  "New layer %s cannot be created.\n",
                  pszName, pszLayerName );

        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Figure out what type of layer we need.                          */
/* -------------------------------------------------------------------- */
    if( eType == wkbUnknown || eType == wkbLineString )
        nShapeType = SHPT_ARC;
    else if( eType == wkbPoint )
        nShapeType = SHPT_POINT;
    else if( eType == wkbPolygon )
        nShapeType = SHPT_POLYGON;
    else if( eType == wkbMultiPoint )
        nShapeType = SHPT_MULTIPOINT;
    else if( eType == wkbPoint25D )
        nShapeType = SHPT_POINTZ;
    else if( eType == wkbLineString25D )
        nShapeType = SHPT_ARCZ;
    else if( eType == wkbMultiLineString )
        nShapeType = SHPT_ARC;
    else if( eType == wkbMultiLineString25D )
        nShapeType = SHPT_ARCZ;
    else if( eType == wkbPolygon25D )
        nShapeType = SHPT_POLYGONZ;
    else if( eType == wkbMultiPolygon )
        nShapeType = SHPT_POLYGON;
    else if( eType == wkbMultiPolygon25D )
        nShapeType = SHPT_POLYGONZ;
    else if( eType == wkbMultiPoint25D )
        nShapeType = SHPT_MULTIPOINTZ;
    else if( eType == wkbNone )
        nShapeType = SHPT_NULL;
    else
        nShapeType = -1;

/* -------------------------------------------------------------------- */
/*      Has the application overridden this with a special creation     */
/*      option?                                                         */
/* -------------------------------------------------------------------- */
    const char *pszOverride = CSLFetchNameValue( papszOptions, "SHPT" );

    if( pszOverride == NULL )
        /* ignore */;
    else if( EQUAL(pszOverride,"POINT") )
    {
        nShapeType = SHPT_POINT;
        eType = wkbPoint;
    }
    else if( EQUAL(pszOverride,"ARC") )
    {
        nShapeType = SHPT_ARC;
        eType = wkbLineString;
    }
    else if( EQUAL(pszOverride,"POLYGON") )
    {
        nShapeType = SHPT_POLYGON;
        eType = wkbPolygon;
    }
    else if( EQUAL(pszOverride,"MULTIPOINT") )
    {
        nShapeType = SHPT_MULTIPOINT;
        eType = wkbMultiPoint;
    }
    else if( EQUAL(pszOverride,"POINTZ") )
    {
        nShapeType = SHPT_POINTZ;
        eType = wkbPoint25D;
    }
    else if( EQUAL(pszOverride,"ARCZ") )
    {
        nShapeType = SHPT_ARCZ;
        eType = wkbLineString25D;
    }
    else if( EQUAL(pszOverride,"POLYGONZ") )
    {
        nShapeType = SHPT_POLYGONZ;
        eType = wkbPolygon25D;
    }
    else if( EQUAL(pszOverride,"MULTIPOINTZ") )
    {
        nShapeType = SHPT_MULTIPOINTZ;
        eType = wkbMultiPoint25D;
    }
    else if( EQUAL(pszOverride,"NONE") || EQUAL(pszOverride,"NULL") )
    {
        nShapeType = SHPT_NULL;
        eType = wkbNone;
    }
    else
    {
        CPLError( CE_Failure, CPLE_NotSupported,
                  "Unknown SHPT value of `%s' passed to Shapefile layer\n"
                  "creation.  Creation aborted.\n",
                  pszOverride );

        return NULL;
    }

    if( nShapeType == -1 )
    {
        CPLError( CE_Failure, CPLE_NotSupported,
                  "Geometry type of `%s' not supported in shapefiles.\n"
                  "Type can be overridden with a layer creation option\n"
                  "of SHPT=POINT/ARC/POLYGON/MULTIPOINT/POINTZ/ARCZ/POLYGONZ/MULTIPOINTZ.\n",
                  OGRGeometryTypeToName(eType) );
        return NULL;
    }
    
/* -------------------------------------------------------------------- */
/*      What filename do we use, excluding the extension?               */
/* -------------------------------------------------------------------- */
    char *pszFilenameWithoutExt;

    if(  bSingleFileDataSource && nLayers == 0 )
    {
        char *pszPath = CPLStrdup(CPLGetPath(pszName));
        char *pszFBasename = CPLStrdup(CPLGetBasename(pszName));

        pszFilenameWithoutExt = CPLStrdup(CPLFormFilename(pszPath, pszFBasename, NULL));

        CPLFree( pszFBasename );
        CPLFree( pszPath );
    }
    else if(  bSingleFileDataSource )
    {
        /* This is a very weird use case : the user creates/open a datasource */
        /* made of a single shapefile 'foo.shp' and wants to add a new layer */
        /* to it, 'bar'. So we create a new shapefile 'bar.shp' in the same */
        /* directory as 'foo.shp' */
        /* So technically, we will not be any longer a single file */
        /* datasource ... Ahem ahem */
        char *pszPath = CPLStrdup(CPLGetPath(pszName));
        pszFilenameWithoutExt = CPLStrdup(CPLFormFilename(pszPath,pszLayerName,NULL));
        CPLFree( pszPath );
    }
    else
        pszFilenameWithoutExt = CPLStrdup(CPLFormFilename(pszName,pszLayerName,NULL));

/* -------------------------------------------------------------------- */
/*      Create the shapefile.                                           */
/* -------------------------------------------------------------------- */
    char        *pszFilename;

    int b2GBLimit = CSLTestBoolean(CSLFetchNameValueDef( papszOptions, "2GB_LIMIT", "FALSE" ));

    if( nShapeType != SHPT_NULL )
    {
        pszFilename = CPLStrdup(CPLFormFilename( NULL, pszFilenameWithoutExt, "shp" ));

        hSHP = SHPCreateLL( pszFilename, nShapeType, (SAHooks*) VSI_SHP_GetHook(b2GBLimit) );
        
        if( hSHP == NULL )
        {
            CPLError( CE_Failure, CPLE_OpenFailed,
                      "Failed to open Shapefile `%s'.\n",
                      pszFilename );
            CPLFree( pszFilename );
            CPLFree( pszFilenameWithoutExt );
            return NULL;
        }
        
        SHPSetFastModeReadObject( hSHP, TRUE );

        CPLFree( pszFilename );
    }
    else
        hSHP = NULL;

/* -------------------------------------------------------------------- */
/*      Has a specific LDID been specified by the caller?               */
/* -------------------------------------------------------------------- */
    const char *pszLDID = CSLFetchNameValue( papszOptions, "ENCODING" );

/* -------------------------------------------------------------------- */
/*      Create a DBF file.                                              */
/* -------------------------------------------------------------------- */
    pszFilename = CPLStrdup(CPLFormFilename( NULL, pszFilenameWithoutExt, "dbf" ));

    if( pszLDID != NULL )
        hDBF = DBFCreateLL( pszFilename, pszLDID, (SAHooks*) VSI_SHP_GetHook(b2GBLimit) );
    else
        hDBF = DBFCreateLL( pszFilename, "LDID/87",(SAHooks*) VSI_SHP_GetHook(b2GBLimit) );

    if( hDBF == NULL )
    {
        CPLError( CE_Failure, CPLE_OpenFailed,
                  "Failed to open Shape DBF file `%s'.\n",
                  pszFilename );
        CPLFree( pszFilename );
        CPLFree( pszFilenameWithoutExt );
        SHPClose(hSHP);
        return NULL;
    }

    CPLFree( pszFilename );

/* -------------------------------------------------------------------- */
/*      Create the .prj file, if required.                              */
/* -------------------------------------------------------------------- */
    if( poSRS != NULL )
    {
        char    *pszWKT = NULL;
        CPLString osPrjFile = CPLFormFilename( NULL, pszFilenameWithoutExt, "prj");
        VSILFILE    *fp;

        /* the shape layer needs it's own copy */
        poSRS = poSRS->Clone();
        poSRS->morphToESRI();

        if( poSRS->exportToWkt( &pszWKT ) == OGRERR_NONE 
            && (fp = VSIFOpenL( osPrjFile, "wt" )) != NULL )
        {
            VSIFWriteL( pszWKT, strlen(pszWKT), 1, fp );
            VSIFCloseL( fp );
        }

        CPLFree( pszWKT );

        poSRS->morphFromESRI();
    }

/* -------------------------------------------------------------------- */
/*      Create the layer object.                                        */
/* -------------------------------------------------------------------- */
    OGRShapeLayer       *poLayer;

    /* OGRShapeLayer constructor expects a filename with an extension (that could be */
    /* random actually), otherwise this is going to cause problems with layer */
    /* names that have a dot (not speaking about the one before the shp) */
    pszFilename = CPLStrdup(CPLFormFilename( NULL, pszFilenameWithoutExt, "shp" ));

    poLayer = new OGRShapeLayer( this, pszFilename, hSHP, hDBF, poSRS, TRUE, TRUE,
                                 eType );

    CPLFree( pszFilenameWithoutExt );
    CPLFree( pszFilename );

    poLayer->SetResizeAtClose( CSLFetchBoolean( papszOptions, "RESIZE", FALSE ) );
    poLayer->CreateSpatialIndexAtClose( CSLFetchBoolean( papszOptions, "SPATIAL_INDEX", FALSE ) );
    poLayer->SetModificationDate(
        CSLFetchNameValue( papszOptions, "DBF_DATE_LAST_UPDATE" ) );

/* -------------------------------------------------------------------- */
/*      Add layer to data source layer list.                            */
/* -------------------------------------------------------------------- */
    AddLayer(poLayer);

    return poLayer;
}
Beispiel #29
0
OGRErr OGRDataSource::ProcessSQLCreateIndex( const char *pszSQLCommand )

{
    char **papszTokens = CSLTokenizeString( pszSQLCommand );

/* -------------------------------------------------------------------- */
/*      Do some general syntax checking.                                */
/* -------------------------------------------------------------------- */
    if( CSLCount(papszTokens) != 6 
        || !EQUAL(papszTokens[0],"CREATE")
        || !EQUAL(papszTokens[1],"INDEX")
        || !EQUAL(papszTokens[2],"ON")
        || !EQUAL(papszTokens[4],"USING") )
    {
        CSLDestroy( papszTokens );
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Syntax error in CREATE INDEX command.\n"
                  "Was '%s'\n"
                  "Should be of form 'CREATE INDEX ON <table> USING <field>'",
                  pszSQLCommand );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Find the named layer.                                           */
/* -------------------------------------------------------------------- */
    int  i;
    OGRLayer *poLayer = NULL;

    for( i = 0; i < GetLayerCount(); i++ )
    {
        poLayer = GetLayer(i);
        
        if( EQUAL(poLayer->GetLayerDefn()->GetName(),papszTokens[3]) )
            break;
    }

    if( i >= GetLayerCount() )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "CREATE INDEX ON failed, no such layer as `%s'.",
                  papszTokens[3] );
        CSLDestroy( papszTokens );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Does this layer even support attribute indexes?                 */
/* -------------------------------------------------------------------- */
    if( poLayer->GetIndex() == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "CREATE INDEX ON not supported by this driver." );
        CSLDestroy( papszTokens );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Find the named field.                                           */
/* -------------------------------------------------------------------- */
    for( i = 0; i < poLayer->GetLayerDefn()->GetFieldCount(); i++ )
    {
        if( EQUAL(papszTokens[5],
                  poLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()) )
            break;
    }

    CSLDestroy( papszTokens );

    if( i >= poLayer->GetLayerDefn()->GetFieldCount() )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "`%s' failed, field not found.",
                  pszSQLCommand );
        return OGRERR_FAILURE;
    }

/* -------------------------------------------------------------------- */
/*      Attempt to create the index.                                    */
/* -------------------------------------------------------------------- */
    OGRErr eErr;

    eErr = poLayer->GetIndex()->CreateIndex( i );
    if( eErr == OGRERR_NONE )
        eErr = poLayer->GetIndex()->IndexAllFeatures( i );

    return eErr;
}
Beispiel #30
0
int SDTSTransfer::GetBounds( double *pdfMinX, double *pdfMinY,
                             double *pdfMaxX, double *pdfMaxY )

{
    bool bFirst = true;

    for( int iLayer = 0; iLayer < GetLayerCount(); iLayer++ )
    {
        if( GetLayerType( iLayer ) == SLTPoint )
        {

            SDTSPointReader *poLayer = reinterpret_cast<SDTSPointReader *>(
                GetLayerIndexedReader( iLayer ) );
            if( poLayer == nullptr )
                continue;

            poLayer->Rewind();

            SDTSRawPoint *poPoint = nullptr;
            while( (poPoint = reinterpret_cast<SDTSRawPoint *>(
                      poLayer->GetNextFeature() ) ) != nullptr )
            {
                if( bFirst )
                {
                    *pdfMinX = poPoint->dfX;
                    *pdfMaxX = poPoint->dfX;
                    *pdfMinY = poPoint->dfY;
                    *pdfMaxY = poPoint->dfY;
                    bFirst = false;
                }
                else
                {
                    *pdfMinX = std::min( *pdfMinX, poPoint->dfX );
                    *pdfMaxX = std::max( *pdfMaxX, poPoint->dfX );
                    *pdfMinY = std::min( *pdfMinY, poPoint->dfY );
                    *pdfMaxY = std::max( *pdfMaxY, poPoint->dfY );
                }

                if( !poLayer->IsIndexed() )
                    delete poPoint;
            }
        }
        else if( GetLayerType( iLayer ) == SLTRaster )
        {
            SDTSRasterReader *poRL = GetLayerRasterReader( iLayer );
            if( poRL == nullptr )
                continue;

            double adfGeoTransform[6];
            poRL->GetTransform( adfGeoTransform );

            const double dfMinX = adfGeoTransform[0];
            const double dfMaxY = adfGeoTransform[3];
            const double dfMaxX = adfGeoTransform[0]
                + poRL->GetXSize() * adfGeoTransform[1];
            const double dfMinY = adfGeoTransform[3]
                + poRL->GetYSize() * adfGeoTransform[5];

            if( bFirst )
            {
                *pdfMinX = dfMinX;
                *pdfMaxX = dfMaxX;
                *pdfMinY = dfMinY;
                *pdfMaxY = dfMaxY;
                bFirst = false;
            }
            else
            {
                *pdfMinX = std::min( dfMinX, *pdfMinX );
                *pdfMaxX = std::max( dfMaxX, *pdfMaxX );
                *pdfMinY = std::min( dfMinY, *pdfMinY );
                *pdfMaxY = std::max( dfMaxY, *pdfMaxY );
            }

            delete poRL;
        }
    }

    return !bFirst;
}