Results 1 to 2 of 2

Thread: Shapefile rendering,zooming,paning,editing using shaplib and qt opengl es2

  1. #1
    Join Date
    Sep 2013
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Shapefile rendering,zooming,paning,editing using shaplib and qt opengl es2

    hi all,

    I am trying to display shapefile for my ARM board but fail always. Any body can help me by supplying qt source example program.

    my code below-
    #include <QtGui/QMouseEvent>
    #include "GLWidget.h"
    #include <stdio.h>

    #include "shapelib/include/shapefil.h"
    //#include "glutlib/include/GL/glut.h"


    #include <vector>
    using namespace std;


    typedef struct MyPoint2D
    {
    double dX;
    double dY;

    }MyPoint2D;

    //Holds Coordinates of Point Shapefile
    vector<MyPoint2D> vPoints;

    typedef struct MyLineString2D
    {
    vector<MyPoint2D> vPointList;

    }MyLineString2D;

    //Holds Coordinates of Line Shapefile
    vector<MyLineString2D> vLines;


    typedef struct MyPolygon2D
    {
    vector<MyPoint2D> vPointList;

    }MyPolygon2D;
    //Holds Coordinates of Polygon Shapefile
    vector<MyPolygon2D> vPolygons;



    typedef struct SBoundingBox
    {
    float fMaxX;
    float fMaxY;
    float fMinX;
    float fMinY;

    }SBoundingBox;
    //Bounding Box of Shapefile
    SBoundingBox sBoundingBox;

    //Function to Open Shapefile and parse the info
    void OpenShapeFile(char* fileName)
    {

    SHPHandle hSHP=SHPOpen(fileName, "rb" );


    //Read Bounding Box of Shapefile
    sBoundingBox.fMaxX=hSHP->adBoundsMax[0];
    sBoundingBox.fMaxY=hSHP->adBoundsMax[1];

    sBoundingBox.fMinX=hSHP->adBoundsMin[0];
    sBoundingBox.fMinY=hSHP->adBoundsMin[1];


    if(hSHP == NULL) return;

    //Point Shapefile
    if(hSHP->nShapeType == SHPT_POINT)
    {
    SHPObject *psShape;
    for(int i=0;i<hSHP->nRecords;i++)
    {
    psShape = SHPReadObject(hSHP, i);

    double fX = psShape->padfX[0];
    double fY = -psShape->padfY[0];

    //Plot these points
    MyPoint2D pt;
    pt.dX=fX;
    pt.dY=-fY;
    vPoints.push_back(pt);
    }
    }


    //Line Shapefile
    else if(hSHP->nShapeType == SHPT_ARC)
    {
    SHPObject *psShape;
    for(int i=0;i<hSHP->nRecords;i++)
    {
    psShape = SHPReadObject(hSHP, i);
    vector<MyPoint2D> tempPointArray;

    for(int j=0;j<psShape->nVertices;j++)
    {
    double fX = psShape->padfX[j];
    double fY = psShape->padfY[j];
    MyPoint2D pt;
    pt.dX=fX;
    pt.dY=fY;
    tempPointArray.push_back(pt);
    }

    MyLineString2D linestring;
    linestring.vPointList=tempPointArray;
    vLines.push_back(linestring);

    }
    }

    //Polygon Shapefile
    if(hSHP->nShapeType == SHPT_POLYGON)
    {
    SHPObject *psShape;
    for(int i=0;i<hSHP->nRecords;i++)
    {
    psShape = SHPReadObject(hSHP, i);
    vector<MyPoint2D> tempPointArray;

    for(int j=0;j<psShape->nVertices;j++)
    {
    double fX = psShape->padfX[j];
    double fY = psShape->padfY[j];
    MyPoint2D pt;
    pt.dX=fX;
    pt.dY=fY;
    tempPointArray.push_back(pt);
    }
    MyPolygon2D polygon;
    polygon.vPointList=tempPointArray;
    vPolygons.push_back(polygon);
    }

    }

    }



    void draw()
    {

    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (0.0, 0.0, 1.0);
    glLoadIdentity ();

    //Render Point Shapefile
    glColor3f (0.0, 0.0, 1.0);
    glEnable(GL_POINT_SMOOTH) ;
    glPointSize(5.0);
    //glBegin(GL_POINTS);

    for(unsigned int i=0;i<vPoints.size();i++)
    {
    glVertex2f(vPoints[i].dX,vPoints[i].dY);
    }

    glEnd();

    //Render Line Shapefile
    glColor3f (0.0, 1.0, 0.0);
    for(unsigned int i=0;i<vLines.size();i++)
    {

    glBegin(GL_LINE_STRIP);
    for(unsigned int j=0;j<vLines[i].vPointList.size();j++)
    {
    glVertex2f(vLines[i].vPointList[j].dX,vLines[i].vPointList[j].dY);

    }

    glEnd();
    }

    //Render Polygon Shapefile
    glColor3f(1.0,0.0, 0.0);
    for(unsigned int i=0;i<vPolygons.size();i++)
    {
    glBegin(GL_LINE_LOOP);
    for(unsigned int j=0;j<vPolygons[i].vPointList.size();j++)
    {
    glVertex2f(vPolygons[i].vPointList[j].dX,vPolygons[i].vPointList[j].dY);
    }

    glEnd();
    }

    glFlush();
    }



    GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) {
    setMouseTracking(true);
    }

    void GLWidget::initializeGL() {
    glClearColor (0.0, 0.0, 0.0, 0.0);
    // glClearColor (1.0, 1.0, 1.0, 1.0);
    glShadeModel (GL_FLAT);
    glEnable (GL_LINE_SMOOTH);
    glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_LINE_SMOOTH);


    //Assign Default Map Bounds to glOrtho
    sBoundingBox.fMaxX=180.0f;
    sBoundingBox.fMaxY=90.0f;
    sBoundingBox.fMinX=-180.0f;
    sBoundingBox.fMinY=-90.0f;
    }

    void GLWidget::resizeGL(int w, int h) {

    OpenShapeFile("test.shp");
    //OpenShapeFile("/root/dev/qt_shape_view/shapeView/Shapefiles/test.shp");
    if(h<=0) h=1 ;
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    //Assign Bounding Box Coordinates of Shapefile to glOrtho()
    glOrtho(sBoundingBox.fMinX, sBoundingBox.fMaxX,sBoundingBox.fMinY,sBoundingBox .fMaxY,-1,1);
    glMatrixMode(GL_MODELVIEW);
    }

    void GLWidget:aintGL() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    draw();
    }

    void GLWidget::mousePressEvent(QMouseEvent *event) {

    }
    void GLWidget::mouseMoveEvent(QMouseEvent *event) {
    printf("%d, %d\n", event->x(), event->y());
    }

    void GLWidget::keyPressEvent(QKeyEvent* event) {
    switch(event->key()) {
    case Qt::Key_Escape:
    close();
    break;
    default:
    event->ignore();
    break;
    }
    }

    it is ok for ubuntu 12.04 desktop opengel but not ok for ARM.

    The error below for ARM opengl es2 is

    GLWidget.cpp::-1: error: undefined reference to `glShadeModel'
    GLWidget.cpp::-1: error: undefined reference to `glColor3f'
    GLWidget.cpp::-1: error: undefined reference to `glLoadIdentity'
    GLWidget.cpp::-1: error: undefined reference to `glColor3f'
    GLWidget.cpp::-1: error: undefined reference to `glPointSize'
    .
    .
    GLWidget.cpp::-1: error: undefined reference to `glOrtho'
    GLWidget.cpp::-1: error: undefined reference to `glMatrixMode'
    :-1: error: collect2: ld returned 1 exit status

    /////////////////

    How I can recover this error.

    Swapan Ghosh
    Last edited by swapan_gh; 28th November 2013 at 10:08.

  2. #2
    Join Date
    Sep 2013
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Shapefile rendering,zooming,paning,editing using shaplib and qt opengl es2

    I can resolved it

Similar Threads

  1. Problem rendering using OpenGL in VM
    By xtal256 in forum Qt Programming
    Replies: 4
    Last Post: 2nd November 2011, 01:10
  2. Image rendering and zooming (QGraphicsView)
    By Sergex in forum Qt Programming
    Replies: 7
    Last Post: 6th October 2011, 12:51
  3. smooth panning and zooming an image, to use OpenGL or not?
    By scarleton in forum Qt Programming
    Replies: 0
    Last Post: 27th August 2010, 22:25
  4. OpenGL rendering and threads
    By brcain in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2008, 09:45
  5. problem with opengl, zooming, drawpixels, and origin
    By ntp in forum General Programming
    Replies: 0
    Last Post: 22nd February 2008, 21:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.