Exemplo n.º 1
0
bool TeSQLite::insertPolygon(const string& table, TePolygon &p)
{
	errorMessage_ = "";

	std::string objectId = p.objectId();

	char* wkb = 0;
	unsigned int wkbSize = 0;

	TeWKBGeometryDecoder::encodePolygon(p, wkb, wkbSize);

	std::string command = "INSERT INTO ";
	command += table;
	command += " (object_id, lower_x, lower_y, upper_x, upper_y, spatial_data)"; 
	command += " VALUES (?1, ?2, ?3, ?4, ?5, ?6)";

	sqlite3_stmt* recordSet = 0;
	int retValue = sqlite3_prepare_v2(_conn, command.c_str(), -1, &recordSet, 0);

	if(retValue != SQLITE_OK)
	{
		errorMessage_ = errorMessage();
		return false;
	}

	sqlite3_bind_text(recordSet, 1, objectId.c_str(), objectId.size(), SQLITE_TRANSIENT);
	sqlite3_bind_double(recordSet, 2, p.box().x1());
	sqlite3_bind_double(recordSet, 3, p.box().y1());
	sqlite3_bind_double(recordSet, 4, p.box().x2());
	sqlite3_bind_double(recordSet, 5, p.box().y2());
	sqlite3_bind_blob(recordSet, 6, wkb, wkbSize, SQLITE_TRANSIENT);

	delete wkb;

	retValue = sqlite3_step(recordSet);
	if(retValue != SQLITE_DONE)
	{
		return false;
	}

	sqlite3_finalize(recordSet);

	//int newId = getMaxValue(this, table, "geom_id");
	int newId = getLastInsertedSerial();
	if(newId >= 0)
	{
		p.geomId(newId);
	}

	return true;
}
Exemplo n.º 2
0
bool TeSQLitePortal::fetchGeometry(TePolygon& geom, const unsigned int& initIndex)
{
	errorMessage_ = "";
	
	const char* bValue = (const char*) sqlite3_column_blob(_recordSet, initIndex + 6);
	unsigned int size = (unsigned int)sqlite3_column_bytes(_recordSet, initIndex + 6);	

	TeWKBGeometryDecoder::decodePolygon(bValue, geom, size);

	geom.geomId(getInt(initIndex + 0));
	geom.objectId(getData(initIndex + 1));
	

	return fetchRow();
}
bool TeINTERSECTOR2::TeSafeIntersections(const TePolygonSet& redPols, const TePolygonSet& bluePols, TeVectorBoundaryIP& report)
{
	unsigned int redPart = 0;
	unsigned int redPolsSize = redPols.size();

	unsigned int i, k;
	register unsigned int j, l;

	// Loops through red polygons
	for(i = 0; i < redPolsSize; ++i)
	{
		TePolygon redPol = redPols[i];
		unsigned int redPolSize = redPol.size();

		// Loops through red polygons rings
		for(j = 0; j < redPolSize; ++j)
		{
			TeLinearRing redRing = redPol[j];			

			// Loops through blue polygons
			unsigned int bluePart = 0;
			unsigned int bluePolsSize =  bluePols.size();

			for(k = 0; k < bluePolsSize; ++k)
			{
				// Loops through blue polygons rings
				TePolygon bluePol = bluePols[k];

				unsigned int bluePolSize = bluePol.size();

				for(l = 0; l < bluePolSize; ++l)
				{
					TeLinearRing blueRing = bluePol[l];

					TeSafeIntersections(redRing, blueRing, report, redPart, bluePart);

					++bluePart;
				}
			}

			++redPart;
		}
	}

	return !report.empty();
}
Exemplo n.º 4
0
bool TeSQLite::updatePolygon(const string& table, TePolygon &p)
{
	errorMessage_ = "";

	std::string command = "UPDATE " + table + " SET ";
	command += "object_id=?";
	command += ", lower_x=?, lower_y=?, upper_x=?, upper_y=?, "; 
	command += ", spatial_data=? WHERE geom_id = " + Te2String(p.geomId());


	std::string objectId = p.objectId();

	char* wkb = 0;
	unsigned int wkbSize = 0;

	TeWKBGeometryDecoder::encodePolygon(p, wkb, wkbSize);

	sqlite3_stmt* recordSet = 0;
	int retValue = sqlite3_prepare_v2(_conn, command.c_str(), -1, &recordSet, 0);

	if(retValue != SQLITE_OK)
	{
		errorMessage_ = errorMessage();
		return false;
	}

	sqlite3_bind_text(recordSet, 1, objectId.c_str(), objectId.size(), SQLITE_TRANSIENT);
	sqlite3_bind_double(recordSet, 2, p.box().x1());
	sqlite3_bind_double(recordSet, 3, p.box().y1());
	sqlite3_bind_double(recordSet, 4, p.box().x2());
	sqlite3_bind_double(recordSet, 5, p.box().y2());
	sqlite3_bind_blob(recordSet, 6, wkb, wkbSize, SQLITE_TRANSIENT);

	delete wkb;

	retValue = sqlite3_step(recordSet);
	if(retValue != SQLITE_DONE)
	{
		return false;
	}

	sqlite3_finalize(recordSet);

	return true;
}
Exemplo n.º 5
0
void SimplifyWindow::pushButton_clicked() {
    std::string inputThemeName=this->themeComboBox->currentText().toStdString();
    double tol=this->lineEdit->text().toDouble();
    std::string outThemeName=this->lineEdit_2->text().toStdString();


    TeDatabase* db = plugin_params_->getCurrentDatabasePtr();

    TeLayer* inputLayer=getLayer(inputThemeName);
    TeProjection* proj = inputLayer->projection();



    if (inputLayer->geomRep() & TeLINES) {
        TeLineSet lines,outputLines;
        inputLayer->getLines(lines);
        for (TeLineSet::iterator lineIt=lines.begin();lineIt!=lines.end();++lineIt) {
            TeLine2D newline;
            newline.copyElements(*lineIt);

            TeLineSimplify(newline,tol,TeLength(newline));
        }
        createLayer(outThemeName,db,proj,outputLines);
    }
    if (inputLayer->geomRep() & TePOLYGONS) {
        TePolygonSet pols,outputPolygons;
        inputLayer->getPolygons(pols);
        for (TePolygonSet::iterator polIt=pols.begin();polIt!=pols.end();++polIt) {
            TePolygon newpol;
            for (TePolygon::iterator ringIt=polIt->begin();ringIt!=polIt->end();++ringIt) {
                TeLinearRing newring;
                newring.copyElements(*ringIt);
                TeLineSimplify(newring,tol,TeLength(newring));
                newpol.add(newring);
            }
            outputPolygons.add(newpol);
        }
        createLayer(outThemeName,db,proj,outputPolygons);
    }
    QMessageBox::information(this, tr("Information"), tr("Simplification process finished!"));
    plugin_params_->updateTVInterface();
}
Exemplo n.º 6
0
void TeMANAGER::TeGDLegend::draw(std::vector<TeLegendEntryVector>& legends,
					  std::vector<std::string>& legendTitles,
					  const int& width)
{
// verifica quantas linhas tera a legenda: uma para cada legenda e mais uma para cada agrupamento
	int legendVecSize = 0;

	for(unsigned int i = 0; i < legends.size(); ++i)
	{
		if(legends[i].size() > 1)	// se existe mais de uma legenda, entao temos um agrupamento!
			legendVecSize += legends[i].size() + 1;
		else						// caso contrario, temos somente uma legenda
			++legendVecSize;
	}

	if(legendVecSize == 0)
		return;

// determina as dimensoes do canvas
	int legendHeight =  legendVecSize * 20;

	double nlin = (double)legendHeight / 20.0;
    double ncol = (double)width/20.0;

	TeCoord2D c1(0.0, 0.0);
	TeCoord2D c2(ncol, nlin);
	TeBox b(0.0, 0.0, ncol, nlin);

// ajusta o canvas
	gdCanvas_->setWorld(b, width, legendHeight);

// marca a posicao inicial de escrita
	int currentLinePosition = 0;

	double posd = legendVecSize - 1;

	TeCoord2D c(ncol/2.0, posd + 0.60);

// desenha as legendas
	for(unsigned int i = 0; i < legends.size(); ++i)
	{
		for(unsigned int j = 0; j < legends[i].size(); ++j)
		{
			posd = legendVecSize - 1 - currentLinePosition;

			if((j == 0) && legends[i].size() > 1)
			{
				TeCoord2D c(0.2, posd + 0.60);

				gdCanvas_->draw(c, legendTitles[i], 0.0, 0.5, 0.0);

				++currentLinePosition;

				posd = legendVecSize - 1 - currentLinePosition;
			}

			bool hasPOLYGONS = (legends[i][j].getVisualMap().find(TePOLYGONS) != legends[i][j].getVisualMap().end());
			bool hasLINES    = (legends[i][j].getVisualMap().find(TeLINES) != legends[i][j].getVisualMap().end());
			bool hasPOINTS   = (legends[i][j].getVisualMap().find(TePOINTS) != legends[i][j].getVisualMap().end());

			double dx = 0;

			if(hasPOLYGONS)
				dx = 1.75;

			if(hasLINES)
				dx += 1.75;

			if(hasPOINTS)
				dx += 1.75;

			if((j == 0) && legends[i].size() == 1)
			{
				TeCoord2D c(dx, posd + 0.60);

				gdCanvas_->draw(c, legendTitles[i], 0.0, 0.5, 0.0);
			}
			else
			{
				TeCoord2D c(dx, posd + 0.60);

				gdCanvas_->draw(c, legends[i][j].label(), 0.0, 0.5, 0.0);
			}

			if(hasPOLYGONS)
			{
				TeCoord2D c1, c2, c3, c4;
				
				c1.setXY(0.2, posd + 0.15);
				c2.setXY(0.2, posd + 0.9);
				c3.setXY(1.5, posd + 0.9);
				c4.setXY(1.5, posd + 0.15);

				TeLine2D l;
				l.add(c1); l.add(c2); l.add(c3); l.add(c4); l.add(c1);

				TeLinearRing r(l);

				TePolygon p;
				p.add(r);
				
				// Draw the legend polygon
				TeGeomRepVisualMap& visualMap = legends[i][j].getVisualMap();
				TeVisual& polygonVisual = *(visualMap[TePOLYGONS]);
				TeColor& polygonColor = polygonVisual.color();
				TeColor& polygonContourColor = polygonVisual.contourColor();

				gdCanvas_->setPolygonColor(polygonColor.red_, polygonColor.green_, polygonColor.blue_, polygonVisual.transparency());
				gdCanvas_->setPolygonStyle(polygonVisual.style());
				gdCanvas_->setPolygonLineColor(polygonContourColor.red_, polygonContourColor.green_, polygonContourColor.blue_);
				gdCanvas_->setPolygonLineStyle(polygonVisual.contourStyle(), polygonVisual.contourWidth());

				gdCanvas_->draw(p);
			}

			if(hasLINES)
			{
				dx = 0;

				if(hasPOLYGONS)
					dx = 1.75;

				TeCoord2D c1, c2, c3, c4;
				
				c1.setXY(0.2 + dx, posd + 0.15);
				c2.setXY(0.6 + dx, posd + 0.9);
				c3.setXY(1.0 + dx, posd + 0.15);
				c4.setXY(1.5 + dx, posd + 0.9);

				TeLine2D l;
				l.add(c1); l.add(c2); l.add(c3); l.add(c4);

				TeGeomRepVisualMap& visualMap = legends[i][j].getVisualMap();
				TeVisual& lnVisual = *(visualMap[TeLINES]);
				TeColor& lnColor = lnVisual.color();			

				gdCanvas_->setLineColor(lnColor.red_, lnColor.green_, lnColor.blue_);
				gdCanvas_->setLineStyle(lnVisual.style(), lnVisual.width() + 1);
	
				gdCanvas_->draw(l);
			}

			if(hasPOINTS)
			{
				dx = 0;

				if(hasPOLYGONS)
					dx = 1.75;

				if(hasLINES)
					dx += 1.75;

				TeCoord2D c(0.6 + dx, posd + 0.6);
				TePoint pt(c);				

				TeGeomRepVisualMap& visualMap = legends[i][j].getVisualMap();
				TeVisual& ptVisual = *(visualMap[TePOINTS]);
				TeColor& ptColor = ptVisual.color();

				gdCanvas_->setPointColor(ptColor.red_, ptColor.green_, ptColor.blue_);
				gdCanvas_->setPointStyle(ptVisual.style(), ptVisual.size() + 1);
				gdCanvas_->draw(pt);				
			}

			++currentLinePosition;
		}
	}
}
Exemplo n.º 7
0
bool TeExportPolygonSet2SHP( const TePolygonSet& ps,const std::string& base_file_name  )
{
    // creating files names
    std::string dbfFilename = base_file_name + ".dbf";
    std::string shpFilename = base_file_name + ".shp";

    // creating polygons attribute list ( max attribute size == 25 )
    TeAttributeList attList;
    TeAttribute at;
    at.rep_.type_ = TeSTRING;               //the id of the cell
    at.rep_.numChar_ = 25;
    at.rep_.name_ = "object_id_";
    at.rep_.isPrimaryKey_ = true;
	attList.push_back(at);
    
    /* DBF output file handle creation */
	DBFHandle hDBF = TeCreateDBFFile (dbfFilename, attList);
	if ( hDBF == 0 )
		return false;
    
    /* SHP output file handle creation */
    SHPHandle hSHP = SHPCreate( shpFilename.c_str(), SHPT_POLYGON );
    if( hSHP == 0 ) 
	{
      DBFClose( hDBF );
      return false;
    }
    
    /* Writing polygons */
    int iRecord = 0;
    int totpoints = 0;
    double  *padfX, *padfY;
    SHPObject       *psObject;
    int posXY, npoints, nelem;
    int nVertices;
    int* panParts;

    TePolygonSet::iterator itps;
    TePolygon poly;

    for (itps = ps.begin() ; itps != ps.end() ; itps++ ) {
      poly=(*itps);
      totpoints = 0;
      nVertices = poly.size();
      for (unsigned int n=0; n<poly.size();n++) {
        totpoints += poly[n].size();
      }

      panParts = (int *) malloc(sizeof(int) * nVertices);
      padfX = (double *) malloc(sizeof(double) * totpoints);
      padfY = (double *) malloc(sizeof(double) * totpoints);
      posXY = 0;
      nelem = 0;
      
      for (unsigned int l=0; l<poly.size(); ++l) {
        if (l==0) {
          if (TeOrientation(poly[l]) == TeCOUNTERCLOCKWISE) {
            TeReverseLine(poly[l]);
          }
        } else {
          if (TeOrientation(poly[l]) == TeCLOCKWISE) {
            TeReverseLine(poly[l]);
          }
        }
        
        npoints = poly[l].size();
        panParts[nelem]=posXY;
        
        for (int m=0; m<npoints; m++ ) {
          padfX[posXY] = poly[l][m].x_;
          padfY[posXY] = poly[l][m].y_;
          posXY++;
        }
        nelem++;
      }
                
      psObject = SHPCreateObject( SHPT_POLYGON, -1, nelem, panParts, NULL,
        posXY, padfX, padfY, NULL, NULL );
        
      int shpRes = SHPWriteObject( hSHP, -1, psObject );
      if (shpRes == -1 )
	  {
	      DBFClose( hDBF );
		  SHPClose( hSHP );
		  return false;
	  }
        
      SHPDestroyObject( psObject );
      free( panParts );
      free( padfX );
      free( padfY );

      // writing attributes - same creation order
      DBFWriteStringAttribute(hDBF, iRecord, 0, poly.objectId().c_str() );
            
      iRecord++;
    }
    
    DBFClose( hDBF );
    SHPClose( hSHP );
    return true;  
}
Exemplo n.º 8
0
bool
TeExportQuerierToShapefile(TeQuerier* querier, const std::string& base)
{
	// check initial conditions
	if (!querier)
		return false;

	if (!querier->loadInstances())
		return false;

	// Get the list of attributes defined by the input querier
	bool onlyObjId = false;
	TeAttributeList qAttList = querier->getAttrList();
	if (qAttList.empty())
	{
		TeAttributeList qAttList;
		TeAttribute at;
		at.rep_.type_ = TeSTRING;               
		at.rep_.numChar_ = 100;
		at.rep_.name_ = "ID";
		at.rep_.isPrimaryKey_ = true;
		qAttList.push_back(at);
		onlyObjId = true;
	}

	// Handles to each type of geometries that will be created if necessary
	DBFHandle hDBFPol = 0;
	SHPHandle hSHPPol = 0;
	DBFHandle hDBFLin = 0;
	SHPHandle hSHPLin = 0;
	DBFHandle hDBFPt = 0;
	SHPHandle hSHPPt = 0;

	// Some auxiliary variables
    int totpoints;
    double*	padfX;
	double*	padfY;
    unsigned int nVertices;
    int* panPart;
    SHPObject *psObject;
    unsigned int posXY, npoints, nelem;
	int shpRes;

	// progress information
	if (TeProgress::instance())
		TeProgress::instance()->setTotalSteps(querier->numElemInstances());
	clock_t	t0, t1, t2;
	t2 = clock();
	t0 = t1 = t2;
	int dt = CLOCKS_PER_SEC/2;
	int dt2 = CLOCKS_PER_SEC; //* .000001;

	// Loop through the instances writting their geometries and attributes
	unsigned int iRecPol=0, iRecLin=0, iRecPt=0;
	unsigned int n, l, m;
	unsigned int nIProcessed = 0;
	TeSTInstance st;
	while(querier->fetchInstance(st))
	{
		totpoints = 0;
		nVertices = 0;
		if (st.hasPolygons())
		{
			TePolygonSet& polSet = st.getPolygons();
			TePolygonSet::iterator itps;
			int nVerticesCount = 0;
			for (itps = polSet.begin(); itps != polSet.end(); ++itps) 
			{
				nVertices = (*itps).size();
				nVerticesCount += nVertices;
				for (n=0; n<nVertices;++n) 
					totpoints += (*itps)[n].size();
			}

			panPart = (int *) malloc(sizeof(int) * nVerticesCount);
			padfX = (double *) malloc(sizeof(double) * totpoints);
			padfY = (double *) malloc(sizeof(double) * totpoints);

			posXY = 0;
			nelem = 0;
			for (itps = polSet.begin(); itps != polSet.end(); ++itps) 
			{
				TePolygon poly = *itps;
				for (l=0; l<poly.size(); ++l) 
				{
					if (l==0) 
					{
						if (TeOrientation(poly[l]) == TeCOUNTERCLOCKWISE) 
							TeReverseLine(poly[l]);
					}
					else 
					{
						if (TeOrientation(poly[l]) == TeCLOCKWISE)
							TeReverseLine(poly[l]);
					}
					npoints = poly[l].size();
					panPart[nelem]=posXY;
        
					for (m=0; m<npoints; ++m) 
					{
						padfX[posXY] = poly[l][m].x_;
						padfY[posXY] = poly[l][m].y_;
						posXY++;
					}
					nelem++;
				}
			}
			psObject = SHPCreateObject(SHPT_POLYGON, -1, nelem, panPart, NULL, posXY, padfX, padfY, NULL, NULL);
			if (hSHPPol == 0)
			{
				string fname = base + "_pol.shp";
				hSHPPol = SHPCreate(fname.c_str(), SHPT_POLYGON);
   				assert (hSHPPol != 0);
			}	
			shpRes = SHPWriteObject(hSHPPol, -1, psObject);
			SHPDestroyObject(psObject);
			free(panPart);
			free(padfX);
			free(padfY);
			assert(shpRes != -1);   
			if (hDBFPol == 0)
			{
				hDBFPol = TeCreateDBFFile(base + "_pol.dbf", qAttList);
				assert (hDBFPol != 0);
			}
			if (onlyObjId)
			{
				DBFWriteStringAttribute(hDBFPol, iRecPol, 0, st.objectId().c_str());
			}
			else
			{
				string val;
				for (n=0; n<qAttList.size();++n) 
				{
					st.getPropertyValue(val,n);
					if (qAttList[n].rep_.type_ == TeSTRING || qAttList[n].rep_.type_ == TeDATETIME)
					{
						DBFWriteStringAttribute(hDBFPol, iRecPol, n, val.c_str());
					}
					else if (qAttList[n].rep_.type_ == TeINT)
					{
						DBFWriteIntegerAttribute(hDBFPol, iRecPol, n, atoi(val.c_str()));
					}
					else if (qAttList[n].rep_.type_ == TeREAL)
					{
						DBFWriteDoubleAttribute(hDBFPol, iRecPol, n, atof(val.c_str()));
					}
				}
			}
			++iRecPol;
		}
		if (st.hasCells())
		{
			TeCellSet& cellSet = st.getCells();
			nVertices = cellSet.size();
			totpoints = nVertices*5;
			panPart = (int *) malloc(sizeof(int) * nVertices);
			padfX = (double *) malloc(sizeof(double) * totpoints);
			padfY = (double *) malloc(sizeof(double) * totpoints);
			posXY = 0;
			nelem = 0;
			TeCellSet::iterator itcs;
			for (itcs=cellSet.begin(); itcs!=cellSet.end(); ++itcs)
			{
				panPart[nelem]=posXY;
				padfX[posXY] = (*itcs).box().lowerLeft().x();
				padfY[posXY] = (*itcs).box().lowerLeft().y();
				posXY++;		
				padfX[posXY] = (*itcs).box().upperRight().x();
				padfY[posXY] = (*itcs).box().lowerLeft().y();
				posXY++;		
				padfX[posXY] = (*itcs).box().upperRight().x();
				padfY[posXY] = (*itcs).box().upperRight().y();
				posXY++;		
				padfX[posXY] = (*itcs).box().lowerLeft().x();
				padfY[posXY] = (*itcs).box().upperRight().y();
				posXY++;		
				padfX[posXY] = (*itcs).box().lowerLeft().x();
				padfY[posXY] = (*itcs).box().lowerLeft().y();
				++posXY;	
				++nelem;
			} 
			psObject = SHPCreateObject(SHPT_POLYGON, -1, nelem, panPart, NULL,posXY, padfX, padfY, NULL, NULL);
			if (hSHPPol == 0)
			{
				string fname = base + "_pol.shp";
				hSHPPol = SHPCreate(fname.c_str(), SHPT_POLYGON);
   				assert (hSHPPol != 0);
			}	
			shpRes = SHPWriteObject(hSHPPol, -1, psObject);
			SHPDestroyObject(psObject);
			free(panPart);
			free(padfX);
			free(padfY);
			assert(shpRes != -1);
			if (hDBFPol == 0)
			{
				hDBFPol = TeCreateDBFFile(base + "_pol.dbf", qAttList);
				assert (hDBFPol != 0);
			}

			if (onlyObjId)
			{
				DBFWriteStringAttribute(hDBFPol, iRecPol, 0, st.objectId().c_str());
			}
			else
			{
				string val;
				for (n=0; n<qAttList.size();++n) 
				{
					st.getPropertyValue(val,n);
					if (qAttList[n].rep_.type_ == TeSTRING || qAttList[n].rep_.type_ == TeDATETIME)
					{
						DBFWriteStringAttribute(hDBFPol, iRecPol, n, val.c_str());
					}
					else if (qAttList[n].rep_.type_ == TeINT)
					{
						DBFWriteIntegerAttribute(hDBFPol, iRecPol, n, atoi(val.c_str()));
					}
					else if (qAttList[n].rep_.type_ == TeREAL)
					{
						DBFWriteDoubleAttribute(hDBFPol, iRecPol, n, atof(val.c_str()));
					}
				}
			}
			++iRecPol;
		}
		if (st.hasLines())
		{
			TeLineSet& lineSet = st.getLines();
			nVertices = lineSet.size();
			TeLineSet::iterator itls;
			for (itls=lineSet.begin(); itls!=lineSet.end(); ++itls)
				totpoints += (*itls).size();
			panPart = (int *) malloc(sizeof(int) * nVertices);
			padfX = (double *) malloc(sizeof(double) * totpoints);
			padfY = (double *) malloc(sizeof(double) * totpoints);
			posXY = 0;
			nelem = 0;
			for (itls=lineSet.begin(); itls!=lineSet.end(); ++itls)
			{
				panPart[nelem]=posXY;
				for (l=0; l<(*itls).size(); ++l)
				{
					padfX[posXY] = (*itls)[l].x();
					padfY[posXY] = (*itls)[l].y();
					++posXY;
				}
				++nelem;
			}
			psObject = SHPCreateObject(SHPT_ARC, -1, nVertices, panPart, NULL,	posXY, padfX, padfY, NULL, NULL);
			if (hSHPLin == 0)
			{
				string fname = base + "_lin.shp"; 
				hSHPLin = SHPCreate(fname.c_str(), SHPT_ARC);
   				assert (hSHPLin != 0);
			}		
			shpRes = SHPWriteObject(hSHPLin, -1, psObject);
			SHPDestroyObject(psObject);
			free(panPart);
			free(padfX);
			free(padfY);
			assert(shpRes != -1);
			if (hDBFLin == 0)
			{
				hDBFLin = TeCreateDBFFile(base + "_lin.dbf", qAttList);
				assert (hDBFLin != 0);
			}
			if (onlyObjId)
			{
				DBFWriteStringAttribute(hDBFLin, iRecLin, 0, st.objectId().c_str());
			}
			else
			{
				string val;
				for (n=0; n<qAttList.size();++n) 
				{
					st.getPropertyValue(val,n);
					if (qAttList[n].rep_.type_ == TeSTRING || qAttList[n].rep_.type_ == TeDATETIME)
					{
						DBFWriteStringAttribute(hDBFLin, iRecLin, n, val.c_str());
					}
					else if (qAttList[n].rep_.type_ == TeINT)
					{
						DBFWriteIntegerAttribute(hDBFLin, iRecLin, n, atoi(val.c_str()));
					}
					else if (qAttList[n].rep_.type_ == TeREAL)
					{
						DBFWriteDoubleAttribute(hDBFLin, iRecLin, n, atof(val.c_str()));
					}
				}
			}
			++iRecLin;
		}
		if (st.hasPoints())
		{
			TePointSet& pointSet = st.getPoints();
			nVertices = pointSet.size();
			panPart = (int *) malloc(sizeof(int) * nVertices);
			padfX = (double *) malloc(sizeof(double) * nVertices);
			padfY = (double *) malloc(sizeof(double) * nVertices);
			nelem = 0;
			TePointSet::iterator itpts;
			for (itpts=pointSet.begin(); itpts!=pointSet.end(); ++itpts)
			{
				panPart[nelem] = nelem;
				padfX[nelem] = (*itpts).location().x();
				padfY[nelem] = (*itpts).location().y();
				++nelem;
			}
			psObject = SHPCreateObject(SHPT_POINT, -1, nVertices, panPart, NULL, nVertices, padfX, padfY, NULL, NULL );
			if (hSHPPt == 0)
			{
				string fname = base + "_pt.shp";
				hSHPPt = SHPCreate(fname.c_str(), SHPT_POINT);
   				assert (hSHPPt != 0);
			}		
			shpRes = SHPWriteObject(hSHPPt, -1, psObject);
			SHPDestroyObject(psObject);
			free(panPart);
			free(padfX);
			free(padfY);
			assert(shpRes != -1);
			if (hDBFPt == 0)
			{
				hDBFPt = TeCreateDBFFile(base + "_pt.dbf", qAttList);
				assert (hDBFPt != 0);
			}
			if (onlyObjId)
			{
				DBFWriteStringAttribute(hDBFPt, iRecPt, 0, st.objectId().c_str());
			}
			else
			{
				string val;
				for (n=0; n<qAttList.size();++n) 
				{
					st.getPropertyValue(val,n);
						if (qAttList[n].rep_.type_ == TeSTRING || qAttList[n].rep_.type_ == TeDATETIME)
					{
						DBFWriteStringAttribute(hDBFPt, iRecPt, n, val.c_str());
					}
					else if (qAttList[n].rep_.type_ == TeINT)
					{
						DBFWriteIntegerAttribute(hDBFPt, iRecPt, n, atoi(val.c_str()));
					}
					else if (qAttList[n].rep_.type_ == TeREAL)
					{
						DBFWriteDoubleAttribute(hDBFPt, iRecPt, n, atof(val.c_str()));
					}
				}
			}
			++iRecPt;
		}
		++nIProcessed;
		if (TeProgress::instance() && int(t2-t1) > dt)
		{
			t1 = t2;
			if(((int)(t2-t0) > dt2))
			{
				if (TeProgress::instance()->wasCancelled())
					break;
				else
					TeProgress::instance()->setProgress(nIProcessed);
			}
		}

	}
	if (hDBFPol != 0)
		DBFClose(hDBFPol);
	if (hSHPPol != 0)
        SHPClose(hSHPPol);
	if (hDBFLin != 0)
		DBFClose(hDBFLin);
	if (hSHPLin != 0)
        SHPClose(hSHPLin);
	if (hDBFPt != 0)
		DBFClose(hDBFPt);
	if (hSHPPt != 0)
        SHPClose(hSHPPt);

	if (TeProgress::instance())
		TeProgress::instance()->reset();
	return true;
}