PDA

View Full Version : Reading a shapeFile



Latha Rani
27th July 2017, 11:03
I am reading a shape file and collecting into a QString,but the string is in some binary format, but not getting geometric data(lat,lons).how to read a shape file.

high_flyer
27th July 2017, 12:08
what is a 'shape file'?
How was it generated?
You say it is in binary format, if so, string will not help you much.
You need to know the serialization protocol, and serialized it back.
This has nothing to do with Qt.

Latha Rani
27th July 2017, 12:51
I am using opengl in Qt


here filestr is D:/cochin_vegitation.shp

QFile mfile(filestr);

if(!mfile.open(QFile::ReadOnly |QIODevice::Text))
{
return;
}
QTextStream in(&mfile);
QString mText=in.readAll();
qDebug()<<"textsize"<<mText.size();

for(int i=0;i<mText.size();i++)
{
qDebug()<<"text"<<mText[i];
}



I am getting out put as

text '00\u00a3'
text '?'
text '\x10'
text 'S'
text '@'
text '00\u00af'
text 'H'
text '$'
text '\x1b'
text 'Y'
text '00\u00e7'
text '#'
text '@'
text '\x1'
text '\x0'
text '\x0'
text '\x0'
text '\x5'
text '\x0'
text '\x0'
text '\x0'
text '\x0'
text '\x0'
text '\x0'
text '\x0'
text '('
text 'I'
But i need Geometric data like Latitude,Longitude

high_flyer
27th July 2017, 12:56
nothing in what you added changes the issue.
You need to know how the data is serialized in the shape file.
Without it, there is nothing you can do.

jefftee
28th July 2017, 04:47
You need to open the file as a binary file, not text, because it contains binary data, not text data.

The file format of a Shapefile is shown here: https://en.wikipedia.org/wiki/Shapefile. The wikipedia article show the layout of the 100 byte header file that is the first 100 bytes in a shapefile, followed by the various record types that it may contain. You'll have to understand the file layout described the article and then successfully read/parse the records that follow the 100 byte header.

Good luck.