decode
[Geographical data formatsShapefile format]


Detailed Description


Functions

SHP_DLL bool TeDecodeShape (SHPObject *psShape, TeMultiGeometry &geomestries, string &objectId)
 Decodify a ShapeObject into a TerraLib multigeometry set.
SHP_DLL void TeSHPPointDecode (SHPObject *psShape, TePointSet &ps, string &objectId)
 Decodify a ShapeObject into a TerraLib point set.
SHP_DLL void TeSHPPolygonDecode (SHPObject *psShape, TePolygonSet &pols, string &objectId)
 Decodify a ShapeObject into a TerraLib polygon set.
SHP_DLL void TeSHPPolyLineDecode (SHPObject *psShape, TeLineSet &ls, string &objectId)
 Decodify a ShapeObject into a TerraLib line set.


Function Documentation

SHP_DLL bool TeDecodeShape ( SHPObject psShape,
TeMultiGeometry geomestries,
string objectId 
)

Parameters:
psShape pointer to a shapelib shape object
geometries TerraLib multi geometry set to receive the geometries
objectId TerraLib identifier to this object

Definition at line 1899 of file TeDriverSHPDBF.cpp.

References TeMultiGeometry::lines_, SHPObject::nSHPType, TeMultiGeometry::points_, TeMultiGeometry::polygons_, SHPT_ARC, SHPT_ARCZ, SHPT_MULTIPOINT, SHPT_MULTIPOINTZ, SHPT_POINT, SHPT_POINTZ, SHPT_POLYGON, SHPT_POLYGONZ, TeSHPPointDecode(), TeSHPPolygonDecode(), and TeSHPPolyLineDecode().

01900 {
01901         int shpType = psShape->nSHPType;
01902         switch (shpType)
01903         {
01904                 case SHPT_POLYGON:
01905                 case SHPT_POLYGONZ:
01906                         TeSHPPolygonDecode(psShape,geomestries.polygons_,objectId);
01907                         return true;
01908                 case SHPT_ARC:
01909                 case SHPT_ARCZ:
01910                         TeSHPPolyLineDecode(psShape,geomestries.lines_,objectId);
01911                         return true;
01912                 case SHPT_POINT:
01913                 case SHPT_POINTZ:
01914                 case SHPT_MULTIPOINT:
01915                 case SHPT_MULTIPOINTZ:
01916                         TeSHPPointDecode(psShape,geomestries.points_,objectId);
01917                         return true;
01918         }
01919         return false;
01920 }

SHP_DLL void TeSHPPointDecode ( SHPObject psShape,
TePointSet ps,
string objectId 
)

Parameters:
psShape pointer to a shapelib shape object
ps TerraLib point set to receive the geometries
objectId TerraLib identifier to this object

Definition at line 1922 of file TeDriverSHPDBF.cpp.

References TeGeomComposite< T >::add(), SHPObject::nVertices, TePoint::objectId(), SHPObject::padfX, and SHPObject::padfY.

01923 {
01924         int nv = psShape->nVertices;
01925         for (int i = 0; i<nv; i++)
01926         {
01927                 TePoint point(psShape->padfX[i], psShape->padfY[i]);
01928                 point.objectId(objid);
01929                 points.add(point);
01930         }
01931 }

SHP_DLL void TeSHPPolygonDecode ( SHPObject psShape,
TePolygonSet pols,
string objectId 
)

Parameters:
psShape pointer to a shapelib shape object
ps TerraLib polygon set to receive the geometries
objectId TerraLib identifier to this object

Definition at line 1957 of file TeDriverSHPDBF.cpp.

References TeGeomComposite< T >::add(), TeAbstractTheme::box(), TeGeometry::box(), TeLine2D::isRing(), SHPObject::nParts, SHPObject::nVertices, TeGeomComposite< T >::objectId(), SHPObject::padfX, SHPObject::padfY, SHPObject::panPartStart, TeGeomComposite< T >::size(), TeBOUNDARY, TeCLOCKWISE, TeGeometryArea(), TeINSIDE, TeMAXFLOAT, TeOrientation(), TeOUTSIDE, TeRelation(), and TeWithinOrCoveredByOrEquals().

