Esempio n. 1
0
    void parse(const std::string& path, Visitor& visitor) const
    {
        SHPHandle shpFile = SHPOpen(path.c_str(), "rb");
        if (shpFile == NULL)
            throw std::domain_error("Cannot open shp file.");

        int shapeType, entityCount;
        double adfMinBound[4], adfMaxBound[4];
        SHPGetInfo(shpFile, &entityCount, &shapeType, adfMinBound, adfMaxBound);

        DBFHandle dbfFile = DBFOpen(path.c_str(), "rb");
        if (dbfFile == NULL)
            throw std::domain_error("Cannot open dbf file.");

        if (DBFGetFieldCount(dbfFile) == 0)
            throw std::domain_error("There are no fields in dbf table.");

        if (entityCount != DBFGetRecordCount(dbfFile))
            throw std::domain_error("dbf file has different entity count.");

        for (int k = 0; k < entityCount; k++)
        {
            SHPObject* shape = SHPReadObject(shpFile, k);
            if (shape == NULL)
                throw std::domain_error("Unable to read shape:" + to_string(k));

            Tags tags = parseTags(dbfFile, k);
            visitShape(*shape, tags, visitor);

            SHPDestroyObject(shape);
        }

        DBFClose(dbfFile);
        SHPClose(shpFile);
    }
Esempio n. 2
0
void Page::loadTags()
{
	if (!m_urlRegex.isEmpty())
	{
		m_replyTags = m_site->get(m_urlRegex);
		connect(m_replyTags, SIGNAL(finished()), this, SLOT(parseTags()));
		m_replyTagsExists = true;
	}
}
Esempio n. 3
0
HRESULT PsfParser::parse() {
	STATSTG streamStat;
	ULONG bytesRead;
	HRESULT hresult;

	hresult=stream->Stat(&streamStat,STATFLAG_NONAME);
	retIfFail;

	if(streamStat.cbSize.QuadPart<MIN_PCF_SIZE) {
		return E_INVALIDARG;
	}

	LARGE_INTEGER seekPos;
	seekPos.QuadPart=0;
	hresult=stream->Seek(seekPos,STREAM_SEEK_SET,nullptr);
	retIfFail;

	CHAR fileSig[3];
	hresult=stream->Read(fileSig,3,&bytesRead);
	retIfNonOk;

	if(strcmp(fileSig,"PSF")!=0) return E_INVALIDARG;

	hresult=stream->Read(&version,1,&bytesRead);
	retIfNonOk;

	uint32_t reservatedLength,compressedLength,compressedCrc;

	hresult=readLong(reservatedLength);
	retIfNonOk;
	hresult=readLong(compressedLength);
	retIfNonOk;
	hresult=readLong(compressedCrc);
	retIfNonOk;

	seekPos.QuadPart=reservatedLength+compressedLength;
	hresult=stream->Seek(seekPos,STREAM_SEEK_CUR,nullptr);
	retIfFail;

	CHAR tagSig[5];
	hresult=stream->Read(tagSig,5,&bytesRead);
	retIfFail;
	if(hresult==S_FALSE) return S_FALSE;

	if(strcmp(tagSig,"[TAG]")!=0) return E_INVALIDARG;

	seekPos.QuadPart=0;
	hresult=stream->Seek(seekPos,STREAM_SEEK_CUR,&tagStart);
	retIfFail;

	return parseTags();
}
Esempio n. 4
0
void LightWaveParser::loadModel(string fname) {
   in.open(fname.c_str(), ios::in | ios::binary);
   if (!in.good()) {
      fprintf(stderr, "Lightwave Parser: Error opening %s\n", fname.c_str());
      return ;
   }

   string chunkID = readChunkID(in, 4);
   int size = readIntBE(in);
   int count = 0;

   readChunkID(in, 4); // read LWO2
   count += 4;

   while(count < size) {
      chunkID = readChunkID(in, 4);
      count += 4;
fprintf(stderr, "ID = %s\n", chunkID.c_str());
      if(chunkID == "TAGS") {
         count += parseTags();
      }
      else if(chunkID == "PNTS") {
         count += parsePoints();
      }
      else if(chunkID == "POLS") {
         count += parsePolygons();
      }
      else if(chunkID == "PTAG") {
         parsePTag();
      }
      else if(chunkID == "SURF") {
         parseSurface();
      }
      else {
         count += skipChunk();
      }
   }

   in.close();

   calculateNormals();
   setupCells();
}