[gdal-dev] Polygon

Chaitanya kumar CH chaitanya.ch at gmail.com
Thu Mar 3 10:24:39 EST 2011


Alexandre,

Can you send your code as a .cpp file as an attachment?
Also, I think you should change the line
Buffer[size+1]='\0';
to
Buffer[size]='\0';

On Thu, Mar 3, 2011 at 6:34 PM, Alexandre Leclerc <a.leclerc at valabre.com>wrote:

> Hello I try to draw a polygon from shapefile on geoconcept.
>
>
>
> But the points that I get are corrupted.
>
>
>
> Strangely a shapefile with no prj, and one ring in WGS84 works.
>
>
>
> Here I try with a prj with lambert 2 extend projection.
>
>
>
> The shapefile contains 2 rings.
>
>
>
> See my code below.
>
>
>
>
>
> ifstream Prj;
>
>                      Prj.open(PrjPath,ios::in);
>
>
> if(Prj.is_open())
>
>                      {
>
>
>
>                         /*-----------read of PRJ--------------*/
>
>                         Prj.seekg(0,
> ios::end);
>
>                         int size =
> Prj.tellg();
>
>                         Prj.seekg(0,ios::beg);
>
>
>                         char *  Buffer = new char[size+1];
>
>                         Prj.read(Buffer,size);
>
>                         /*---------------------------------------*/
>
>
>
>                         Buffer[size+1]='\0';
>
>
>
>                         OGRSpatialReference oSRS, oSRS2;
>
>                         OGRCoordinateTransformation *poCT;
>
>
>
>                         oSRS.importFromESRI(&Buffer);
>
>                         oSRS2.SetGeogCS( "My geographic coordinate system",
>
>                                         "WGS_1984",
>
>                                         "My WGS84 Spheroid",
>
>                                         SRS_WGS84_SEMIMAJOR,
> SRS_WGS84_INVFLATTENING,
>
>                                         "Greenwich", 0.0,
>
>                                         "degree",
> atoi(SRS_UA_DEGREE_CONV));
>
>
>
>                         poCT =
> OGRCreateCoordinateTransformation(&oSRS,&oSRS2);
>
>
>
>
>
>                         if((poCT == NULL)||(poPoly->transform(poCT)!= OGRERR_NONE))
>          //Convert lambert 2 to WGS84
>
>                         {
>
>                          MessageBox(NULL,"Erreur,
> Réessayez","Erreur",MB_ICONERROR);
>
>                          PRJ = true;
>
>                          return;
>
>                         }
>
>
>
>                      }
>
>                      Prj.close();
>
>
>
> int nparts = poPoly->getNumInteriorRings();
>
>
>
>                    if(nparts==0)
>
>                       nparts = 1;
>
>
>
>                   for(int
> n=0;n<nparts;n++)                                                           //for
> npart…
>
>                   {
>
>                      OGRLinearRing *poRing;
>
>
>
>                       if(poPoly->getNumInteriorRings()>0)
>                 //if I understand correctly, through the function
>
>                         poRing =
> poPoly->getInteriorRing(n);                          //
> OGRGeometryFactory::organizePolygons() of
>
>                       else
>                                                                  //SHPReadOGRObject,
> all the outer rings are converted in inner rings
>
>                         poRing =
> poPoly->getExteriorRing();                            //so if there is
> more rings than 0, there is many interior rings
>
>
> //else getInteriorRing(n) should be give the N rings
>
>
> //but the function gives one ring with one point which as an incorrect value
>
>
>
>
>                      const LPXTNPOINT3D tabPoints = new
> XTNPOINT3D[poRing->getNumPoints()];        //Tab of points for draw ring
>
>
>
>                      for(i=0;i<poRing->getNumPoints();i++)
>
>  // Loop To Assign Points good projection
>
>                      {
>
>                         XTNPROJECTIONINFO xtnProjectionInfo =
> XtnStartMapProjection(xtnMapID);        // Creating a
> projection for the coordinates
>
>                         LPXTNPROJECTION lpxtnProjection = new
> XTNPROJECTION;
> //---------------------------------------------------------------
>
>
>
>                         lpxtnProjection->prLongitude =
> poRing->getX(i)*3.1415926535/180;
> //Longitude point conversion in Projected
>
>                         lpxtnProjection->prLatitude =
> poRing->getY(i)*3.1415926535/180;
> //Latitude--------------------------------------
>
>
>
>                         XtnProjection_Do(xtnProjectionInfo,
> lpxtnProjection);                                                       //Projection
> conversion
>
>                         XtnProjection_Destroy(xtnProjectionInfo);
>
>
>
>                         tabPoints[i].X
> =((long)((double)(lpxtnProjection->prX * 100.0 + 1.0))) / 100;          //Conversion
> long
>
>                         tabPoints[i].Y
> =((long)((double)(lpxtnProjection->prY * 100.0 + 1.0))) / 100;
>
>                         tabPoints[i].Z = 0 ;
>
>                      }
>
>
> XtnGeom_SetPoints(MaForme,n,poRing->getNumPoints(),tabPoints);
>  // Insertion Points in the figure
>
>                    }
>
>
>
>
>
> So, can you help me to fix my problem please ?
>
>
>
> Sincerely.
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
Best regards,
Chaitanya kumar CH.
/tʃaɪθənjə/ /kʊmɑr/
+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110303/a584d6e1/attachment-0001.html


More information about the gdal-dev mailing list