01958 {
01959         int iPart = 0;
01960         vector<int> partStart;
01961 
01962         // Build an array whose components point to the starting point
01963         // of the rings that compose the polygon shape
01964         for ( iPart = 0; iPart < psShape->nParts; iPart++ )
01965                 partStart.push_back ( psShape->panPartStart[iPart] );
01966         partStart.push_back ( psShape->nVertices ); // point to the end
01967 
01968         vector<TePolygon> pList;
01969         vector<TeLinearRing> holes;
01970         int j = 0;
01971         iPart = 0;
01972         while (j < psShape->nVertices)
01973         {
01974                 TeLine2D line;
01975                 iPart++;                                                // while it doesn�t reach the start of next part
01976                 while ( j < partStart[iPart] )  // build a line from the coordinates
01977                 {
01978                         TeCoord2D pt ( psShape->padfX[j], psShape->padfY[j] );
01979                         line.add ( pt );
01980                         j++;
01981                 }                                                               
01982                 if (!line.isRing())                             // force the closing of opened rings
01983                         line.add(line[0]);
01984 
01985                 // decide if a ring is an outter ring or an inner ring based on its orientation
01986                 TeLinearRing ring(line);
01987                 short orient = TeOrientation(ring);
01988                 if(orient == TeCLOCKWISE)       // outter ring: start a new polygon
01989                 {
01990                         TePolygon p;
01991                         p.add(ring);
01992                         p.objectId(objid);
01993                         pList.push_back(p);
01994                 }
01995                 else    // COUNTERCLOCKWISE => inner ring: put on the list of holes
01996                         holes.push_back(ring);
01997         } // read all vertices
01998 
01999 
02000         // even though there are rings that are in counter clockwise orientation, 
02001         // there aren't any clockwise orientation rings to be possible parents of 
02002         // these inner rings. The decision here: treat all of them as outter rings...
02003         if (pList.empty() && !holes.empty())
02004         {
02005                 for (unsigned int i=0; i<holes.size(); ++i)
02006                 {
02007                         TePolygon p;
02008                         p.add(holes[i]);
02009                         p.objectId(objid);
02010                         polys.add(p);
02011                 }
02012                 return;
02013         }
02014 
02015         if (pList.size() == 1)  // shape has only one polygon that should
02016         {                                               // contain all the inner rings
02017                 for(unsigned int i = 0; i < holes.size(); ++i)
02018                         pList[0].add(holes[i]);
02019         }
02020         else
02021         {       // shape has multiple outter ring and inner rings
02022                 // we have to find a parent to each inner ring 
02023                 for(unsigned int i = 0; i < holes.size(); ++i)
02024                 {
02025                         vector<TePolygon> candidates;
02026                         TeLinearRing ring = holes[i];
02027                         
02028                         // step 1: consider as a inner ring parent candidate every polygon 
02029                         // that intercepts the ring MBR
02030                         unsigned int j = 0;
02031                         for(j = 0; j < pList.size(); ++j)
02032                         {
02033                                 if(TeWithinOrCoveredByOrEquals(ring.box(), pList[j].box()))
02034                                         candidates.push_back(pList[j]);
02035                         }
02036 
02037                         // if there is only one candidate this is the parent
02038                         if(candidates.size() == 1)
02039                         {
02040                                 candidates[0].add(ring);
02041                                 continue;
02042                         }
02043 
02044                         // step 2: refine the candidates to parent: consider only those 
02045                         // that contains the ring (not just its MBR)
02046                         vector<TePolygon> newCandidates;
02047                         for(j = 0; j < candidates.size(); ++j)
02048                         {
02049                                 short rel = TeBOUNDARY;
02050                                 bool inside = false;
02051 
02052                                 unsigned int nthVert = ring.size();
02053                                 unsigned int iVert = 0u;
02054 
02055                                 while(iVert < nthVert)
02056                                 {
02057                                         rel = TeRelation(ring[iVert], candidates[j][0]);
02058 
02059                                         if(rel & TeINSIDE)
02060                                         {
02061                                                 inside = true;
02062                                                 newCandidates.push_back(candidates[j]);
02063                                                 break;
02064                                         }
02065                                         else if(rel & TeOUTSIDE)
02066                                                 break;
02067                                         ++iVert;
02068                                 }
02069 
02070                                 if(iVert == nthVert)    
02071                                         break;
02072                         }
02073                         
02074                         // sort the new candidates according to their areas
02075                         int idxMinArea = 0;
02076                         double minArea = TeMAXFLOAT;
02077                         for(j = 0; j < newCandidates.size(); ++j)
02078                         {
02079                                 if(TeGeometryArea(newCandidates[j].box()) < minArea)
02080                                 {
02081                                         idxMinArea = j;
02082                                         minArea = TeGeometryArea(newCandidates[j].box());
02083                                 }
02084                         }
02085                         // choose as parent the candidate that has the smaller area
02086                         if (!newCandidates.empty())
02087                                 newCandidates[idxMinArea].add(ring);
02088                 }
02089         }
02090 
02091         // add polygons to the list passed as parameter
02092         vector<TePolygon>::iterator it = pList.begin();
02093         while (it != pList.end())
02094         {
02095                 polys.add(*it);
02096                 ++it;
02097         }
02098 }

SHP_DLL void TeSHPPolyLineDecode ( SHPObject psShape,
TeLineSet ls,
string objectId 
)

Parameters:
psShape pointer to a shapelib shape object
ps TerraLib line set to receive the geometries
objectId TerraLib identifier to this object

Definition at line 1934 of file TeDriverSHPDBF.cpp.

References TeGeomComposite< T >::add(), SHPObject::nParts, SHPObject::nVertices, TeLine2D::objectId(), SHPObject::padfX, SHPObject::padfY, and SHPObject::panPartStart.

01935 {
01936         int iPart,j=0,nextStart=0; 
01937         for (iPart = 0; iPart < psShape->nParts; iPart++)
01938         {
01939                 if (iPart == psShape->nParts-1)
01940                         nextStart = psShape->nVertices;
01941                 else 
01942                         nextStart = psShape->panPartStart[iPart+1];
01943 
01944                 TeLine2D line;
01945                 while (j<nextStart)
01946                 {
01947                         TeCoord2D pt ( psShape->padfX[j], psShape->padfY[j] );
01948                         line.add ( pt );
01949                         j++;
01950                 }
01951                 line.objectId (objid);  
01952                 lines.add ( line );
01953         }
01954 }


Generated on Sun Jul 29 04:04:35 2012 for TerraLib - Development Source by  doxygen 1.5.3